...
|
...
|
@@ -11,6 +11,7 @@ |
|
|
namespace app\portal\controller;
|
|
|
|
|
|
use cmf\controller\HomeBaseController;
|
|
|
use think\Config;
|
|
|
use think\Session;
|
|
|
use think\Db;
|
|
|
|
...
|
...
|
@@ -65,9 +66,6 @@ class WxloginController extends HomeBaseController |
|
|
* Main:授权登录 获取openid
|
|
|
*/
|
|
|
public function OAuth($redirect_uri){
|
|
|
echo "<pre/>";
|
|
|
print_r($redirect_uri);
|
|
|
die;
|
|
|
if (!Session::get('uid')) {
|
|
|
$url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
|
|
$temp_one = explode('code=',$url);
|
...
|
...
|
@@ -75,7 +73,7 @@ class WxloginController extends HomeBaseController |
|
|
$temp_two = explode('&state',$temp_one[1]);
|
|
|
if ($temp_two[0]) {
|
|
|
//第二步 获取access_token
|
|
|
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx100c2e5f27e34b92&secret=4de2264efb220ea89c1095580f4f4350&code=" . $temp_two[0] . "&grant_type=authorization_code";
|
|
|
$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";
|
|
|
$resp = file_get_contents($url);
|
|
|
$resp_arr = json_decode($resp, true);
|
|
|
// 将accesstoken 存session
|
...
|
...
|
@@ -83,7 +81,7 @@ class WxloginController extends HomeBaseController |
|
|
Session::set('user.accessTime',time());
|
|
|
//第三步
|
|
|
$refresh_token = $resp_arr['refresh_token'];
|
|
|
$url1 = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=wx100c2e5f27e34b92&grant_type=refresh_token&refresh_token=".$refresh_token;
|
|
|
$url1 = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=".Config::get('WX_APPID')."&grant_type=refresh_token&refresh_token=".$refresh_token;
|
|
|
$resp1 = file_get_contents($url1);
|
|
|
$resp_arr1 = json_decode($resp1, true);
|
|
|
//第四步
|
...
|
...
|
@@ -107,12 +105,12 @@ class WxloginController extends HomeBaseController |
|
|
Session::set('uid',$is_isset['id']);
|
|
|
}
|
|
|
} else {
|
|
|
$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";
|
|
|
$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";
|
|
|
Header("Location: $url");
|
|
|
exit;
|
|
|
}
|
|
|
}else{
|
|
|
$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";
|
|
|
$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";
|
|
|
Header("Location: $url");
|
|
|
exit;
|
|
|
}
|
...
|
...
|
|