Commit 0393c19f authored by clone's avatar clone

微信授权

parent ec7a6d5e
...@@ -81,7 +81,7 @@ class WxCallbackUntils ...@@ -81,7 +81,7 @@ class WxCallbackUntils
'province' => $user_info->province, 'province' => $user_info->province,
'city' => $user_info->city, 'city' => $user_info->city,
'buyer_img' => $user_info->headimgurl, 'buyer_img' => $user_info->headimgurl,
'union_id' => $user_info->unionid, 'wx_union_id' => $user_info->unionid,
); );
session("userInfo", $data); session("userInfo", $data);
return $data; return $data;
......
...@@ -6,7 +6,10 @@ use app\api\untils\WxCallbackUntils; ...@@ -6,7 +6,10 @@ use app\api\untils\WxCallbackUntils;
use app\model\AppVersion; use app\model\AppVersion;
use app\model\HouseImgs; use app\model\HouseImgs;
use app\model\HouseInfos; use app\model\HouseInfos;
use app\model\Users;
use app\model\UWxInfo;
use think\Controller; use think\Controller;
use think\Exception;
use think\Log; use think\Log;
use think\Response; use think\Response;
...@@ -15,29 +18,55 @@ class Index ...@@ -15,29 +18,55 @@ class Index
private $url = CURRENT_URL . "/app_broker/index"; private $url = CURRENT_URL . "/app_broker/index";
private $_wxApi; private $_wxApi;
private $wxInfoModel;
private $userModel;
public function __construct() public function __construct()
{ {
$this->_wxApi = new WxCallbackUntils(); $this->_wxApi = new WxCallbackUntils();
$this->wxInfoModel = new UWxInfo();
$this->userModel = new Users();
} }
public function index() public function index()
{ {
$code = empty($_GET['code']) ? null : $_GET['code']; $code = empty($_GET['code']) ? null : $_GET['code'];
$userInfo = session("userInfo");
if (!$code) { if (!$code) {
$this->_wxApi->getWxCode($this->url); $this->_wxApi->getWxCode($this->url);
} else { } else {
$this->_wxApi->getUserInfoByAccessToken($code); $userInfo = $this->_wxApi->getUserInfoByAccessToken($code);
Log::record("session wx -----------------" . json_encode($userInfo), "info"); Log::record("session wx -----------------" . json_encode($userInfo), "info");
if (!$userInfo) { if (!$userInfo) {
$this->_wxApi->getWxCode($this->url); $this->_wxApi->getWxCode($this->url);
} else { } else {
$userInfo["source"] = 0;
dump($userInfo); $wx_union_id = $userInfo["wx_union_id"];
return view("index/index");
// 验证open_id是否已经存在,存在则更新
$wxInfoObj = $this->wxInfoModel->getWxInfoByOpenId($wx_union_id);
try {
if ($wxInfoObj && count($wxInfoObj) > 0) {
$userInfo["id"] = $wxInfoObj[0]["id"];
$id = $this->wxInfoModel->updateWxInfo($userInfo);
} else {
$id = $this->wxInfoModel->addWxInfo($userInfo);
}
} catch (Exception $exception) {
Log::record("wx authorization error,msg:".$exception);
}
$conditions["buyer_id"] = $id;
$fields = "id,user_nick,user_phone,user_pic,other_pic";
$user_info = $this->userModel->getUserByWhere($conditions, $fields);
if(count($user_info) > 0){
//下载页
header(CURRENT_URL."app/download_c");
die();
}else{
//绑定页
header(CURRENT_URL."app/dist/index.html#/inviteRegister");
die();
}
} }
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace app\index\controller; namespace app\index\controller;
use app\api\controller\WxSdk;
use app\api\untils\WxCallbackUntils; use app\api\untils\WxCallbackUntils;
use app\index\extend\Basic; use app\index\extend\Basic;
use Think\Log; use Think\Log;
...@@ -37,6 +38,7 @@ class WxAuthorization extends Basic ...@@ -37,6 +38,7 @@ class WxAuthorization extends Basic
if (!$userInfo) { if (!$userInfo) {
$this->_wxApi->getWxCode($this->url); $this->_wxApi->getWxCode($this->url);
} else { } else {
//saveWxInfo();
dump($userInfo); dump($userInfo);
return view("test"); return view("test");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment