请求签名方法
登录后台获取key,这里我们做以下假设:
e1TZWs5SLtm8CFZ3n9Axd5BdMXkOsPgGnqt3M4S9iic=
需要以下信息
- 时间戳当前时间 timeStamp
- 随机字符串 randomStr
- key令牌 token
生成方法
- 按参数首字母排序
- 将字符串拼凑
- 进行MD5加密
- 再转为大写
<?php/** @param $timeStamp 时间戳* @param $randomStr 随机字符串* @return string 返回签名*/function arithmetic($timeStamp,$randomStr,$token){$arr['timeStamp'] = $timeStamp;$arr['randomStr'] = $randomStr;$arr['token'] = $token;//按照首字母大小写顺序排序sort($arr,SORT_STRING);//拼接成字符串$str = implode($arr);//进行加密$signature = md5($str);//转换成大写$signature = strtoupper($signature);return $signature;}//随机生成字符串32位function createNonceStr($length = 32) {$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";$str = "";for ($i = 0; $i < $length; $i++) {$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);}return $str;}$timeStamp = time(); //时间戳$randomStr = createNonceStr(); //随机字符串$token = "e1TZWs5SLtm8CFZ3n9Axd5BdMXkOsPgGnqt3M4S9iic="; //令牌key$signature = arithmetic($timeStamp,$randomStr,$token);echo $signature;
最终生成的请求签名如下:
2DF9563499C4E9F8AB85A6FA2F963099
文档更新时间: 2022-05-09 15:27 作者:admin