"WeChat ?? ??? ??: ?? ????? ??"??? AccessToken(???? ?????)? ?? ??? ??????.
?? ?? ???? ?? ?? ?????? AccessToken? ???? ??? ?? ?????? ???? ?? ?? AccessToken? ?? ???? ???? ???. ?:
var accessToken = AccessTokenContainer.TryGetAccessToken(appId, appSecret);
?? appId ? appSecret? ????? ??? ? ??? ??? ?? ????:
var accessToken = AccessTokenContainer.GetAccessToken(_appId);
?? ?? ? accessToken? ???? ?? ?????? ???? ??? ? ????. ?? ?? ??? ?? ??? ?? ? ????. ??>
var result = CommonApi.GetMenu(accessToken);????? ?? ?? ?? ??? API ?? ???????. ??? ??? ??? ??? ?? ????. ?? ?? API ??? ? ?? ??? ????. ? ??? ???? ?? ??? ? ???? ??? ? ??? ? ?? ????? ????. API? ??? AccessToken? ???? ????? ???(?? ? ?? ??? ??? ???? ??). ???) WeChat ?? ??? ?? AccessToken? ????? ?? ??? ?? AccessToken? ???? ? ????.) ?? ??? API ??? ?? ??? ???? ???. ?? API ?? ??? ???? ??? ?? ??? ??? ?????. ?? ???? ? ? ?? ???? API? ?? ??? ? ??? ?? appId? ???? ???.
var result = CommonApi.GetMenu(appId);?? ???? ?? ??? ?? appId ? appSecret? ???? ???? ???.
AccessTokenContainer.Register(_appId, _appSecret);//全局只需注冊一次,例如可以放在Global的Application_Start()方法中。????? ?? accessToken? appId? ????(? ????? ??? accessToken ??? ???) accessToken? ?? ????? ?????. . ???? ??? ??? ???? ????. SDK ?? ?? ?? ???? ???? (??? ??) ??? AccessToken? ???? ???? ?? SDK?? Senparc.Weixin.MP/AccessTokenHandlerWapper.Do() ???? ??????. ?? ???????? AccessTokenHandlerWapper.cs? ??? ApiHandlerWapper.cs? ??? Do() ???? ?????? TryCommonApi() ???? ???????. ??? ??? ????.
namespace Senparc.Weixin.MP { /// <summary> /// 針對AccessToken無效或過期的自動處理類 /// </summary> public static class ApiHandlerWapper { /// <summary> /// 使用AccessToken進(jìn)行操作時,如果遇到AccessToken錯誤的情況,重新獲取AccessToken一次,并重試。 /// 使用此方法之前必須使用AccessTokenContainer.Register(_appId, _appSecret);或JsApiTicketContainer.Register(_appId, _appSecret);方法對賬號信息進(jìn)行過注冊,否則會出錯。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="fun"></param> /// <param name="accessTokenOrAppId">AccessToken或AppId。如果為null,則自動取已經(jīng)注冊的第一個appId/appSecret來信息獲取AccessToken。</param> /// <param name="retryIfFaild">請保留默認(rèn)值true,不用輸入。</param> /// <returns></returns> public static T TryCommonApi<T>(Func<string, T> fun, string accessTokenOrAppId = null, bool retryIfFaild = true) where T : WxJsonResult { string appId = null; string accessToken = null; if (accessTokenOrAppId == null) { appId = AccessTokenContainer.GetFirstOrDefaultAppId(); if (appId == null) { throw new WeixinException("尚無已經(jīng)注冊的AppId,請先使用AccessTokenContainer.Register完成注冊(全局執(zhí)行一次即可)!"); } } else if (ApiUtility.IsAppId(accessTokenOrAppId)) { if (!AccessTokenContainer.CheckRegistered(accessTokenOrAppId)) { throw new WeixinException("此appId尚未注冊,請先使用AccessTokenContainer.Register完成注冊(全局執(zhí)行一次即可)!"); } appId = accessTokenOrAppId; } else { //accessToken accessToken = accessTokenOrAppId; } T result = null; try { if (accessToken == null) { var accessTokenResult = AccessTokenContainer.GetAccessTokenResult(appId, false); accessToken = accessTokenResult.access_token; } result = fun(accessToken); } catch (ErrorJsonResultException ex) { if (!retryIfFaild && appId != null && ex.JsonResult.errcode == ReturnCode.獲取access_token時AppSecret錯誤或者access_token無效) { //嘗試重新驗(yàn)證 var accessTokenResult = AccessTokenContainer.GetAccessTokenResult(appId, true); accessToken = accessTokenResult.access_token; result = TryCommonApi(fun, appId, false); } } return result; } } }?? API? ?? ??? ?? ??? ????. :
/// <summary> /// 獲取當(dāng)前菜單,如果菜單不存在,將返回null /// </summary> /// <param name="accessToken"></param> /// <returns></returns> public static GetMenuResult GetMenu(string accessToken) { var url = string.Format("https://api.weixin.qq.com/cgi-bin/menu/get?access_token={0}", accessToken); var jsonString = HttpUtility.RequestUtility.HttpGet(url, Encoding.UTF8); //var finalResult = GetMenuFromJson(jsonString); GetMenuResult finalResult; JavaScriptSerializer js = new JavaScriptSerializer(); try { var jsonResult = js.Deserialize<GetMenuResultFull>(jsonString); if (jsonResult.menu == null || jsonResult.menu.button.Count == 0) { throw new WeixinException(jsonResult.errmsg); } finalResult = GetMenuFromJsonResult(jsonResult); } catch (WeixinException ex) { finalResult = null; } return finalResult; }?? TryCommonApi() ???? ??? ?:
/// <summary> /// 獲取當(dāng)前菜單,如果菜單不存在,將返回null /// </summary> /// <param name="accessTokenOrAppId">AccessToken或AppId。當(dāng)為AppId時,如果AccessToken錯誤將自動獲取一次。當(dāng)為null時,獲取當(dāng)前注冊的第一個AppId。</param> /// <returns></returns> public static GetMenuResult GetMenu(string accessTokenOrAppId) { return ApiHandlerWapper.TryCommonApi(accessToken => { var url = string.Format("https://api.weixin.qq.com/cgi-bin/menu/get?access_token={0}", accessToken); var jsonString = HttpUtility.RequestUtility.HttpGet(url, Encoding.UTF8); //var finalResult = GetMenuFromJson(jsonString); GetMenuResult finalResult; JavaScriptSerializer js = new JavaScriptSerializer(); try { var jsonResult = js.Deserialize<GetMenuResultFull>(jsonString); if (jsonResult.menu == null || jsonResult.menu.button.Count == 0) { throw new WeixinException(jsonResult.errmsg); } finalResult = GetMenuFromJsonResult(jsonResult); } catch (WeixinException ex) { finalResult = null; } return finalResult; }, accessTokenOrAppId); }??? ?? ?? ??? ??? ? ????. 1. ?? accessToken ?? ??? accessTokenOrAppId? ?????(?? ? ????? ?????? ?? ??? ?????. ?? ? ? ????? accessToken(?? ??? ???) ?? appId(accessToken? ?? ?? ??)? ???? ??? ? ????. SDK? ??? ??? ?? ?? ???? ??? ???? ???? ?????. 3?? ??? ????? ?????: a) appId. appId? ????? ??? ??? ?? appId ? appSecret? ?? ??? ?????. API ?? ?? ??? AccessToken? ??? ??? ???? SDK? ???? AccessToken? ?? ??? API ??? ?? ???? ??? ??? ???? ?????. ????. appId? ???? ?? ?? ??? ?????. b) accessToken. ? ?? ?? ?? ??? ?????. accessToken? ???? ??? ??? ?? ?? ??? ?????. c) null. accessTokenOrAppId ????? null?? SDK? ????? ??? ? ?? appId? ???? ?????. ?? WeChat ID? ???? ??????? ???? ?? ? ??? ??? ? ????. ????? ??? appId? ??? ??? ?????. 2. ?? ????? API? ????? ?? ??? ?? ????? ???? ?????. ?? return ApiHandlerWapper.TryCommonApi(accessToken =>{...},accessTokenOrAppId) ???? ???? ?? ????. ?? ??? ??? ? ?? ??? ??? ? SDK? ??? ??? ???? ??? ? ??? ?? ????. ? ??? Senparc.Weixin.MP v12.1?? ???????.
? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

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

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

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

Clothoff.io
AI ? ???

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

?? ??
?? ?? ?? ??? | Uma Musume Pretty Derby
1 ? ? ?
By Jack chen
<night> : ???? 99 ? - ?? ?? ? ?? ?? ??
1 ? ? ?
By DDD
?? ? ??? ????? Rimworld Odyssey ?? ???
3 ? ? ?
By Jack chen
Mejiro Ryan ?? ??? | Uma Musume Pretty Derby
4 ? ? ?
By Jack chen
Rimworld Odyssey ?? ??
3 ? ? ?
By Jack chen

??? ??

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

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

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

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

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