소스 검색

debug wechat author

stanley-king 8 년 전
부모
커밋
9baaa9546d
6개의 변경된 파일13개의 추가작업 그리고 130개의 파일을 삭제
  1. 11 0
      helper/session_helper.php
  2. 0 1
      helper/third_author/wxauthor.php
  3. 0 89
      mobile/api/wxLogin/callback.php
  4. 0 16
      mobile/api/wxLogin/config.php
  5. 0 16
      mobile/api/wxLogin/index.php
  6. 2 8
      mobile/wxauthor.php

+ 11 - 0
helper/session_helper.php

@@ -287,20 +287,31 @@ class session_helper
         }
         else
         {
+            Log::record("need_wechat_author 1",Log::DEBUG);
             if(array_key_exists('wx_author',$_SESSION))
             {
+                Log::record("need_wechat_author 2 0",Log::DEBUG);
+
                 if(array_key_exists('handled',$_SESSION['wx_author']))
                 {
+                    Log::record("need_wechat_author 2",Log::DEBUG);
+
                     $user_info = $_SESSION['wx_author']['user_info'];
                     $loginer = new login_helper();
                     if(self::logined()) {
+                        Log::record("need_wechat_author 3",Log::DEBUG);
+
                         $loginer->bind_wechat($user_info);
                         unset($_SESSION['wx_author']);
                     }
                     else
                     {
+                        Log::record("need_wechat_author 4",Log::DEBUG);
+
                         if($loginer->wechat_login($user_info['openid']) == true)
                         {
+                            Log::record("need_wechat_author 5",Log::DEBUG);
+
                             $loginer->bind_wechat($user_info);
                             unset($_SESSION['wx_author']);
                         }

+ 0 - 1
helper/third_author/wxauthor.php

@@ -57,7 +57,6 @@ class wxauthor
             Log::record("wxauthor user_info error code:{$this->mErrcode} msg:{$this->mErrmsg}");
             return false;
         } else {
-
             return $user_info;
         }
     }

+ 0 - 89
mobile/api/wxLogin/callback.php

@@ -1,89 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: james
- * Date: 2017/4/25
- * Time: 下午3:43
- */
-
-include 'config.php';
-//判断state是否正确
-if(empty($_GET['state'])) {
-    exit('参数错误,请重新登录');
-}
-
-if($_GET['state'] != $_SESSION['state']) {
-    exit('<script>alert("参数错误!"); 
-    location.href="../login.php";</script>');
-}
-
-//检查用户是否同意授权
-if(empty($_GET['code'])) {
-    exit('<script>alert("您没有同意授权!"); 
-    location.href="../login.php";</script>');
-}
-
-/*
- * 通过code换取网页授权access_token
- * https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
- */
-$url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.appID.
-    '&secret='.appsecret.
-    '&code='.$_GET['code'].
-    '&grant_type=authorization_code';
-//通过curl获取access_token
-$res  = myCurl($url);
-/*
- * 正确返回
- * { "access_token":"ACCESS_TOKEN","expires_in":7200, "refresh_token":"REFRESH_TOKEN","openid":"OPENID","scope":"SCOPE" }
- * 错误返回
- * {"errcode":40029,"errmsg":"invalid code"}
- */
-
-//将json信息转换为数组
-$info = json_decode($res, true);
-//判断是否成功
-if(empty($info['access_token'])){
-    exit('参数错误,请重新登录...');
-}
-
-/* 获取用户信息
- * 请求地址:
- * https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN
- * 正确时返回的JSON数据包如下:
- * openid 用户的唯一标识
- * nickname 用户昵称
- * 其他相信查看手册
- * 错误时微信会返回JSON数据包如下(示例为openid无效):
- * {"errcode":40003,"errmsg":" invalid openid "}
-*/
-$url = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$info['access_token'].'&openid='.$info['openid'].'&lang=zh_CN';
-$res  = myCurl($url);
-//将json信息转换为数组
-$user = json_decode($res, true);
-if(!empty($user['errcode'])) {
-    exit('参数错误,请重新登录...');
-}
-
-//注册session 并返回登录页面
-$_SESSION['wxopenid'] = $user['openid'];
-$_SESSION['uface']    = $user['headimgurl'];
-$_SESSION['uname']    = $user['nickname'];
-
-header('location:');
-
-function myCurl($url, $type = 'GET', $data = null){
-    $curl = curl_init();
-    curl_setopt($curl, CURLOPT_URL            , $url);
-    curl_setopt($curl, CURLOPT_RETURNTRANSFER , true);
-    if($type != 'GET'){
-        curl_setopt($curl, CURLOPT_POST, 1);
-        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
-    }
-    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER , false);
-    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST , false);
-    curl_setopt($curl, CURLOPT_ENCODING       , 'gzip,deflate');
-    $res  = curl_exec($curl);
-    curl_close($curl);
-    return $res;
-}

+ 0 - 16
mobile/api/wxLogin/config.php

@@ -1,16 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: james
- * Date: 2017/4/25
- * Time: 下午3:42
- */
-//开启session
-define('appID'           ,   'wx6b42e00ecaade538');
-//appsecret
-define('appsecret'       ,   'ee64233b3144d76217161666f8cb4c86');
-//微信登录成功返回的页面(回调页面)
-//define('BACKURL'         ,   'http://a.lrlz.com/mobile/api/wxLogin/callback.php');
-define('BACKURL'         ,   'http://a.lrlz.com/mobile/wxauthor.php');
-//微信登录所需的access_token信息存放文件位置
-define('TOKEN_FILE'      ,    'access_token.json');

+ 0 - 16
mobile/api/wxLogin/index.php

@@ -1,16 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: james
- * Date: 2017/4/25
- * Time: 下午3:43
- */
-include 'config.php';
-//设置state 一个随机码并使用session记录
-$_SESSION['state'] = md5(rand(111111, 99999999));
-
-$url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.appID.'&redirect_uri='.urlencode(BACKURL).'&response_type=code&scope=snsapi_userinfo&state='.$_SESSION['state'].'#wechat_redirect';
-//跳转即可
-Log::record("url={$url}",Log::DEBUG);
-
-fcgi_header("location:{$url}");

+ 2 - 8
mobile/wxauthor.php

@@ -9,8 +9,8 @@
 require_once (BASE_ROOT_PATH . '/helper/third_author/wxauthor.php');
 require_once (BASE_ROOT_PATH . '/helper/session.php');
 
-//ini_set('date.timezone','Asia/Shanghai');
-//error_reporting(E_ERROR);
+ini_set('date.timezone','Asia/Shanghai');
+error_reporting(E_ERROR);
 
 $code = $_GET['code'];
 if(empty($code)) {
@@ -39,11 +39,5 @@ else
                 fcgi_header("location:{$origin_url}");
             }
         }
-
-//        $sid = $_GET['state'];
-//        $data = session::read_other_session($sid);
-//        $data['wx_author']['user_info'] = $user_info;
-//        $data['wx_author']['handled'] = false;
-//        session::write_other_session($sid,$data);
     }
 }