OAuth2.0? ??
?? ??? ?? OAuth2.0? ?? ??? ?????:
?? ??? ?? ? ? ??. ?? ????? ? ?? "?????"? ?? ????? ??? AccessToken? ???? ??? ??? ??????. ?? ????? ??? ????.
A: ?????? ??? ?? ??? ????. ???? ????? ?? ???? ??? ?????.
appId? ?? ID ??
?? ? ??? URL(redirectUrl)
?? ????(?? ??)
?? ?? ??? ??(?? ??)
?? ??(?? ??)
B: ??? ??? ??? ???? ?? ?? ??(WeChat??? ?? ????? ???? ??)? ?????. ?? ??? ?. RedirectUrl? A? ???? ??? ???? ?? ? ?? ????? ???? RedirectUrl? ??????.
C: ?????? ????Url ?? ???? ??? ?? ???? ?? ??? ?????. ? ??? ?????
ID ??
????
grant string (code) grant type (??, ???? WeChat ??) D: ???? ID, ????, grant? ??? ??? ? ?? AccessToken (??, ??? AccessToken? ?? ?? ????? ? ?? ??????? ??? AccessToken? ??? ??? ??? ???? ??? ? ????.) E: ?????? AccessToken? ???? ??? API? ?????. , ? ?? ????? appId, Secret, grant ? ?? ??? ??? ???? ????. F: ??? ?? ??? ?????. WeChat?? OAuth2.0 ????OAuth2.0? ?? ??? ??? ?, WeChat?? OAuth2.0? ??? ????? ???????. ????? ??? ?????. ???? WeChat ?? ??? ??? ?? ???? ?? ??? ?? WeChat ?? ?????? ?? ????? ???. ? ????? ???? ????? ???? ?? ??? ???? ???. . ? ??? ??? ? ?? ? ?? ??? ????. ???? ????? ???? ?????? ?????(??? WeChat??? ? ????? ? ??? ?? ????? ? ?? ????). ??? ???? ??? ?? ?? ??? ?? ????.) ?? ?? ?? ???? ??????. OAuth2.0? ?????. ???? ? ???? ???? ?? ???? ????? ??? ?????. ??? ?? ?? ???? OAuth2.0 ?? ???? ?????. ? ???? ???? ?? ABCD ??? ??? ??? ?? EF? ?? ???? OpenId? ????. ??? ?? ??? ??(??? ??)? ???? ???(?? ??? ??) ??? ??? ?, ???? ??? ?? ??? ???? ???. OAuth2.0? ???? ??? ??? ?? ???? ???? WeChat OpenId? ???? ????? ??? ? ??? ? ? ????. ??? ??? "OAuth2.0 ?? ???"?? ? ?? ??? ??? ?? ?????. ?? A? Scope? snsapi_base? ?? ?? ?? ????? ???? ?????. ???? ?????? ?? ???? ????? ??? ?? ??? ???? OpenId? ?? ? ????. (???? ???? ?????? ??? ???? ?? ???? ???? ????? ?? ??? ?? ?????? ?????. ???? OpenId? ?? ?? ?? ?? ?????? ?????. ??? ????? ??? ??? ????. ?? A? ??? snsapi_userinfo? ?? ?? ???? ???? ???(??? ??). ?? ????? ??? ??? QQ ??? ???? ??????.) ???? ??? ??? ???? ?? ??? ?? ?? ? ????. ??? ???? ????? ???? ?? ?? ????? ?? ???? ?? ??? ???? ??? ?????. Senparc.Weixin.MP OAuth2.0 ????? ?? ?? ??: Senparc.Weixin.MP/AdvancedAPIs/OAuth ?? ???? ?? ???? ??? ????. :namespace Senparc.Weixin.MP.AdvancedAPIs { //官方文檔:http://mp.weixin.qq.com/wiki/index.php?title=%E7%BD%91%E9%A1%B5%E6%8E%88%E6%9D%83%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E5%9F%BA%E6%9C%AC%E4%BF%A1%E6%81%AF#.E7.AC.AC.E4.B8.80.E6.AD.A5.EF.BC.9A.E7.94.A8.E6.88.B7.E5.90.8C.E6.84.8F.E6.8E.88.E6.9D.83.EF.BC.8C.E8.8E.B7.E5.8F.96code /// <summary> /// 應(yīng)用授權(quán)作用域 /// </summary> public enum OAuthScope { /// <summary> /// 不彈出授權(quán)頁面,直接跳轉(zhuǎn),只能獲取用戶openid /// </summary> snsapi_base, /// <summary> /// 彈出授權(quán)頁面,可通過openid拿到昵稱、性別、所在地。并且,即使在未關(guān)注的情況下,只要用戶授權(quán),也能獲取其信息 /// </summary> snsapi_userinfo } public static class OAuth { /// <summary> /// 獲取驗證地址 /// </summary> /// <param name="appId"></param> /// <param name="redirectUrl"></param> /// <param name="state"></param> /// <param name="scope"></param> /// <param name="responseType"></param> /// <returns></returns> public static string GetAuthorizeUrl(string appId, string redirectUrl, string state, OAuthScope scope, string responseType = "code") { var url = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type={2}&scope={3}&state={4}#wechat_redirect", appId, redirectUrl.UrlEncode(), responseType, scope, state); /* 這一步發(fā)送之后,客戶會得到授權(quán)頁面,無論同意或拒絕,都會返回redirectUrl頁面。 * 如果用戶同意授權(quán),頁面將跳轉(zhuǎn)至 redirect_uri/?code=CODE&state=STATE。這里的code用于換取access_token(和通用接口的access_token不通用) * 若用戶禁止授權(quán),則重定向后不會帶上code參數(shù),僅會帶上state參數(shù)redirect_uri?state=STATE */ return url; } /// <summary> /// 獲取AccessToken /// </summary> /// <param name="appId"></param> /// <param name="secret"></param> /// <param name="code">code作為換取access_token的票據(jù),每次用戶授權(quán)帶上的code將不一樣,code只能使用一次,5分鐘未被使用自動過期。</param> /// <param name="grantType"></param> /// <returns></returns> public static OAuthAccessTokenResult GetAccessToken(string appId, string secret, string code, string grantType = "authorization_code") { var url = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type={3}", appId, secret, code, grantType); return CommonJsonSend.Send<OAuthAccessTokenResult>(null, url, null, CommonJsonSendType.GET); } /// <summary> /// 刷新access_token(如果需要) /// </summary> /// <param name="appId"></param> /// <param name="refreshToken">填寫通過access_token獲取到的refresh_token參數(shù)</param> /// <param name="grantType"></param> /// <returns></returns> public static OAuthAccessTokenResult RefreshToken(string appId, string refreshToken, string grantType = "refresh_token") { var url = string.Format("https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={0}&grant_type={1}&refresh_token={2}", appId, grantType, refreshToken); return CommonJsonSend.Send<OAuthAccessTokenResult>(null, url, null, CommonJsonSendType.GET); } public static OAuthUserInfo GetUserInfo(string accessToken,string openId) { var url = string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}",accessToken,openId); return CommonJsonSend.Send<OAuthUserInfo>(null, url, null, CommonJsonSendType.GET); } } }???? ?? ???? Senparc.Weixin.MP.Sample/Controllers/OAuth2Controller.cs? ?? ?? ?? ??? ?????. ??OAuth ?????? ????? ??? ??? ??? ??? ???. ??????? ???? AccessToken? ?? ?????(?? ????? ??)?? ???? AccessToken? ??? AppId? Secret? ?? ?????? ?? ??? ????.
?? ?? ?? ???? 100% ????? ????. ??? ? ?? ??? ??? ??? ??? ???? ??? ?????? ???? ? ?? ??? ??? ????? ??? ? ? ????. ?? ???? ?????.
???? ??? OAuth2.0? ???? ?? WeChat ???? [? ???]? ???? ?? ???? ??? ??? ???? ???.
? ?? WeChat ?? ??? ??: OAuth2.0 ??? ??? PHP ??? ?????? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)