[更新]修改公众号页面支持

This commit is contained in:
Anyon 2018-04-03 13:13:23 +08:00
parent 0d1538ad4d
commit 3beeed5a41
2 changed files with 13 additions and 24 deletions

View File

@ -24,13 +24,6 @@ use think\facade\Response;
*/ */
class Script class Script
{ {
/**
* 当前请求对象
* @var \think\Request
*/
protected $request;
/** /**
* jsSign签名 * jsSign签名
* @throws \Exception * @throws \Exception
@ -41,12 +34,12 @@ class Script
$wechat = WechatService::webOauth($result->get('mode', 1)); $wechat = WechatService::webOauth($result->get('mode', 1));
$url = $result->server('HTTP_REFERER', $result->url(true), null); $url = $result->server('HTTP_REFERER', $result->url(true), null);
$assign = [ $assign = [
'jssdk' => json_encode(WechatService::webJsSDK($url), 256), 'jssdk' => WechatService::webJsSDK($url),
'openid' => $wechat['openid'], 'fansinfo' => $wechat['fansinfo'], 'openid' => $wechat['openid'], 'fansinfo' => $wechat['fansinfo'],
]; ];
return Response::create(env('APP_PATH') . 'wechat/view/api/script/index.js', 'view', 200, [ return Response::create(env('APP_PATH') . 'wechat/view/api/script/index.js', 'view', 200, [
'content-type' => 'application/x-javascript;charset=utf-8', 'Content-Type' => 'application/x-javascript;charset=utf-8',
'cache-control' => 'no-cache', 'pragma' => 'no-cache', 'expires' => '0', 'Cache-Control' => 'no-cache', 'Pragma' => 'no-cache', 'Expires' => '0',
])->assign($assign); ])->assign($assign);
} }
} }

View File

@ -1,14 +1,10 @@
!(function () {
if (typeof wx === 'object') { if (typeof wx === 'object') {
wx.openid = '{$fansinfo.openid|default=""}'; wx.openid = '{$fansinfo.openid|default=""}';
wx.unionid = '{$fansinfo.unionid|default=""}'; wx.unionid = '{$fansinfo.unionid|default=""}';
wx.getUserInfo = function () { wx.fansinfo = eval('{$fansinfo|default=[]|json_encode=###,256|raw}');
return eval('{$fansinfo|default=[]|json_encode=###,256|raw}'); wx.config(eval('{$jssdk|default=[]|json_encode=###,256|raw}'));
};
wx.config(eval('({$jssdk|default=[]|json_encode=###,256|raw})'));
wx.ready(function () { wx.ready(function () {
wx.hideOptionMenu(); wx.hideOptionMenu();
wx.hideAllNonBaseMenuItem(); wx.hideAllNonBaseMenuItem();
}); });
} }
})();