Commit 395cf1f7 authored by zhuwei's avatar zhuwei

微信

parent 1613d4b7
......@@ -39,6 +39,13 @@ class WxCallbackUntils
header("Location:" . $url);
}
public function getWxCodesnSapiBase($redirect_url)
{
$redirect_url = urlencode($redirect_url);
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $this->appId . "&redirect_uri="
. $redirect_url . "&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
header("Location:" . $url);
}
/**
* 获取access_token
......@@ -90,6 +97,21 @@ class WxCallbackUntils
return $data;
}
/**
* 获取用户信息
* @param $code
* @return array
*/
public function getUserOpenId($code)
{
$access_token_info = $this->getAccessTokenByCode($code);
$access_token_info = json_decode($access_token_info);
$open_id = $access_token_info->openid;
return $open_id;
}
public function curl($url, $data = [])
{
$ch = curl_init();
......
......@@ -21,6 +21,7 @@ class WxAuthorization extends Basic
public function __construct()
{
parent::__construct();
$this->_wxApi = new WxCallbackUntils();
$this->url = CURRENT_URL . "/index/getWxInfo";
}
......@@ -50,12 +51,23 @@ class WxAuthorization extends Basic
public function getWxInfoV2()
{
$code = empty($_GET['code']) ? null : $_GET['code'];
if (!$code) {
$this->_wxApi->getWxCode(CURRENT_URL . "/index/getWxInfoV2");
$this->_wxApi->getWxCodesnSapiBase(CURRENT_URL . "/index/getWxInfoV2");
} else {
$userInfo = $this->_wxApi->getUserInfoByAccessToken($code);
dump($userInfo);
$userInfo = $this->_wxApi->getUserOpenId($code);
$data = [
'id' => '2',
'housename' => '怡华苑路304号',
'user_tel' => '13918937741',
'user_name' => '于盼盼',
'share' => '1',
'client' => 'b',
];
$this->assign('data',json_encode($data));
return view("share_detail");
}
}
......
......@@ -64,6 +64,7 @@ class Basic extends Controller
'index/getAllDisc',
'index/getAgentGroupSite',
'index/getRandKingList',
'index/getWxInfoV2',
);
/**
......@@ -77,6 +78,7 @@ class Basic extends Controller
*/
public function __construct(Request $request = null)
{
parent::__construct();
// CORS 跨域 Options 检测响应
$this->corsOptionsHandler();
// 输入对象
......
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