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

调式微博登录

@@ -22,6 +22,9 @@ class LoginController extends HomeBaseController @@ -22,6 +22,9 @@ class LoginController extends HomeBaseController
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.xingqiu.cn/portal/login/wb_login';//回调地址 24 private $redirect_uri = 'http://www.xingqiu.cn/portal/login/wb_login';//回调地址
  25 +
  26 + private $appkey1 = 'wx9cfa880272f186bf';//微信appkey
  27 + private $appsecret1 = '11b643393b1e54d6ef5eaa984ba4e545';//微信appsecret
25 //登录页面 28 //登录页面
26 public function login(){ 29 public function login(){
27 return $this->fetch(); 30 return $this->fetch();
@@ -348,15 +351,20 @@ class LoginController extends HomeBaseController @@ -348,15 +351,20 @@ class LoginController extends HomeBaseController
348 351
349 //第三方微信登录 352 //第三方微信登录
350 public function wx_login(){ 353 public function wx_login(){
351 - $config = Config::get('wx_login');  
352 - $app_id = $config['app_id'];  
353 - $redirect_uri = $config['redirect_uri'];  
354 - $scope = $config['scope'];  
355 - $state = md5(uniqid(rand(), TRUE));  
356 - $url = 'https://open.weixin.qq.com/connect/qrconnect?appid='.$app_id.'&redirect_uri='.$redirect_uri.'&response_type=code&scope='.$scope.'&state='.$state.'#wechat_redirect'; 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';
357 $res = $this->http_get($url); 357 $res = $this->http_get($url);
358 - var_dump(11);  
359 - var_dump($res);exit; 358 + $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';
  363 + //通过access_token获取用户信息
  364 + $url1 = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$token.'&openid='.$openid;
  365 + $res1 = $this->http_get($url1);
  366 + $json_arr1 = json_decode($res1,true);
  367 + var_dump($json_arr1);exit;
360 } 368 }
361 369
362 //第三方微博登录 370 //第三方微博登录
@@ -391,6 +399,9 @@ class LoginController extends HomeBaseController @@ -391,6 +399,9 @@ class LoginController extends HomeBaseController
391 $user = $this->findThird($where); 399 $user = $this->findThird($where);
392 //获取微博id,昵称,头像 400 //获取微博id,昵称,头像
393 $userModel = new UserModel(); 401 $userModel = new UserModel();
  402 + $ip = get_client_ip();
  403 + $users['last_login_time'] = time();
  404 + $users['last_login_ip'] = $ip;
394 if($user){ 405 if($user){
395 $users['user_nickname'] = $info['screen_name']; 406 $users['user_nickname'] = $info['screen_name'];
396 $users['avatar'] = $info['profile_image_url']; 407 $users['avatar'] = $info['profile_image_url'];
@@ -424,8 +435,7 @@ class LoginController extends HomeBaseController @@ -424,8 +435,7 @@ class LoginController extends HomeBaseController
424 435
425 //取消授权 436 //取消授权
426 public function wb_cancel(){ 437 public function wb_cancel(){
427 - echo '取消了';  
428 -// $this->redirect('/'); 438 + $this->redirect('/');
429 } 439 }
430 440
431 //查询第三方用户是否存在 441 //查询第三方用户是否存在
@@ -34,7 +34,7 @@ @@ -34,7 +34,7 @@
34 <!--登陆--> 34 <!--登陆-->
35 <div class="login_right_main clearfix"> 35 <div class="login_right_main clearfix">
36 <div class="WeChat"> 36 <div class="WeChat">
37 - <a href=""><img src="__TMPL__/public/assets/starImg/aicon_89.png" alt=""></a> 37 + <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"><img src="__TMPL__/public/assets/starImg/aicon_89.png" alt=""></a>
38 </div> 38 </div>
39 <form action="https://api.weibo.com/oauth2/authorize" method="POST" id="wb_form"> 39 <form action="https://api.weibo.com/oauth2/authorize" method="POST" id="wb_form">
40 <div class="Sina" id="wb_login"> 40 <div class="Sina" id="wb_login">
@@ -197,6 +197,10 @@ $(function() { @@ -197,6 +197,10 @@ $(function() {
197 window.open('http://v.t.sina.com.cn/share/share.php?' + temp.join('&')); 197 window.open('http://v.t.sina.com.cn/share/share.php?' + temp.join('&'));
198 }); 198 });
199 199
  200 + $('.weibo_share').click(function() {
  201 + $('#wb_share').submit();
  202 + });
  203 +
200 //微博登录 204 //微博登录
201 $('#wb_login').click(function(){ 205 $('#wb_login').click(function(){
202 $('#wb_form').submit(); 206 $('#wb_form').submit();
@@ -204,8 +208,8 @@ $(function() { @@ -204,8 +208,8 @@ $(function() {
204 }); 208 });
205 209
206 //点赞收藏 210 //点赞收藏
207 -function operation(url, id = '') {  
208 - if (id == '') { 211 +function operation(url, id) {
  212 + if (id == '' || id == undefined) {
209 var article_id = getUrlParam('id'); 213 var article_id = getUrlParam('id');
210 } else { 214 } else {
211 var article_id = $('#li_id').val(); 215 var article_id = $('#li_id').val();
@@ -22,8 +22,14 @@ @@ -22,8 +22,14 @@
22 <p>168</p> 22 <p>168</p>
23 </div> 23 </div>
24 <!-- wb分享 --> 24 <!-- wb分享 -->
25 - <div class="wb_go weibo">  
26 - <img src="__TMPL__/public/assets/starImg/bicon_05.png" alt="">  
27 - <p>168</p>  
28 - </div> 25 + <form action="https://api.weibo.com/oauth2/authorize" method="POST" id="wb_share">
  26 + <div class="wb_go weibo_share">
  27 + <img src="__TMPL__/public/assets/starImg/bicon_05.png" alt="">
  28 + <p>168</p>
  29 + </div>
  30 + <input type="hidden" name="client_id" value="737607150">
  31 + <input type="hidden" name="redirect_uri" value="http://www.xingqiu.cn/portal/login/wb_login">
  32 + <input type="hidden" name="flag" value="1">
  33 + </form>
  34 +
29 </div> 35 </div>
@@ -264,8 +264,8 @@ function video_mask(msg) { @@ -264,8 +264,8 @@ function video_mask(msg) {
264 }, 6000); 264 }, 6000);
265 } 265 }
266 //点赞收藏 266 //点赞收藏
267 -function operation(url, id = '') {  
268 - if (id == '') { 267 +function operation(url,id) {
  268 + if (id == '' || id == undefined) {
269 var article_id = getUrlParam('id'); 269 var article_id = getUrlParam('id');
270 } else { 270 } else {
271 var article_id = $('#li_id').val(); 271 var article_id = $('#li_id').val();