[更新]整理前端支持签名函数

This commit is contained in:
Anyon 2018-02-02 18:40:42 +08:00
parent 96e2b06d8f
commit 393fd6a281
2 changed files with 21 additions and 19 deletions

View File

@ -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

View File

@ -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));
}
}