/// <summary> /// 获取AccessToken /// </summary> public void RefreshToken() { _tokenRefreshLock = true; var param = new Dictionary <string, string> { { "grant_type", "client_credential" }, { "appid", AppId }, { "secret", AppSecret } }; var reponseStr = _helper.SendGet("https://api.weixin.qq.com/cgi-bin/token", param); if (reponseStr == null) { _log.Error("获取AccessToken出错,请检查错误"); return; } var responseObj = new { access_token = "", expires_in = 0 }; var responseJson = JsonConvert.DeserializeAnonymousType(reponseStr, responseObj); if (responseJson != null) { _accessToken = responseJson.access_token; _tokenExpiresIn = responseJson.expires_in; _tokenUpdTime = DateTime.Now; } else { var responseErrorObj = new { errcode = "", errmsg = "" }; var errorJson = JsonConvert.DeserializeAnonymousType(reponseStr, responseErrorObj); _log.Error("获取AccessToken出错,错误代码{0},错误信息:{1}", errorJson.errcode, errorJson.errmsg); } _tokenRefreshLock = false; }
public MenuListModel GetMenuList() { var requestParam = new Dictionary <string, string> { { "access_token", _wcCommonService.AccessToken } }; var result = _wcHelper.SendGet("https://api.weixin.qq.com/cgi-bin/menu/get", requestParam); var model = JsonConvert.DeserializeObject <MenuListModel>(result); if (model.Menu == null) { var error = JsonConvert.DeserializeObject <MessageResultModel>(result); _log.Error("获取自定义菜单出错,错误代码{0},错误信息:{1}", error.Errcode, error.ErrMsg); return(null); } return(model); }