diff --git a/application/common.php b/application/common.php index 585e0990d..7978e248f 100755 --- a/application/common.php +++ b/application/common.php @@ -11,6 +11,32 @@ // 应用公共文件 +/** + * 判断当前是否小程序环境中 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2019-06-29T22:21:44+0800 + */ +function MiniAppEnv() +{ + if(!empty($_SERVER['HTTP_USER_AGENT'])) + { + // 微信小程序 miniProgram + if(stripos($_SERVER['HTTP_USER_AGENT'], 'miniProgram') !== false) + { + return 'weixin'; + } + + // 支付宝客户端 AlipayClient + if(stripos($_SERVER['HTTP_USER_AGENT'], 'AlipayClient') !== false) + { + return 'alipay'; + } + } + return null; +} + /** * RGB 转 十六进制 * @author Devil diff --git a/application/index/controller/Common.php b/application/index/controller/Common.php index 327b14a4d..e0c412696 100755 --- a/application/index/controller/Common.php +++ b/application/index/controller/Common.php @@ -159,6 +159,28 @@ class Common extends Controller } } + /** + * [CommonInit 公共数据初始化] + * @author Devil + * @blog http://gong.gg/ + * @version 0.0.1 + * @datetime 2017-03-09T11:43:48+0800 + */ + private function CommonInit() + { + // 用户数据 + $this->user = UserService::LoginUserInfo(); + + // 公共参数 + $this->params = input(); + + // 推荐人 + if(!empty($this->params['referrer'])) + { + session('share_referrer_id', $this->params['referrer']); + } + } + /** * [IsLogin 登录校验] * @author Devil @@ -179,31 +201,6 @@ class Common extends Controller } } - /** - * [CommonInit 公共数据初始化] - * @author Devil - * @blog http://gong.gg/ - * @version 0.0.1 - * @datetime 2017-03-09T11:43:48+0800 - */ - private function CommonInit() - { - // 用户数据 - if(session('user') !== null) - { - $this->user = UserService::LoginUserInfo(); - } - - // 公共参数 - $this->params = input(); - - // 推荐人 - if(!empty($this->params['referrer'])) - { - session('share_referrer_id', $this->params['referrer']); - } - } - /** * [ViewInit 视图初始化] * @author Devil diff --git a/application/service/UserService.php b/application/service/UserService.php index 5cd37cda2..a0517d892 100755 --- a/application/service/UserService.php +++ b/application/service/UserService.php @@ -35,13 +35,32 @@ class UserService */ public static function LoginUserInfo() { + // 参数 + $params = input(); + + // 用户数据处理 + $user = null; if(APPLICATION == 'web') { - return session('user'); + // token仅小程序浏览器环境和api接口环境中有效 + if(!empty($params['token']) && in_array(MiniAppEnv(), ['weixin', 'alipay', 'baidu'])) + { + $user = cache(config('shopxo.cache_user_info').$params['token']); + if(isset($user['id'])) + { + self::UserLoginRecord($user['id']); + } + } else { + $user = session('user'); + } } else { - $params = input(); - return empty($params['token']) ? null : cache(config('shopxo.cache_user_info').$params['token']); + if(!empty($params['token'])) + { + $user = cache(config('shopxo.cache_user_info').$params['token']); + } } + + return $user; } /** diff --git a/public/appmini/old/alipay/app.js b/public/appmini/old/alipay/app.js index 687e5af03..0741d5d79 100644 --- a/public/appmini/old/alipay/app.js +++ b/public/appmini/old/alipay/app.js @@ -172,7 +172,7 @@ App({ params = "&" + params; } var user = this.get_user_cache_info(); - var token = (user == false) ? 0 : user.token; + var token = (user == false) ? '' : user.token || ''; return ( this.data.request_url + "index.php?s=/" + m + "/" + c + "/" + a + @@ -553,7 +553,7 @@ App({ switch(type) { // web case 0 : - my.navigateTo({url: '/pages/web-view/web-view?url='+value}); + my.navigateTo({url: '/pages/web-view/web-view?url='+encodeURIComponent(value)}); break; // 内部页面 diff --git a/public/appmini/old/alipay/pages/web-view/web-view.js b/public/appmini/old/alipay/pages/web-view/web-view.js old mode 100755 new mode 100644 index b6405a1c8..21f41cbcd --- a/public/appmini/old/alipay/pages/web-view/web-view.js +++ b/public/appmini/old/alipay/pages/web-view/web-view.js @@ -4,8 +4,24 @@ Page({ web_url: null, }, onLoad(option) { + // url处理 + var url = decodeURIComponent(option.url) || null; + if (url != null) + { + // token处理 + if (url.indexOf('{token}') >= 0) + { + var user = app.get_user_cache_info(); + var token = (user == false) ? null : user.token || null; + if (token != null) + { + url = url.replace(/{token}/ig, token); + } + } + } + this.setData({ - web_url: option.url || null, - }) + web_url: url, + }); } }); \ No newline at end of file diff --git a/public/appmini/old/weixin/app.js b/public/appmini/old/weixin/app.js index 487dd356b..4188557f1 100755 --- a/public/appmini/old/weixin/app.js +++ b/public/appmini/old/weixin/app.js @@ -61,7 +61,7 @@ App({ // 请求地址 // request_url: "{{request_url}}", request_url: 'http://tp5-dev.com/', - request_url: 'https://test.shopxo.net/', + //request_url: 'https://test.shopxo.net/', // 基础信息 application_title: "{{application_title}}", @@ -432,7 +432,7 @@ App({ switch (type) { // web case 0: - wx.navigateTo({ url: '/pages/web-view/web-view?url=' + value }); + wx.navigateTo({ url: '/pages/web-view/web-view?url=' + encodeURIComponent(value) }); break; // 内部页面 diff --git a/public/appmini/old/weixin/pages/web-view/web-view.js b/public/appmini/old/weixin/pages/web-view/web-view.js index b6405a1c8..21f41cbcd 100755 --- a/public/appmini/old/weixin/pages/web-view/web-view.js +++ b/public/appmini/old/weixin/pages/web-view/web-view.js @@ -4,8 +4,24 @@ Page({ web_url: null, }, onLoad(option) { + // url处理 + var url = decodeURIComponent(option.url) || null; + if (url != null) + { + // token处理 + if (url.indexOf('{token}') >= 0) + { + var user = app.get_user_cache_info(); + var token = (user == false) ? null : user.token || null; + if (token != null) + { + url = url.replace(/{token}/ig, token); + } + } + } + this.setData({ - web_url: option.url || null, - }) + web_url: url, + }); } }); \ No newline at end of file