PHP哈希签名方式sha1和sha256用于API对接签名验证
sha1 (长度40字节)
--------------------------------------------------------------
$str = '203fpid';
$sha1 = sha1($str);
echo $sha1.'<br>';
php sha256加密 (长度64)
--------------------------------------------------------------
$str = '203fpidf02lvj!!_@#_!';
$sha256 = hash('sha256',$str);
echo $sha256.'<br>';
/** 生成签名(哈希sha256 64位)
* @param $data
* @return false|string
*/
public function _sign($data){
$data = array_filter($data);
ksort($data);
$temps = [];
foreach ($data as $key => $value) {
$temps[] = sprintf('%s=%s', $key, $value);
}
$signBefore = $this->app_secret.implode('&', $temps);
return hash('sha256',$signBefore);
}
原文地址:https://blog.csdn.net/happyzhlb/article/details/140737159
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!