|
@@ -21,7 +21,7 @@ class LoginController extends HomeBaseController |
|
@@ -21,7 +21,7 @@ class LoginController extends HomeBaseController |
21
|
private $limit = 8;//收藏,搜索分页
|
21
|
private $limit = 8;//收藏,搜索分页
|
22
|
private $appkey = 737607150;//微博appkey
|
22
|
private $appkey = 737607150;//微博appkey
|
23
|
private $appsecret = 'd80b43a1e74e8ba095590b36a3459480';//微博appsecret
|
23
|
private $appsecret = 'd80b43a1e74e8ba095590b36a3459480';//微博appsecret
|
24
|
- private $redirect_uri = 'http://www.starplanet.cn/portal/login/wb_login';//回调地址
|
24
|
+ private $redirect_uri = 'http://www.xingqiu.cn/portal/login/wb_login';//回调地址
|
25
|
|
25
|
|
26
|
private $appkey1 = 'wx9cfa880272f186bf';//微信appkey
|
26
|
private $appkey1 = 'wx9cfa880272f186bf';//微信appkey
|
27
|
private $appsecret1 = '11b643393b1e54d6ef5eaa984ba4e545';//微信appsecret
|
27
|
private $appsecret1 = '11b643393b1e54d6ef5eaa984ba4e545';//微信appsecret
|
|
@@ -352,19 +352,44 @@ class LoginController extends HomeBaseController |
|
@@ -352,19 +352,44 @@ class LoginController extends HomeBaseController |
352
|
//第三方微信登录
|
352
|
//第三方微信登录
|
353
|
public function wx_login(){
|
353
|
public function wx_login(){
|
354
|
$code = $this->request->get('code');
|
354
|
$code = $this->request->get('code');
|
355
|
- $code = '021HoCq91Re1wP1g5Eo91Vgnq91HoCqd';
|
|
|
356
|
$url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$this->appkey1.'&secret='.$this->appsecret1.'&code='.$code.'&grant_type=authorization_code';
|
355
|
$url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$this->appkey1.'&secret='.$this->appsecret1.'&code='.$code.'&grant_type=authorization_code';
|
357
|
$res = $this->http_get($url);
|
356
|
$res = $this->http_get($url);
|
358
|
$json_arr = json_decode($res,true);
|
357
|
$json_arr = json_decode($res,true);
|
359
|
-// $token = $json_arr['access_token'];
|
|
|
360
|
- $token = '22_LFufsKgmxT1jCtIuDJ7CLLwAOI7mOPlmNYHRHECuScIwrNZ3-Bmxj8pOjr2NZs7qdzH7iBkPddFtBdyVoBd7zas_gkQhDw3YJgm5iYa6d5w';
|
|
|
361
|
-// $openid = $json_arr['openid'];
|
|
|
362
|
- $openid = 'oYOYl5hbULoKimG5R8Uk-Paha0d8';
|
358
|
+
|
|
|
359
|
+ if(!isset($json_arr['access_token'])&&empty($json_arr['access_token'])){
|
|
|
360
|
+ //用户取消登录
|
|
|
361
|
+ $this->redirect('/portal/login/thirdLogin');
|
|
|
362
|
+ }
|
|
|
363
|
+ $token = $json_arr['access_token'];
|
|
|
364
|
+ $openid = $json_arr['openid'];
|
363
|
//通过access_token获取用户信息
|
365
|
//通过access_token获取用户信息
|
364
|
$url1 = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$token.'&openid='.$openid;
|
366
|
$url1 = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$token.'&openid='.$openid;
|
365
|
$res1 = $this->http_get($url1);
|
367
|
$res1 = $this->http_get($url1);
|
366
|
- $json_arr1 = json_decode($res1,true);
|
|
|
367
|
- var_dump($json_arr1);exit;
|
368
|
+ $info = json_decode($res1,true);
|
|
|
369
|
+ //查询该微信用户是否存在
|
|
|
370
|
+ $where = ['wb_id'=>$info['openid'],'source'=>'微信'];
|
|
|
371
|
+ $user = $this->findThird($where);
|
|
|
372
|
+ //获取微博id,昵称,头像
|
|
|
373
|
+ $userModel = new UserModel();
|
|
|
374
|
+ $ip = get_client_ip();
|
|
|
375
|
+ $users['last_login_time'] = time();
|
|
|
376
|
+ $users['last_login_ip'] = $ip;
|
|
|
377
|
+ if($user){
|
|
|
378
|
+ $users['user_nickname'] = $info['nickname'];
|
|
|
379
|
+ $users['avatar'] = $info['headimgurl'];
|
|
|
380
|
+ $userModel->where(['wb_id'=>$info['openid'],'source'=>'微信'])->update($users);
|
|
|
381
|
+ }else{
|
|
|
382
|
+ $users['wb_id'] = $info['openid'];
|
|
|
383
|
+ $users['user_nickname'] = $info['nickname'];
|
|
|
384
|
+ $users['avatar'] = $info['headimgurl'];
|
|
|
385
|
+ $users['source'] = '微信';
|
|
|
386
|
+ $users['user_type'] = 2;
|
|
|
387
|
+ $users['create_time'] = time();
|
|
|
388
|
+ $userModel->create($users);
|
|
|
389
|
+ }
|
|
|
390
|
+ $userInfo = $this->findThird($where);
|
|
|
391
|
+ cmf_update_current_user($userInfo);
|
|
|
392
|
+ $this->redirect('/');
|
368
|
}
|
393
|
}
|
369
|
|
394
|
|
370
|
//第三方微博登录
|
395
|
//第三方微博登录
|
|
@@ -387,15 +412,6 @@ class LoginController extends HomeBaseController |
|
@@ -387,15 +412,6 @@ class LoginController extends HomeBaseController |
387
|
$this->redirect('/portal/login/thirdLogin');
|
412
|
$this->redirect('/portal/login/thirdLogin');
|
388
|
}
|
413
|
}
|
389
|
$token = $json_arr['access_token'];
|
414
|
$token = $json_arr['access_token'];
|
390
|
-
|
|
|
391
|
- $url = 'https://api.weibo.com/2/statuses/share.json';
|
|
|
392
|
- $data = [
|
|
|
393
|
- 'access_token' => $token,
|
|
|
394
|
- 'status' => URLencode('http://www.starplanet.cn/portal/enjoy/getEnjoyDetail?id=52')
|
|
|
395
|
- ];
|
|
|
396
|
- $res = $this->http_post($url,$data);
|
|
|
397
|
- $json_arr = json_decode($res,true);
|
|
|
398
|
- var_dump($json_arr);exit;
|
|
|
399
|
//存token到session
|
415
|
//存token到session
|
400
|
session('token', $token);
|
416
|
session('token', $token);
|
401
|
$uid = $json_arr['uid'];
|
417
|
$uid = $json_arr['uid'];
|
|
@@ -426,8 +442,7 @@ class LoginController extends HomeBaseController |
|
@@ -426,8 +442,7 @@ class LoginController extends HomeBaseController |
426
|
}
|
442
|
}
|
427
|
$userInfo = $this->findThird($where);
|
443
|
$userInfo = $this->findThird($where);
|
428
|
cmf_update_current_user($userInfo);
|
444
|
cmf_update_current_user($userInfo);
|
429
|
- $this->wb_share();
|
|
|
430
|
-// $this->redirect('/');
|
445
|
+ $this->redirect('/');
|
431
|
}
|
446
|
}
|
432
|
|
447
|
|
433
|
//微博分享
|
448
|
//微博分享
|