獲取codephp
https://open.weixin.qq.com/connect/oauth2/authorize?appid=這裏是你的公衆號的APPID&redirect_uri=http://www.xx.com/getcode&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirecthtml
用戶點擊確認登陸,自動跳轉下面地址獲得codejson
http://www.xiaohuang.cc/post/437.htmlapi
http://www.xx.com/getcode 這個是你本身的跳轉地址數組
http://www.xx.com/getcode?code=0064f7afef7af7b395147bfe8b51f7bf&state=123微信
後面的這個 ?code=……123 是微信自動跳轉添加的,不是你本身加的app
下面是PHP語言,寫在getcode這個頁面裏post
1
2
3
4
5
|
$code
=
$_GET
[
'code'
];
//獲取code
$weixin
=
file_get_contents
(
"https://api.weixin.qq.com/sns/oauth2/access_token?appid=這裏是你的APPID&secret=這裏是你的SECRET&code="
.
$code
.
"&grant_type=authorization_code"
);//經過code換取網頁受權access_token
$jsondecode
= json_decode(
$weixin
);
//對JSON格式的字符串進行編碼
$array
= get_object_vars(
$jsondecode
);
//轉換成數組
$openid
=
$array
[
'openid'
];
//輸出openid
|
怎麼樣,是否是灰常的簡單?!小皇研究了三四天整理出這麼簡單的方法編碼
別謝哥,謝國家!spa
本文禁止轉載!