mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-24 18:36:15 +08:00
Update Js.php
This commit is contained in:
parent
9abcc35750
commit
46b56306b2
@ -26,8 +26,12 @@ use think\Response;
|
|||||||
*/
|
*/
|
||||||
class Js extends Controller
|
class Js extends Controller
|
||||||
{
|
{
|
||||||
|
protected $params;
|
||||||
|
protected $openid;
|
||||||
|
protected $fansinfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回生成的JS内容
|
* 生成网页授权的JS内容
|
||||||
* @return \think\Response
|
* @return \think\Response
|
||||||
* @throws \WeChat\Exceptions\InvalidResponseException
|
* @throws \WeChat\Exceptions\InvalidResponseException
|
||||||
* @throws \WeChat\Exceptions\LocalCacheException
|
* @throws \WeChat\Exceptions\LocalCacheException
|
||||||
@ -38,18 +42,19 @@ class Js extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$this->mode = $this->request->get('mode', 1);
|
$mode = $this->request->get('mode', 1);
|
||||||
$this->source = $this->request->server('http_referer', $this->request->url(true));
|
$source = $this->request->server('http_referer') ?: $this->request->url(true);
|
||||||
$user = WechatService::instance()->getWebOauthInfo($this->source, $this->mode, false);
|
$userinfo = WechatService::instance()->getWebOauthInfo($source, $mode, false);
|
||||||
if (empty($user['openid'])) {
|
if (empty($userinfo['openid'])) {
|
||||||
$content = 'alert("Wechat webOauth failed.")';
|
$content = 'alert("Wechat webOauth failed.")';
|
||||||
} else {
|
} else {
|
||||||
$this->openid = $user['openid'];
|
$this->openid = $userinfo['openid'];
|
||||||
$this->config = json_encode(WechatService::instance()->getWebJssdkSign($this->source));
|
$this->params = json_encode(WechatService::instance()->getWebJssdkSign($source));
|
||||||
$this->fansinfo = json_encode(empty($user['fansinfo']) ? [] : $user['fansinfo'], JSON_UNESCAPED_UNICODE);
|
$this->fansinfo = json_encode($userinfo['fansinfo'] ?? [], JSON_UNESCAPED_UNICODE);
|
||||||
// 生成接口授权令牌
|
// 生成数据授权令牌
|
||||||
$this->token = uniqid('oauth') . rand(10000, 99999);
|
$this->token = uniqid('oauth') . rand(10000, 99999);
|
||||||
$this->app->cache->set($this->openid, $this->token, 3600);
|
$this->app->cache->set($this->openid, $this->token, 3600);
|
||||||
|
// 生成前端JS变量代码
|
||||||
$content = $this->_buildContent();
|
$content = $this->_buildContent();
|
||||||
}
|
}
|
||||||
return Response::create($content)->contentType('application/x-javascript');
|
return Response::create($content)->contentType('application/x-javascript');
|
||||||
@ -66,7 +71,7 @@ if(typeof wx === 'object'){
|
|||||||
wx.token="{$this->token}";
|
wx.token="{$this->token}";
|
||||||
wx.openid="{$this->openid}";
|
wx.openid="{$this->openid}";
|
||||||
wx.fansinfo={$this->fansinfo};
|
wx.fansinfo={$this->fansinfo};
|
||||||
wx.config({$this->config});
|
wx.config({$this->params});
|
||||||
wx.ready(function(){
|
wx.ready(function(){
|
||||||
wx.hideOptionMenu();
|
wx.hideOptionMenu();
|
||||||
wx.hideAllNonBaseMenuItem();
|
wx.hideAllNonBaseMenuItem();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user