github : https://github.com/xjnotxj/wechat_interaction_authphp
xxx爲config.js中的
WECHAT_DOMAIN
git
xxx/?route=auth&redirect_uri=http://www.baidu.com/&scope=snsapi_base&state=123github
xxx/?route=auth&redirect_uri=http://www.baidu.com/&scope=snsapi_userinfo&state=123json
參數 | 描述 | 例子 |
---|---|---|
redirect_uri | 獲取用戶信息後回調的url | encodeURIComponent('http://www.baidu.com') |
scope | snsapi_base / snsapi_userinfo [默認snsapi_base] | snsapi_base 靜默受權,返回info=openid / snsapi_userinfo 非靜默受權,返回完整用戶信息:info={用戶信息json格式字符串} |
state | 回調後會帶上state參數,能夠填寫a-zA-Z0-9 | 123 |
調用成功後示例:api
http://www.baidu.com?info=oJT88wHBcuAwp7fCvJ9VvS1iE4zg&state=123數組
info爲openid微信
state爲初始帶來的參數微信公衆平臺
調用成功後示例:oop
info格式化後的字段以下:
openid | 用戶的惟一標識 |
---|---|
nickname | 用戶暱稱 |
sex | 用戶的性別,值爲1時是男性,值爲2時是女性,值爲0時是未知 |
province | 用戶我的資料填寫的省份 |
city | 普通用戶我的資料填寫的城市 |
country | 國家,如中國爲CN |
headimgurl | 用戶頭像,最後一個數值表明正方形頭像大小(有0、4六、6四、9六、132數值可選,0表明640*640正方形頭像),用戶沒有頭像時該項爲空 |
privilege | 用戶特權信息,json 數組,如微信沃卡用戶爲(chinaunicom) |
state爲初始帶來的參數
一、此接口請先配置/config.php
文件
二、微信公衆平臺裏,在開發 - 接口權限 - 網頁服務 - 網頁賬號 - 網頁受權獲取用戶基本信息」的配置選項中,修改受權回調域名。