当前位置:   article > 正文

php快手开发平台api签名_快手开放平台 php

快手开放平台 php

使用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';
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

第一种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;
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

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;
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/238905
推荐阅读
相关标签
  

闽ICP备14008679号