/// <summary> /// 获取微信服务器Ip地址列表 /// </summary> /// <param name="appId">公众号appID</param> /// <param name="appSecret">公众号appSecret</param> /// <returns>Ip地址列表(JArray)</returns> public static JArray GetIP(string appId, string appSecret) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token={0}", AccessToken.GetToken(appId, appSecret));//获取微信服务器Ip地址的url。 string result = WechatWebClient.Get(url); return(JsonConvert.DeserializeObject <dynamic>(result)["ip_list"]); }
/// <summary> /// 获取jsapiTicket /// </summary> /// <param name="appId">公众号appID</param> /// <param name="appSecret">公众号appSecret</param> /// <returns>jsapiTicket(string)</returns> public static string GetTicket(string appId, string appSecret) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=jsapi", AccessToken.GetToken(appId, appSecret)); var model = Helper.JsApiTicketHelper.Get("jsapi"); if (model == null || string.IsNullOrEmpty(model.Ticket) || Common.IsExprie(model.DateTime)) { string result = WechatWebClient.Get(url); model.Ticket = JsonConvert.DeserializeObject <dynamic>(result)["ticket"]; model.DateTime = DateTime.Now; Helper.JsApiTicketHelper.Set("jsapi", model); } return(model.Ticket); }
/// <summary> /// 获取Token /// </summary> /// <param name="appId">公众号appID</param> /// <param name="appSecret">公众号appSecret</param> /// <returns>token(string)</returns> public static string GetToken(string appId, string appSecret) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", appId, appSecret); var tokenModel = Helper.AccessTokenHelper.Get(appId); //如果token不存在或已过期则重新生成Token if (tokenModel == null || string.IsNullOrEmpty(tokenModel.Token) || Common.IsExprie(tokenModel.DateTime)) { string result = WechatWebClient.Get(url); tokenModel.Token = JsonConvert.DeserializeObject <dynamic>(result)["access_token"]; tokenModel.DateTime = DateTime.Now; Helper.AccessTokenHelper.Set(appId, tokenModel); } return(tokenModel.Token); }
public static string GetTemporaryMedia(string appId, string appSecret, string media_id) { var url = string.Format("http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={0}&media_id={1}", AccessToken.GetToken(appId, appSecret), media_id); return(WechatWebClient.Get(url)); }
/// <summary> /// 查询摇一摇周边申请的审核状态 /// </summary> /// <param name="appId">公众号appID</param> /// <param name="appSecret">公众号appSecret</param> /// <returns></returns> public static string GetAuditStatus(string appId, string appSecret) { string url = string.Format("https://api.weixin.qq.com/shakearound/account/auditstatus?access_token={0}", AccessToken.GetToken(appId, appSecret)); return(WechatWebClient.Get(url)); }
/// <summary> /// 拉取scope为 snsapi_userinfo时的用户信息 /// </summary> /// <param name="openId">上面方法中获得openId</param> /// <param name="token">上面方法中获得token</param> /// <param name="language">返回此用户国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语</param> /// <returns>ResultModels.OAuth2UserInfoResult</returns> public static ResultModels.OAuth2UserInfoResult GetUserInfo(string openId, string token, string language) { string url = string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang={2}", token, openId, language); return(WechatWebClient.Get <ResultModels.OAuth2UserInfoResult>(url)); }
/// <summary> /// 刷新access_token /// 注释:如果需要则判断授权凭证是否有效,有效则不需刷新,无效就刷新 /// </summary> /// <param name="appId">公众号appID</param> /// <param name="refreshToken">通过GetToken方法获得的refresh_token</param> /// <returns>ResultModels.Oauth2TokenResult</returns> public static ResultModels.Oauth2TokenResult RefreshToken(string appId, string refreshToken) { string url = string.Format("https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={0}&grant_type=refresh_token&refresh_token={1}", appId, refreshToken); return(WechatWebClient.Get <ResultModels.Oauth2TokenResult>(url)); }
/// <summary> /// 检验授权凭证(access_token)是否有效 /// </summary> /// <param name="openId">上面方法中获得openId</param> /// <param name="token">获得的网页授权token</param> /// <returns>ResultModels.WechatResult</returns> public static ResultModels.WechatResult GetOAuthTokenIsValid(string openId, string token) { string url = string.Format("https://api.weixin.qq.com/sns/auth?access_token={0}&openid={1}", token, openId); return(WechatWebClient.Get <ResultModels.WechatResult>(url)); }
/// <summary> /// 通过code换取网页授权access_token /// 注释:此处的token和AccessTokenAPI处的token不一样。 /// 【则本步骤中获取到网页授权access_token的同时,也获取到了openid,snsapi_base式的网页授权流程即到此为止】。 /// </summary> /// <param name="appId">公众号appID</param> /// <param name="appSecret">公众号appSecret</param> /// <param name="code">通过GetCode方法获得的code</param> /// <returns>ResultModels.Oauth2TokenResult</returns> public static ResultModels.Oauth2TokenResult GetToken(string appId, string appSecret, string code) { string url = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", appId, appSecret, code); return(WechatWebClient.Get <ResultModels.Oauth2TokenResult>(url)); }
/// <summary> /// 删除所有的菜单 /// </summary> /// <param name="appId">公众号appID</param> /// <param name="appSecret">公众号appSecret</param> /// <returns>ResultModels.WechatResult</returns> public static ResultModels.WechatResult DeleteAllMenu(string appId, string appSecret) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/menu/delete?access_token={0}", AccessToken.GetToken(appId, appSecret)); return(WechatWebClient.Get <ResultModels.WechatResult>(url)); }
/// <summary> /// 查询所有菜单 /// </summary> /// <param name="appId">公众号appID</param> /// <param name="appSecret">公众号appSecret</param> /// <returns>string</returns> public static string GetMenu(string appId, string appSecret) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/menu/get?access_token={0}", AccessToken.GetToken(appId, appSecret)); return(WechatWebClient.Get(url)); }