$appid='xxxxxxx'; $redirect_uri = urlencode ( 'http://www.xxxxxxxx.com/xxx/xxxx/getuser' ); $url ="https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";
获取链接请求下一步操作
public function getuser() {//获取用户数据 if(isset($_GET['code'])) { $code = $_GET["code"]; $appId = $this->appId(); $appSecret = $this->appSecret(); $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appId&secret=$appSecret&code=$code&grant_type=authorization_code"; $res = $this->sendRequest($url); //得到openid以及accesstoken $data = json_decode($res); $access_token = $data['access_token']; $openId = $data['openid']; $getUserInfo = "https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openId&lang=zh_CN"; //得到用户详细参数 $user_info = $this->sendRequest($getUserInfo); //进行想要的逻辑....
} }
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); }
2 Comments
R XG牛笔
谢谢