寰俊鏀寔鐨凙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

娴佺▼鍥撅細鎶€鏈浘鐗? class=

绗竴姝ワ細璇锋眰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‘鐨勮繑鍥烇細

  1.  
  2.  
    "access_token":"ACCESS_TOKEN",
  3.  
    "expires_in":7200,
  4.  
    "refresh_token":"REFRESH_TOKEN",
  5.  
    "openid":"OPENID",
  6.  
    "scope":"SCOPE"
  7.  
鍙傛暟璇存槑
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‘鐨勮繑鍥烇細

  1.  
  2.  
    "access_token":"ACCESS_TOKEN",
  3.  
    "expires_in":7200,
  4.  
    "refresh_token":"REFRESH_TOKEN",
  5.  
    "openid":"OPENID",
  6.  
    "scope":"SCOPE"
  7.  
鍙傛暟璇存槑
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鏁版嵁鍖呭涓嬶細

  1.  
  2.  
    "openid":" OPENID",
  3.  
    " nickname": NICKNAME,
  4.  
    "sex":"1",
  5.  
    "province":"PROVINCE"
  6.  
    "city":"CITY",
  7.  
    "country":"COUNTRY",
  8.  
    "headimgurl": "http://wx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/46",
  9.  
    "privilege":[ "PRIVILEGE1" "PRIVILEGE2" ],
  10.  
    "unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL"
  11.  
鍙傛暟鎻忚堪
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鍓嶉潰鐨勬柟妗?鏍峰紡淇敼

浜鸿劯瀹炴椂姣斿涓庤韩浠借瘉姣斿鍒ゆ柇鏄惁鏄竴涓汉鐨凙ndroid Demo

java涓璮or寰幆鍜寃hile寰幆锛屽摢涓洿蹇紵

寰幆璇彞

寰幆缁撴瀯