<?php
$appId = 'xxx'; // 公众号AppId
$appSecret = 'xxx'; // 公众号AppSecret
$code = $_GET['code'];
$state = $_GET['state'];
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appId&secret=$appSecret&code={$code}&grant_type=authorization_code";
$a = file_get_contents($url);
switch($state){
case 'project1':
preg_match_all("/\"openid\":\"(.*?)\"/", $a, $matches, PREG_SET_ORDER);
$openid = $matches[0][1];
$json=(array)json_decode($a);
if(!isset($json['errcode'])){
$openid = $json['openid'];
$url ="https://api.weixin.qq.com/sns/userinfo?access_token=".$json['access_token']."&openid=".$json['openid'];
$a = file_get_contents($url);
$json = (array)json_decode($a);
$nickname = $json['nickname'];
$headimgurl = $json['headimgurl'];
header("Location:http://xxx/index.html?openid=$openid&nickname=$nickname&headimgurl=$headimgurl");
}else{
}
break;
/*
case 'project2':
...
break;
*/
default:
echo "ERROR";
}
?>
高飞家的猫
- 粉丝: 77
- 资源: 10
最新资源
- (源码)基于SSM框架的大学消息通知系统服务端.zip
- (源码)基于Java Servlet的学生信息管理系统.zip
- (源码)基于Qt和AVR的FestosMechatronics系统终端.zip
- (源码)基于Java的DVD管理系统.zip
- (源码)基于Java RMI的共享白板系统.zip
- (源码)基于Spring Boot和WebSocket的毕业设计选题系统.zip
- (源码)基于C++的机器人与船舶管理系统.zip
- (源码)基于WPF和Entity Framework Core的智能货架管理系统.zip
- SAP Note 532932 FAQ Valuation logic with active material ledger
- (源码)基于Spring Boot和Redis的秒杀系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页