作者 郭鑫
1 个管道 的构建 通过 耗费 0 秒

登录

@@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
11 namespace app\portal\controller; 11 namespace app\portal\controller;
12 12
13 use cmf\controller\HomeBaseController; 13 use cmf\controller\HomeBaseController;
  14 +use think\Config;
14 use think\Session; 15 use think\Session;
15 use think\Db; 16 use think\Db;
16 17
@@ -65,9 +66,6 @@ class WxloginController extends HomeBaseController @@ -65,9 +66,6 @@ class WxloginController extends HomeBaseController
65 * Main:授权登录 获取openid 66 * Main:授权登录 获取openid
66 */ 67 */
67 public function OAuth($redirect_uri){ 68 public function OAuth($redirect_uri){
68 - echo "<pre/>";  
69 - print_r($redirect_uri);  
70 - die;  
71 if (!Session::get('uid')) { 69 if (!Session::get('uid')) {
72 $url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 70 $url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
73 $temp_one = explode('code=',$url); 71 $temp_one = explode('code=',$url);
@@ -75,7 +73,7 @@ class WxloginController extends HomeBaseController @@ -75,7 +73,7 @@ class WxloginController extends HomeBaseController
75 $temp_two = explode('&state',$temp_one[1]); 73 $temp_two = explode('&state',$temp_one[1]);
76 if ($temp_two[0]) { 74 if ($temp_two[0]) {
77 //第二步 获取access_token 75 //第二步 获取access_token
78 - $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx100c2e5f27e34b92&secret=4de2264efb220ea89c1095580f4f4350&code=" . $temp_two[0] . "&grant_type=authorization_code"; 76 + $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".Config::get('WX_APPID')."&secret=".Config::get('WX_APP_SECRET')."&code=" . $temp_two[0] . "&grant_type=authorization_code";
79 $resp = file_get_contents($url); 77 $resp = file_get_contents($url);
80 $resp_arr = json_decode($resp, true); 78 $resp_arr = json_decode($resp, true);
81 // 将accesstoken 存session 79 // 将accesstoken 存session
@@ -83,7 +81,7 @@ class WxloginController extends HomeBaseController @@ -83,7 +81,7 @@ class WxloginController extends HomeBaseController
83 Session::set('user.accessTime',time()); 81 Session::set('user.accessTime',time());
84 //第三步 82 //第三步
85 $refresh_token = $resp_arr['refresh_token']; 83 $refresh_token = $resp_arr['refresh_token'];
86 - $url1 = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=wx100c2e5f27e34b92&grant_type=refresh_token&refresh_token=".$refresh_token; 84 + $url1 = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=".Config::get('WX_APPID')."&grant_type=refresh_token&refresh_token=".$refresh_token;
87 $resp1 = file_get_contents($url1); 85 $resp1 = file_get_contents($url1);
88 $resp_arr1 = json_decode($resp1, true); 86 $resp_arr1 = json_decode($resp1, true);
89 //第四步 87 //第四步
@@ -107,12 +105,12 @@ class WxloginController extends HomeBaseController @@ -107,12 +105,12 @@ class WxloginController extends HomeBaseController
107 Session::set('uid',$is_isset['id']); 105 Session::set('uid',$is_isset['id']);
108 } 106 }
109 } else { 107 } else {
110 - $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx100c2e5f27e34b92&redirect_uri=" . $redirect_uri . "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"; 108 + $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".Config::get('WX_APPID')."&redirect_uri=" . $redirect_uri . "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
111 Header("Location: $url"); 109 Header("Location: $url");
112 exit; 110 exit;
113 } 111 }
114 }else{ 112 }else{
115 - $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx100c2e5f27e34b92&redirect_uri=" . $redirect_uri . "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"; 113 + $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".Config::get('WX_APPID')."&redirect_uri=" . $redirect_uri . "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
116 Header("Location: $url"); 114 Header("Location: $url");
117 exit; 115 exit;
118 } 116 }