赞
踩
使用php对接快手小点的api
签名官方文档:https://open.kwaixiaodian.com/docs/dev?pageSign=8cca5d25ba0015e5045a7ebec6383b741614263875756#section-7
php的签名写法:
参与签名的参数
//参与签名的参数
$biz_params =[];//body请求参数
$params = [
'appkey'=>$appid,
'timestamp'=>$timestamp,
'access_token'=>$access_token,
'version'=>$v,
'param'=>json_encode($biz_params),
'method'=>$method,
'signMethod'=>'HMAC_SHA256'
];
$signSecret = '申请的key';
第一种md5方式:
public function KuaiShousign($param,$signSecret){
$paramStr = "";
ksort($param);
foreach ($param as $kk=>$vv){
if (null != $vv && "null" != $vv) {
$paramStr .= $kk . "=" . $vv . "&";
}
}
$unSignParaString = '';
if (strlen($paramStr) > 0) {
$unSignParaString = substr($paramStr, 0, strlen($paramStr) - 1);
}
$signStr = (md5($unSignParaString . "&signSecret=" . $signSecret));
return $signStr;
}
2.HMAC_SHA256(官方推荐)
public function KuaiShousigns($param,$signSecret){
$paramStr = "";
ksort($param);
foreach ($param as $kk=>$vv){
if (null != $vv && "null" != $vv) {
$paramStr .= $kk . "=" . $vv . "&";
}
}
$unSignParaString = '';
if (strlen($paramStr) > 0) {
$unSignParaString = substr($paramStr, 0, strlen($paramStr) - 1);
}
$unSignParaString = $unSignParaString."&signSecret=" . $signSecret;
$signStr = base64_encode(
hash_hmac(
'sha256',
$unSignParaString,
$signSecret,
true
)
);
return $signStr;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。