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 授权公众号模式