[更新]增加又模式网页授权兼容

This commit is contained in:
Anyon 2018-03-19 15:42:28 +08:00
parent e1e39b0023
commit c07f237eca
2 changed files with 24 additions and 3 deletions

View File

@ -53,12 +53,14 @@ class Tools extends BasicAdmin
/** /**
* JSSDK测试 * JSSDK测试
* @return string * @return string
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
* @throws \think\Exception
* @throws \think\exception\PDOException
*/ */
public function jssdk() public function jssdk()
{ {
$wechat = WechatService::wechat(); return $this->fetch('', ['options' => WechatService::webJsSDK()]);
$options = $wechat->jsSign($this->request->url(true));
return $this->fetch('', ['options' => $options]);
} }
/** /**

View File

@ -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 授权公众号模式 * @param int $fullMode 授权公众号模式