mirror of
https://gitee.com/zoujingli/WeChatDeveloper.git
synced 2025-04-05 19:41:44 +08:00
[更新]整理前端支持签名函数
This commit is contained in:
parent
96e2b06d8f
commit
393fd6a281
@ -47,24 +47,7 @@ class Tools
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据生成签名
|
||||
* @param array $data 签名数组
|
||||
* @param string $method 签名方法
|
||||
* @return bool|string 签名值
|
||||
*/
|
||||
public static function getSignature($data, $method = "sha1")
|
||||
{
|
||||
if (!function_exists($method)) {
|
||||
return false;
|
||||
}
|
||||
ksort($data);
|
||||
$params = [];
|
||||
foreach ($data as $key => $value) {
|
||||
$params[] = "{$key}={$value}";
|
||||
}
|
||||
return $method(join('&', $params));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据文件后缀获取文件MINE
|
||||
|
@ -85,7 +85,7 @@ class Script extends WeChat
|
||||
"appId" => $appid,
|
||||
"nonceStr" => $data['noncestr'],
|
||||
"timestamp" => $data['timestamp'],
|
||||
"signature" => Tools::getSignature($data, 'sha1'),
|
||||
"signature" => $this->getSignature($data, 'sha1'),
|
||||
'jsApiList' => [
|
||||
'onWXDeviceBluetoothStateChange', 'onWXDeviceStateChange',
|
||||
'openProductSpecificView', 'addCard', 'chooseCard', 'openCard',
|
||||
@ -99,4 +99,23 @@ class Script extends WeChat
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据生成签名
|
||||
* @param array $data 签名数组
|
||||
* @param string $method 签名方法
|
||||
* @return bool|string 签名值
|
||||
*/
|
||||
protected function getSignature($data, $method = "sha1")
|
||||
{
|
||||
if (!function_exists($method)) {
|
||||
return false;
|
||||
}
|
||||
ksort($data);
|
||||
$params = [];
|
||||
foreach ($data as $key => $value) {
|
||||
$params[] = "{$key}={$value}";
|
||||
}
|
||||
return $method(join('&', $params));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user