
本文共 5490 字,大约阅读时间需要 18 分钟。
���������������������������������������������
������������������������������������������������������������������������������������������������
���������������������������������������������������������������"������"���������������"������������������"���"������������"������������������������������������������������������������������
a. ���������������.Drawable������������
���������������������������������������������������������������������������������������������������������������������wx.xxx.com���������_DRAWABLE���������������������������������������������������������������������������������������������������������������������
b. ������������code���������
������������������������������������������������������code���������������������������������������������������redirect_uri���������������������������������������������������������������������������������������������������������������������������������������������������������
c. ������������������������������
���������������������������������������������������������������������������������������������������������������������������ID���������������������
- ������������������code���������������
- ���������������������������������������
- PHP������������������
- ���������������������������
������������������������������������������������code������������������������������������������������������������URL������������������������������������������
a. ������wxid������
������URL���������������������������������������������wxid���������������������������������������������������������
b. ������state������
������������CSRF������������������state������������������������������������������������������
c. ������������������
���������������wxid���state������������������������������������������������URL���������������������������������������������������������
URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URL&response_type=code&scope=SCOPE&state=STATE"
���������APPID���������ID���REDIRECT_URL���������������������������������SCORE������������������������snsapi_userinfo���������������������URL������������������������������
���������������������������������������code������������������REDIRECT_URL������������������������������������������code������������API������access_token���openid���
a. ���������������code������
������������������������code���state���������������������������������������������������CSRF���������������
b. ������������access_token���������
���������������������API���������code���app_id���app_secret������������������������������������������������OPENID���
c. ������������������������
������������������������������������������������������������������������������������������������������������������������������������������������
������������������������������������������PHP���������
function wxauthorize() { global $.getConfig;
// ������code���state������$code = isset($_GET['code']) ? $_GET['code'] : '';$state = isset($_GET['state']) ? $_GET['state'] : '';$validate_State = $getConfig('auth_validate_state');if ($validate_State && !$validate_State->isStateValid($state)) { echo "���������������"; exit();}// ������������������������$data = M('userbindingwxconfig')->where('id='.$getConfig['wx_id'])->select();if (empty($data)) { echo "���������������������"; exit();}$appid = $data[0]['appId'];$appsecret = $data[0]['appSecret'];// ������access_token���openid$token_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$appsecret."&code=".$code."&grant_type=authorization_code";$token_data = file_get_contents($token_url);if ($token_data === false) { echo "������token������"; exit();}$token_obj = (array) json_decode($token_data, true);$access_token = $token_obj['access_token'] ?? '';$openid = $token_obj['openid'] ?? '';if (empty($access_token) || empty($openid)) { echo "���������������������"; exit();}// ������������������������$userinfo_url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid."&lang=zh_CN";$userinfo = file_get_contents($userinfo_url);if ($userinfo === false) { echo "������������������������"; exit();}$user_data = (array) json_decode($userinfo, true);return $user_data;
}
������������������������������������������������������������������������������������
���������������������������������������������������������������������������
a. IISRewriteRule������
���������������������URL���������������������������IIS������������������������Web���������������������������������������������
b. ���������������������
���������APPID���APPSECRET��������� secretion leak���������������state���������������������������CSRF���������
c. ������������������
������������������������������������������������������������������������������������������������������������URL������������
d. ������������������
��� Fehler������������������������������������error handling���������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
