寰俊鏀寔鐨凙uthorization code鎺堟潈妯″紡锛堝叕浼楀彿寮€鍙戯級锛堝紑鏀惧钩鍙拌祫鏂欎腑蹇冧腑鐨勪唬鍏紬鍙峰彂璧风綉椤垫巿鏉冿級
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了寰俊鏀寔鐨凙uthorization code鎺堟潈妯″紡锛堝叕浼楀彿寮€鍙戯級锛堝紑鏀惧钩鍙拌祫鏂欎腑蹇冧腑鐨勪唬鍏紬鍙峰彂璧风綉椤垫巿鏉冿級相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e6%95%b0%e7%bb%84' title='鏁扮粍'>鏁扮粍 err blog stat 鍐呭 鑻辫 line
閾炬帴锛?a href="https://blog.csdn.net/ASZJBGD/article/details/82838356">https://blog.csdn.net/ASZJBGD/article/details/82838356
涓昏娴佺▼鍒嗕负涓ゆ锛?/p>
1.鑾峰彇code
2.閫氳繃code鎹㈠彇accesstoken
娴佺▼鍥撅細
绗竴姝ワ細璇锋眰CODE
璇锋眰鏂规硶
鍦ㄧ‘淇濆井淇″叕浼楄处鍙锋嫢鏈夋巿鏉冧綔鐢ㄥ煙锛坰cope鍙傛暟锛夌殑鏉冮檺鐨勫墠鎻愪笅锛堜竴鑸€岃█锛屽凡寰俊璁よ瘉鐨勬湇鍔″彿鎷ユ湁snsapi_base鍜宻nsapi_userinfo锛夛紝浣跨敤寰俊瀹㈡埛绔墦寮€浠ヤ笅閾炬帴锛堜弗鏍兼寜鐓т互涓嬫牸寮忥紝鍖呮嫭椤哄簭鍜屽ぇ灏忓啓锛屽苟璇峰皢鍙傛暟鏇挎崲涓哄疄闄呭唴瀹癸級锛?/p>
https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE&component_appid=component_appid#wechat_redirect
鑻ユ彁绀?ldquo;璇ラ摼鎺ユ棤娉曡闂?rdquo;锛岃妫€鏌ュ弬鏁版槸鍚﹀~鍐欓敊璇紝鏄惁鎷ユ湁scope鍙傛暟瀵瑰簲鐨勬巿鏉冧綔鐢ㄥ煙鏉冮檺銆?/p>
鍙傛暟璇存槑
鍙傛暟 | 鏄惁蹇呴』 | 璇存槑 |
---|---|---|
appid | 鏄?/td> | 鍏紬鍙风殑appid |
redirect_uri | 鏄?/td> | 閲嶅畾鍚戝湴鍧€锛岄渶瑕乽rlencode锛岃繖閲屽~鍐欑殑搴旀槸鏈嶅姟寮€鍙戞柟鐨勫洖璋冨湴鍧€ |
response_type | 鏄?/td> | 濉玞ode |
scope | 鏄?/td> | 鎺堟潈浣滅敤鍩燂紝鎷ユ湁澶氫釜浣滅敤鍩熺敤閫楀彿锛?锛夊垎闅?/td> |
state | 鍚?/td> | 閲嶅畾鍚戝悗浼氬甫涓妔tate鍙傛暟锛屽紑鍙戣€呭彲浠ュ~鍐欎换鎰忓弬鏁板€硷紝鏈€澶?28瀛楄妭 |
component_appid | 鏄?/td> | 鏈嶅姟鏂圭殑appid锛屽湪鐢宠鍒涘缓鍏紬鍙锋湇鍔℃垚鍔熷悗锛屽彲鍦ㄥ叕浼楀彿鏈嶅姟璇︽儏椤垫壘鍒?/td> |
杩斿洖璇存槑
鐢ㄦ埛鍏佽鎺堟潈鍚庯紝灏嗕細閲嶅畾鍚戝埌redirect_uri鐨勭綉鍧€涓婏紝骞朵笖甯︿笂code, state浠ュ強appid
redirect_uri?code=CODE&state=STATE&appid=APPID
鑻ョ敤鎴风姝㈡巿鏉冿紝鍒欓噸瀹氬悜鍚庝笉浼氬甫涓奵ode鍙傛暟锛屼粎浼氬甫涓妔tate鍙傛暟
redirect_uri?state=STATE
绗簩姝ワ細閫氳繃code鎹㈠彇access_token
璇锋眰鏂规硶
鑾峰彇绗竴姝ョ殑code鍚庯紝璇锋眰浠ヤ笅閾炬帴鑾峰彇access_token锛?/p>
https://api.weixin.qq.com/sns/oauth2/component/access_token?appid=APPID&code=CODE&grant_type=authorization_code&component_appid=COMPONENT_APPID&component_access_token=COMPONENT_ACCESS_TOKEN
闇€瑕佹敞鎰忕殑鏄紝鐢变簬瀹夊叏鏂归潰鐨勮€冭檻锛屽璁块棶璇ラ摼鎺ョ殑瀹㈡埛绔湁IP鐧藉悕鍗曠殑瑕佹眰銆?/p>
鍙傛暟璇存槑
鍙傛暟 | 鏄惁蹇呴』 | 璇存槑 |
---|---|---|
appid | 鏄?/td> | 鍏紬鍙风殑appid |
code | 鏄?/td> | 濉啓绗竴姝ヨ幏鍙栫殑code鍙傛暟 |
grant_type | 鏄?/td> | 濉玜uthorization_code |
component_appid | 鏄?/td> | 鏈嶅姟寮€鍙戞柟鐨刟ppid |
component_access_token | 鏄?/td> | 鏈嶅姟寮€鍙戞柟鐨刟ccess_token |
杩斿洖璇存槑
姝g‘鐨勮繑鍥烇細
-
-
"access_token":"ACCESS_TOKEN",
-
"expires_in":7200,
-
"refresh_token":"REFRESH_TOKEN",
-
"openid":"OPENID",
-
"scope":"SCOPE"
-
鍙傛暟 | 璇存槑 |
---|---|
access_token | 鎺ュ彛璋冪敤鍑瘉 |
expires_in | access_token鎺ュ彛璋冪敤鍑瘉瓒呮椂鏃堕棿锛屽崟浣嶏紙绉掞級 |
refresh_token | 鐢ㄦ埛鍒锋柊access_token |
openid | 鎺堟潈鐢ㄦ埛鍞竴鏍囪瘑 |
scope | 鐢ㄦ埛鎺堟潈鐨勪綔鐢ㄥ煙锛屼娇鐢ㄩ€楀彿锛?锛夊垎闅?/td> |
閿欒杩斿洖鏍蜂緥锛?/p>
"errcode":40029,"errmsg":"invalid code"
绗笁姝ワ細鍒锋柊access_token锛堝鏋滈渶瑕侊級
鐢变簬access_token鎷ユ湁杈冪煭鐨勬湁鏁堟湡锛屽綋access_token瓒呮椂鍚庯紝鍙互浣跨敤refresh_token杩涜鍒锋柊锛宺efresh_token鎷ユ湁杈冮暱鐨勬湁鏁堟湡锛?0澶╋級锛屽綋refresh_token澶辨晥鐨勫悗锛岄渶瑕佺敤鎴烽噸鏂版巿鏉冦€?/p>
璇锋眰鏂规硶
鑾峰彇绗竴姝ョ殑code鍚庯紝璇锋眰浠ヤ笅閾炬帴鑾峰彇access_token锛?/p>
https://api.weixin.qq.com/sns/oauth2/component/refresh_token?appid=APPID&grant_type=refresh_token&component_appid=COMPONENT_APPID&component_access_token=COMPONENT_ACCESS_TOKEN&refresh_token=REFRESH_TOKEN
鍙傛暟璇存槑
鍙傛暟 | 鏄惁蹇呴』 | 璇存槑 |
---|---|---|
appid | 鏄?/td> | 鍏紬鍙风殑appid |
grant_type | 鏄?/td> | 濉玶efresh_token |
refresh_token | 鏄?/td> | 濉啓閫氳繃access_token鑾峰彇鍒扮殑refresh_token鍙傛暟 |
component_appid | 鏄?/td> | 鏈嶅姟寮€鍙戝晢鐨刟ppid |
component_access_token | 鏄?/td> | 鏈嶅姟寮€鍙戞柟鐨刟ccess_token |
杩斿洖璇存槑
姝g‘鐨勮繑鍥烇細
-
-
"access_token":"ACCESS_TOKEN",
-
"expires_in":7200,
-
"refresh_token":"REFRESH_TOKEN",
-
"openid":"OPENID",
-
"scope":"SCOPE"
-
鍙傛暟 | 璇存槑 |
---|---|
access_token | 鎺ュ彛璋冪敤鍑瘉 |
expires_in | access_token鎺ュ彛璋冪敤鍑瘉瓒呮椂鏃堕棿锛屽崟浣嶏紙绉掞級 |
refresh_token | 鐢ㄦ埛鍒锋柊access_token |
openid | 鎺堟潈鐢ㄦ埛鍞竴鏍囪瘑 |
scope | 鐢ㄦ埛鎺堟潈鐨勪綔鐢ㄥ煙锛屼娇鐢ㄩ€楀彿锛?锛夊垎闅?/td> |
閿欒杩斿洖鏍蜂緥锛?
"errcode":40029,"errmsg":"invalid code"
绗洓姝ワ細閫氳繃缃戦〉鎺堟潈access_token鑾峰彇鐢ㄦ埛鍩烘湰淇℃伅锛堥渶鎺堟潈浣滅敤鍩熶负snsapi_userinfo锛?/p>
濡傛灉缃戦〉鎺堟潈浣滅敤鍩熶负snsapi_userinfo锛屽垯姝ゆ椂寮€鍙戣€呭彲浠ラ€氳繃access_token鍜宱penid鎷夊彇鐢ㄦ埛淇℃伅浜嗐€?/p>
璇锋眰鏂规硶
http锛欸ET锛堣浣跨敤https鍗忚锛?https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN
鍙傛暟璇存槑
鍙傛暟 | 鎻忚堪 |
---|---|
access_token | 缃戦〉鎺堟潈鎺ュ彛璋冪敤鍑瘉,娉ㄦ剰锛氭access_token涓庡熀纭€鏀寔鐨刟ccess_token涓嶅悓 |
openid | 鐢ㄦ埛鐨勫敮涓€鏍囪瘑 |
lang | 杩斿洖鍥藉鍦板尯璇█鐗堟湰锛寊h_CN 绠€浣擄紝zh_TW 绻佷綋锛宔n 鑻辫 |
杩斿洖璇存槑
姝g‘鏃惰繑鍥炵殑JSON鏁版嵁鍖呭涓嬶細
-
-
"openid":" OPENID",
-
" nickname": NICKNAME,
-
"sex":"1",
-
"province":"PROVINCE"
-
"city":"CITY",
-
"country":"COUNTRY",
-
"headimgurl": "http://wx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/46",
-
"privilege":[ "PRIVILEGE1" "PRIVILEGE2" ],
-
"unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL"
-
鍙傛暟 | 鎻忚堪 |
---|---|
openid | 鐢ㄦ埛鐨勫敮涓€鏍囪瘑 |
nickname | 鐢ㄦ埛鏄电О |
sex | 鐢ㄦ埛鐨勬€у埆锛屽€间负1鏃舵槸鐢锋€э紝鍊间负2鏃舵槸濂虫€э紝鍊间负0鏃舵槸鏈煡 |
province | 鐢ㄦ埛涓汉璧勬枡濉啓鐨勭渷浠?/td> |
city | 鏅€氱敤鎴蜂釜浜鸿祫鏂欏~鍐欑殑鍩庡競 |
country | 鍥藉锛屽涓浗涓篊N |
headimgurl | 鐢ㄦ埛澶村儚锛屾渶鍚庝竴涓暟鍊间唬琛ㄦ鏂瑰舰澶村儚澶у皬锛堟湁0銆?6銆?4銆?6銆?32鏁板€煎彲閫夛紝0浠h〃640*640姝f柟褰㈠ご鍍忥級锛岀敤鎴锋病鏈夊ご鍍忔椂璇ラ」涓虹┖銆傝嫢鐢ㄦ埛鏇存崲澶村儚锛屽師鏈夊ご鍍廢RL灏嗗け鏁堛€?/td> |
privilege | 鐢ㄦ埛鐗规潈淇℃伅锛宩son 鏁扮粍锛屽寰俊娌冨崱鐢ㄦ埛涓猴紙chinaunicom锛?/td> |
unionid | 鍙湁鍦ㄧ敤鎴峰皢鍏紬鍙风粦瀹氬埌寰俊寮€鏀惧钩鍙板笎鍙峰悗锛屾墠浼氬嚭鐜拌瀛楁銆傝瑙侊細 鑾峰彇鐢ㄦ埛涓汉淇℃伅锛圲nionID鏈哄埗锛?/td> |
閿欒鏃跺井淇′細杩斿洖JSON鏁版嵁鍖呭涓嬶紙绀轰緥涓簅penid鏃犳晥锛?
"errcode":40003,"errmsg":" invalid openid "
以上是关于寰俊鏀寔鐨凙uthorization code鎺堟潈妯″紡锛堝叕浼楀彿寮€鍙戯級锛堝紑鏀惧钩鍙拌祫鏂欎腑蹇冧腑鐨勪唬鍏紬鍙峰彂璧风綉椤垫巿鏉冿級的主要内容,如果未能解决你的问题,请参考以下文章
娣卞害瀛︿範鎴樹簤锛欶acebook 鏀寔鐨?PyTorch 涓?Google 鐨?TensorFlow | Linux 涓浗
寰俊灏忕▼搴忓幓鎺塩heckbox鍓嶉潰鐨勬柟妗?鏍峰紡淇敼