PHP adjustment interface Sign verification

不言
Release: 2023-03-25 17:46:02
Original
2054 people have browsed it

This article mainly introduces the verification of the PHP adjustment interface Sign. It has a certain reference value. Now I share it with everyone. Friends in need can refer to it.

<?php
namespace App\Librarys;

class SignUtil{
    /**
     * @param array $params
     * @return string
     */
    public static function getCheckSign($params) {
    	$arrSign = [];
        ksort($params);
        $ts = $params[&#39;ts&#39;];
        $token = &#39;8553d751250eb0846e84d67b6bdf250f&#39;;
        foreach ($params as $k => $v) {
            if ($k == &#39;sign&#39; || $k == &#39;ts&#39;) {
                continue;
            }
            if (is_array($v)) {
                $v = json_encode($v);
            }
            $strTmp = trim($k) . &#39;=&#39; . trim($v);
            $arrSign[$strTmp] = $strTmp;
        }
        $strSign = implode(&#39;&&#39;, $arrSign);
        $sign = md5($strSign.$ts.$token);
        return $sign;
    }

}
Copy after login
   $params = $request->all();  
if(!isset($params[&#39;sign&#39;])){  
    return $this->failsmsg(&#39;缺少sign校验参数&#39;);  
}  
$mySign = SignUtil::getCheckSign($params);  
if($params[&#39;sign&#39;] != $mySign){  
    return $this->failsmsg(&#39;sign校验失败&#39;);  
}
Copy after login

The above is the entire article. Content, please pay attention to the PHP Chinese website for more related content.

Related recommendations:

Detailed explanation of SQLite PHP interface

The meaning of interface in php interface

The above is the detailed content of PHP adjustment interface Sign verification. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!