Home >Backend Development >PHP Tutorial >PHP adjustment interface Sign verification

PHP adjustment interface Sign verification

不言
不言Original
2018-05-09 10:33:232075browse

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;
    }

}
   $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;);  
}

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!

Statement:
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