From dfd9522f19f472661801e9ffe23478a31b6ad234 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Wed, 7 Aug 2024 17:37:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=BE=AE=E4=BF=A1JsSDK?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=8E=A5=E5=8F=A32?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/wechat/Wechat.php | 9 +++++++-- app/service/wechat/WechatService.php | 16 ++++------------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/controller/wechat/Wechat.php b/app/controller/wechat/Wechat.php index 77a8c20..f9ad7e9 100644 --- a/app/controller/wechat/Wechat.php +++ b/app/controller/wechat/Wechat.php @@ -130,11 +130,16 @@ class Wechat extends Base } } - public function getJsSdkData() + public function getJsSdkData(Request $request) { try { + $param = $request->param(); + + validate()->rule(['url' => 'require'])->check($param); + + $url = urldecode($param['url']); $WechatService = new WechatService(); - return $this->buildSuccess($WechatService->getJsSdkSignature()); + return $this->buildSuccess($WechatService->getJsSdkSignature($url)); } catch (\Exception $e) { return $this->buildFailed(ReturnCode::INVALID,$e->getMessage()); } diff --git a/app/service/wechat/WechatService.php b/app/service/wechat/WechatService.php index 2783975..f7f21c7 100644 --- a/app/service/wechat/WechatService.php +++ b/app/service/wechat/WechatService.php @@ -71,27 +71,19 @@ class WechatService extends BaseService /** * + * @param $url * @return array * @throws FuncException */ - public function getJsSdkSignature(): array + public function getJsSdkSignature($url): array { $timestamp = time(); - $nonceStr = generate_random_string(16); + $nonceStr = generate_random_string(10); $jsapi_ticket = $this->getJsApiTicket(); - $ascllArr = [ - 'noncestr=' . $nonceStr, - 'jsapi_ticket=' . $jsapi_ticket, - 'timestamp=' . $timestamp, - 'url=' . 'http://mp.weixin.qq.com?params=value', - ]; - - sort($ascllArr); - - $signature = sha1(implode('&', $ascllArr)); + $signature = sha1(sprintf('jsapi_ticket=%s&noncestr=%s×tamp=%s&url=%s', $jsapi_ticket, $nonceStr, $timestamp, $url)); return [ 'appId' => env('wechat.appid'),