From c07f237ecae1f160bd82193b733e3b2681a0f5e3 Mon Sep 17 00:00:00 2001 From: Anyon Date: Mon, 19 Mar 2018 15:42:28 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=E5=A2=9E=E5=8A=A0=E5=8F=88?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E7=BD=91=E9=A1=B5=E6=8E=88=E6=9D=83=E5=85=BC?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/wechat/controller/api/Tools.php | 8 +++++--- extend/service/WechatService.php | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/application/wechat/controller/api/Tools.php b/application/wechat/controller/api/Tools.php index 644c52a24..778f3bdec 100644 --- a/application/wechat/controller/api/Tools.php +++ b/application/wechat/controller/api/Tools.php @@ -53,12 +53,14 @@ class Tools extends BasicAdmin /** * JSSDK测试 * @return string + * @throws \WeChat\Exceptions\InvalidResponseException + * @throws \WeChat\Exceptions\LocalCacheException + * @throws \think\Exception + * @throws \think\exception\PDOException */ public function jssdk() { - $wechat = WechatService::wechat(); - $options = $wechat->jsSign($this->request->url(true)); - return $this->fetch('', ['options' => $options]); + return $this->fetch('', ['options' => WechatService::webJsSDK()]); } /** diff --git a/extend/service/WechatService.php b/extend/service/WechatService.php index 5d550a9e0..223741741 100644 --- a/extend/service/WechatService.php +++ b/extend/service/WechatService.php @@ -84,6 +84,25 @@ class WechatService } } + /** + * 获取微信网页JSSDK + * @return array + * @throws \think\Exception + * @throws \WeChat\Exceptions\InvalidResponseException + * @throws \WeChat\Exceptions\LocalCacheException + * @throws \think\exception\PDOException + */ + public static function webJsSDK() + { + switch (strtolower(sysconf('wechat_type'))) { + case 'api': + return WechatService::script()->getJsSign(request()->url(true)); + case 'thr': + default: + return WechatService::wechat()->jsSign(request()->url(true)); + } + } + /** * 初始化进入授权 * @param int $fullMode 授权公众号模式