時(shí)間:2022-07-24 01:39:01 | 來源:網(wǎng)站運(yùn)營
時(shí)間:2022-07-24 01:39:01 來源:網(wǎng)站運(yùn)營
https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
以上鏈接進(jìn)行配置后,進(jìn)行點(diǎn)擊訪問或跳轉(zhuǎn)。https://open.weixin.qq.com/connect/oauth2/authorize?appid=你公眾號(hào)的APPID&redirect_uri=你服務(wù)器的接收code的頁面鏈接&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect
點(diǎn)擊允許,將會(huì)開始獲取code,并且跳轉(zhuǎn)到你的redirect_uri,redirect_uri就是你要接收code的頁面。<?phpheader("Content-type:text/html;charset=utf-8");$code = $_GET["code"];echo $code;?>
例如你的服務(wù)器域名是http://www.abc.com,你的代碼放在服務(wù)器的wx目錄下,那么你的redirect_uri應(yīng)該是http://www.abc.com/wx/getcode.php
最后,你在微信內(nèi)點(diǎn)擊上面獲取code的鏈接,那么就會(huì)彈窗問你是否允許獲取用戶信息的了。https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
上面所需的參數(shù)基本都有,APPID、APPSECRET是你服務(wù)號(hào)的,CODE上面已經(jīng)獲取到了,那么直接請求接口,就能獲得access_token了。<?phpheader("Content-type:text/html;charset=utf-8");$code = $_GET["code"];$appid = "你公眾號(hào)的APPID";$appsecret = "你公眾號(hào)的APPSECRET";$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$appsecret."&code=".$code."&grant_type=authorization_code ";//發(fā)起請求$getopenid = file_get_contents($url);$getopenid_arr = json_decode($getopenid, true);$openid = $getopenid_arr["openid"];$access_token = $getopenid_arr["access_token"];?>
以上代碼直接就可以返回openid和access_token了,接下來直接通過另一個(gè)接口,就可以獲得用戶基本信息。https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN
代碼我就不上了,跟上面的請求方式是一樣的。關(guān)鍵詞:用戶,信息,基本,獲取,授權(quán),公眾
客戶&案例
營銷資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。