diff --git a/WeChat/Contracts/Tools.php b/WeChat/Contracts/Tools.php index 4423894..e78149c 100644 --- a/WeChat/Contracts/Tools.php +++ b/WeChat/Contracts/Tools.php @@ -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 diff --git a/WeChat/Script.php b/WeChat/Script.php index 4d66aa1..26710a0 100644 --- a/WeChat/Script.php +++ b/WeChat/Script.php @@ -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)); + } } \ No newline at end of file