作者 景龙
1 个管道 的构建 通过 耗费 3 秒

微信登录

... ... @@ -21,7 +21,7 @@ class LoginController extends HomeBaseController
private $limit = 8;//收藏,搜索分页
private $appkey = 737607150;//微博appkey
private $appsecret = 'd80b43a1e74e8ba095590b36a3459480';//微博appsecret
private $redirect_uri = 'http://www.starplanet.cn/portal/login/wb_login';//回调地址
private $redirect_uri = 'http://www.xingqiu.cn/portal/login/wb_login';//回调地址
private $appkey1 = 'wx9cfa880272f186bf';//微信appkey
private $appsecret1 = '11b643393b1e54d6ef5eaa984ba4e545';//微信appsecret
... ... @@ -352,19 +352,44 @@ class LoginController extends HomeBaseController
//第三方微信登录
public function wx_login(){
$code = $this->request->get('code');
$code = '021HoCq91Re1wP1g5Eo91Vgnq91HoCqd';
$url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$this->appkey1.'&secret='.$this->appsecret1.'&code='.$code.'&grant_type=authorization_code';
$res = $this->http_get($url);
$json_arr = json_decode($res,true);
// $token = $json_arr['access_token'];
$token = '22_LFufsKgmxT1jCtIuDJ7CLLwAOI7mOPlmNYHRHECuScIwrNZ3-Bmxj8pOjr2NZs7qdzH7iBkPddFtBdyVoBd7zas_gkQhDw3YJgm5iYa6d5w';
// $openid = $json_arr['openid'];
$openid = 'oYOYl5hbULoKimG5R8Uk-Paha0d8';
if(!isset($json_arr['access_token'])&&empty($json_arr['access_token'])){
//用户取消登录
$this->redirect('/portal/login/thirdLogin');
}
$token = $json_arr['access_token'];
$openid = $json_arr['openid'];
//通过access_token获取用户信息
$url1 = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$token.'&openid='.$openid;
$res1 = $this->http_get($url1);
$json_arr1 = json_decode($res1,true);
var_dump($json_arr1);exit;
$info = json_decode($res1,true);
//查询该微信用户是否存在
$where = ['wb_id'=>$info['openid'],'source'=>'微信'];
$user = $this->findThird($where);
//获取微博id,昵称,头像
$userModel = new UserModel();
$ip = get_client_ip();
$users['last_login_time'] = time();
$users['last_login_ip'] = $ip;
if($user){
$users['user_nickname'] = $info['nickname'];
$users['avatar'] = $info['headimgurl'];
$userModel->where(['wb_id'=>$info['openid'],'source'=>'微信'])->update($users);
}else{
$users['wb_id'] = $info['openid'];
$users['user_nickname'] = $info['nickname'];
$users['avatar'] = $info['headimgurl'];
$users['source'] = '微信';
$users['user_type'] = 2;
$users['create_time'] = time();
$userModel->create($users);
}
$userInfo = $this->findThird($where);
cmf_update_current_user($userInfo);
$this->redirect('/');
}
//第三方微博登录
... ... @@ -387,15 +412,6 @@ class LoginController extends HomeBaseController
$this->redirect('/portal/login/thirdLogin');
}
$token = $json_arr['access_token'];
$url = 'https://api.weibo.com/2/statuses/share.json';
$data = [
'access_token' => $token,
'status' => URLencode('http://www.starplanet.cn/portal/enjoy/getEnjoyDetail?id=52')
];
$res = $this->http_post($url,$data);
$json_arr = json_decode($res,true);
var_dump($json_arr);exit;
//存token到session
session('token', $token);
$uid = $json_arr['uid'];
... ... @@ -426,8 +442,7 @@ class LoginController extends HomeBaseController
}
$userInfo = $this->findThird($where);
cmf_update_current_user($userInfo);
$this->wb_share();
// $this->redirect('/');
$this->redirect('/');
}
//微博分享
... ...
... ... @@ -41,7 +41,7 @@
<img src="__TMPL__/public/assets/starImg/aicon_90.png" alt="">
</div>
<input type="hidden" name="client_id" value="737607150">
<input type="hidden" name="redirect_uri" value="http://www.starplanet.cn/portal/login/wb_login">
<input type="hidden" name="redirect_uri" value="http://www.xingqiu.cn/portal/login/wb_login">
</form>
</div>
</div>
... ...
... ... @@ -28,7 +28,7 @@
<p>168</p>
</div>
<input type="hidden" name="client_id" value="737607150">
<input type="hidden" name="redirect_uri" value="http://www.starplanet.cn/portal/login/wb_login">
<input type="hidden" name="redirect_uri" value="http://www.xingqiu.cn/portal/login/wb_login">
<input type="hidden" name="flag" value="1">
</form>
... ...
... ... @@ -44,9 +44,11 @@
<div class="index_tenth_seconds">
<div class="index_tenth_second">
<div class="index_tenth_second_one">
<div class="index_tenth_second_img">
<img src="__TMPL__/public/assets/images/cicon_71@2x.png" alt="" />
</div>
<a href="https://open.weixin.qq.com/connect/qrconnect?appid=wx9cfa880272f186bf&redirect_uri=http://www.starplanet.cn/portal/login/wx_login&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect">
<div class="index_tenth_second_img">
<img src="__TMPL__/public/assets/images/cicon_71@2x.png" alt="" />
</div>
</a>
<div class="index_tenth_second_title">
微信登录
</div>
... ...