Commit 0393c19f authored by clone's avatar clone

微信授权

parent ec7a6d5e
......@@ -81,7 +81,7 @@ class WxCallbackUntils
'province' => $user_info->province,
'city' => $user_info->city,
'buyer_img' => $user_info->headimgurl,
'union_id' => $user_info->unionid,
'wx_union_id' => $user_info->unionid,
);
session("userInfo", $data);
return $data;
......
......@@ -6,7 +6,10 @@ use app\api\untils\WxCallbackUntils;
use app\model\AppVersion;
use app\model\HouseImgs;
use app\model\HouseInfos;
use app\model\Users;
use app\model\UWxInfo;
use think\Controller;
use think\Exception;
use think\Log;
use think\Response;
......@@ -15,29 +18,55 @@ class Index
private $url = CURRENT_URL . "/app_broker/index";
private $_wxApi;
private $wxInfoModel;
private $userModel;
public function __construct()
{
$this->_wxApi = new WxCallbackUntils();
$this->wxInfoModel = new UWxInfo();
$this->userModel = new Users();
}
public function index()
{
$code = empty($_GET['code']) ? null : $_GET['code'];
$userInfo = session("userInfo");
if (!$code) {
$this->_wxApi->getWxCode($this->url);
} else {
$this->_wxApi->getUserInfoByAccessToken($code);
$userInfo = $this->_wxApi->getUserInfoByAccessToken($code);
Log::record("session wx -----------------" . json_encode($userInfo), "info");
if (!$userInfo) {
$this->_wxApi->getWxCode($this->url);
} else {
dump($userInfo);
return view("index/index");
$userInfo["source"] = 0;
$wx_union_id = $userInfo["wx_union_id"];
// 验证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 @@
namespace app\index\controller;
use app\api\controller\WxSdk;
use app\api\untils\WxCallbackUntils;
use app\index\extend\Basic;
use Think\Log;
......@@ -37,6 +38,7 @@ class WxAuthorization extends Basic
if (!$userInfo) {
$this->_wxApi->getWxCode($this->url);
} else {
//saveWxInfo();
dump($userInfo);
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