mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
修改微信授权
This commit is contained in:
parent
a2ffb55d89
commit
1d8367885a
@ -38,25 +38,41 @@ class Js extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$url = $this->request->server('http_referer', $this->request->url(true));
|
$this->mode = $this->request->get('mode', 1);
|
||||||
$user = WechatService::instance()->getWebOauthInfo($url, $this->request->get('mode', 1), false);
|
$this->source = $this->request->server('http_referer', $this->request->url(true));
|
||||||
$openid = isset($user['openid']) ? $user['openid'] : '';
|
$user = WechatService::instance()->getWebOauthInfo($this->source, $this->mode, false);
|
||||||
$unionid = empty($user['fansinfo']['unionid']) ? '' : $user['fansinfo']['unionid'];
|
if (empty($user['openid'])) {
|
||||||
$configJson = json_encode(WechatService::instance()->getWebJssdkSign($url), JSON_UNESCAPED_UNICODE);
|
$content = 'alert("Wechat webOauth failed.")';
|
||||||
$fansinfoJson = json_encode(isset($user['fansinfo']) ? $user['fansinfo'] : [], JSON_UNESCAPED_UNICODE);
|
} else {
|
||||||
$html = <<<EOF
|
$this->openid = $user['openid'];
|
||||||
|
$this->config = json_encode(WechatService::instance()->getWebJssdkSign($this->source));
|
||||||
|
$this->fansinfo = json_encode(empty($user['fansinfo']) ? [] : $user['fansinfo'], JSON_UNESCAPED_UNICODE);
|
||||||
|
// 生成接口授权令牌
|
||||||
|
$this->token = uniqid('oauth') . rand(10000, 99999);
|
||||||
|
$this->app->cache->set($this->openid, $this->token, 3600);
|
||||||
|
$content = $this->_buildContent();
|
||||||
|
}
|
||||||
|
return Response::create($content)->contentType('application/x-javascript');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成授权内容
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function _buildContent()
|
||||||
|
{
|
||||||
|
return <<<EOF
|
||||||
if(typeof wx === 'object'){
|
if(typeof wx === 'object'){
|
||||||
wx.openid="{$openid}";
|
wx.token="{$this->token}";
|
||||||
wx.unionid="{$unionid}";
|
wx.openid="{$this->openid}";
|
||||||
wx.config({$configJson});
|
wx.fansinfo={$this->fansinfo};
|
||||||
wx.fansinfo={$fansinfoJson};
|
wx.config({$this->config});
|
||||||
wx.ready(function(){
|
wx.ready(function(){
|
||||||
wx.hideOptionMenu();
|
wx.hideOptionMenu();
|
||||||
wx.hideAllNonBaseMenuItem();
|
wx.hideAllNonBaseMenuItem();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
EOF;
|
EOF;
|
||||||
return Response::create($html)->contentType('application/x-javascript');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
2
vendor/services.php
vendored
2
vendor/services.php
vendored
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// This file is automatically generated at:2019-12-30 18:33:07
|
// This file is automatically generated at:2019-12-30 18:59:17
|
||||||
declare (strict_types = 1);
|
declare (strict_types = 1);
|
||||||
return array (
|
return array (
|
||||||
0 => 'think\\app\\Service',
|
0 => 'think\\app\\Service',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user