Commit 6d152eea by 冷斌

fix bug

parent 30c39096
...@@ -86,14 +86,20 @@ class PassportAction extends CommonAction ...@@ -86,14 +86,20 @@ class PassportAction extends CommonAction
} else { } else {
$pageKeyData = model('Xdata')->get('admin_Config:wxpay'); $pageKeyData = model('Xdata')->get('admin_Config:wxpay');
if (empty($_GET['code']) && !empty($pageKeyData['mp_appid'])) {
$appId = $pageKeyData['mp_appid']; $appId = $pageKeyData['mp_appid'];
if (empty($_GET['code']) && !empty($pageKeyData['mp_appid'])) {
$redirect_uri = urlencode('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']); $redirect_uri = urlencode('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
$reurl2 ="https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appId&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"; $reurl2 ="https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appId&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
header("Location:{$reurl2}"); header("Location:{$reurl2}");
exit(); exit();
}else { }else {
var_dump($_GET['code']); $code = $_GET["code"];
// appId与appSecret
$appSecret = $pageKeyData['mp_api_secret'];
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appId&secret=$appSecret&code=$code&grant_type=authorization_code";
$res = $this->sendRequest($url);
var_dump($res);
$openId = $res['openid'];
die; die;
} }
} }
...@@ -108,6 +114,18 @@ class PassportAction extends CommonAction ...@@ -108,6 +114,18 @@ class PassportAction extends CommonAction
$this->display(); $this->display();
} }
public function sendRequest($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output, true);
}
/** /**
* 快速登录 * 快速登录
*/ */
......
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