参数名 | 类型 | 说明 |
app_key | string(32) | 人人秀平台分配的AppKey |
time_stamp | string(14) | 1970-01-01开始的时间戳,精确到毫秒 |
sign | string(32) | 根据签名算法计算所得 |
openid: ot1UbuBBzlE6IjEDWfyXQW3dy2S4
transaction_no: 69201704060281699381
time_stamp: 1543999047492
nonce_str: ibuaiVcKdpRxkhJA
order_no: 19201704060281699381
app_key: 96c84928b1dce057d110ea3b3880fc83
time_stamp: 1543999047492
sign:
openid: ot1UbuBBzlE6IjEDWfyXQW3dy2S4
transaction_no: 69201704060281699381
nonce_str: ibuaiVcKdpRxkhJA
order_no: 19201704060281699381
app_key: 96c84928b1dce057d110ea3b3880fc83
time_stamp: 1543999047492
sign:
openid: ot1UbuBBzlE6IjEDWfyXQW3dy2S4
transaction_no: 69201704060281699381
nonce_str: ibuaiVcKdpRxkhJA
order_no: 19201704060281699381
示例代码
// 计算签名类
class RrxAPI
{
protected $values = array();
public function __construct($data=array())
{
foreach ($data as &$d){
// 参数解码
$d = urldecode($d);
}
$this->values = $data;
}
/**
* 签名生成算法
* @param string $secret API密钥
* @return string 签名
*/
public function makeSign($secret){
//签名步骤一:按字典序排序参数
ksort($this->values);
$string = $this->ToUrlParams();
//签名步骤二:在string后加入app_secret
$string = $string . "&app_secret=".$secret;
//签名步骤三:MD5加密
$string = md5($string);
//签名步骤四:所有字符转为大写
$result = strtoupper($string);
return $result;
}
/**
* 格式化参数格式化成url参数
*/
private function ToUrlParams()
{
$buff = "";
foreach ($this->values as $k => $v)
{
// 排除签名参数sign 、空值 、 数组
if($k != "sign" && $v != "" && !is_array($v)){
$buff .= $k . "=" . $v . "&";
}
}
$buff = trim($buff, "&");
return $buff;
}
}
// 调用签名方法,计算签名
$query_data=[
'app_key'=>'test_app_key',
'openid'=>'test_openid',
'time_stamp'=>'1543999047492',
'name'=>'张飞'
];
$apiSdk = new RrxAPI($query_data);
$secret = 'test_secret';
$sign=$apiSdk->makeSign($secret);
得到签名为 8F4CC38010A6F917E788ED99518BD589