/// <summary> /// 获取素材列表 /// </summary> /// <param name="type">素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)</param> /// <param name="offset">从全部素材的该偏移位置开始返回,0表示从第一个素材 返回</param> /// <param name="count">返回素材的数量,取值在1到20之间</param> public BaseMsg batchGetMaterial(String ACCESS_TOKEN,String type, int offset, int count) { try { String url = string.Format("https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token={0}", ACCESS_TOKEN); RequestSimulator Request = new RequestSimulator(); String parm = "{\"type\":\"" + type + "\",\"offset\":\"" + offset + "\",\"count\":\"" + count + "\"}"; //IDictionary<String, String> parm = new Dictionary<String, String>(); //parm.Add("type", type); //parm.Add("offset", offset + ""); //parm.Add("count", count + ""); String jsonStr = Request.Post(url, parm); ErrorCode errorCode = MsgFilter.filter(jsonStr); if (errorCode.errcode != 0) { return errorCode; } newP3 newp3 = JsonHelper.parse<newP3>(jsonStr); return newp3; } catch (Exception ex) { throw ex; } }
public String CreateMenu(AccessToken AccessToken) { String url = " https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + AccessToken.access_token; String menuData = ReadMenuFile("menu.txt"); Console.WriteLine(menuData); RequestSimulator request = new RequestSimulator(); return request.Post(url,menuData); }
public BaseMsg create(string ACCESS_TOKEN, string parmName,string parmValue) { String postData = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"" + parmName + "\": \"" + parmValue + "\"}}}"; String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + ACCESS_TOKEN; RequestSimulator Request = new RequestSimulator(); String jsonStr = Request.Post(url,postData); ErrorCode errorCode = MsgFilter.filter(jsonStr); if (errorCode.errcode != 0) { return errorCode; } CreateQRResult obj = JsonHelper.parse<CreateQRResult>(jsonStr); return obj; }
/// <summary> /// 生成自定义菜单 /// </summary> /// <param name="ACCESS_TOKEN"></param> /// <param name="menuData"></param> /// <returns></returns> public BaseMsg CreateMenu(String ACCESS_TOKEN, String menuData) { try { String url = string.Format("https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}", ACCESS_TOKEN); RequestSimulator Request = new RequestSimulator(); String jsonStr = Request.Post(url, menuData); ErrorCode errorCode = MsgFilter.filter(jsonStr); return errorCode; } catch (Exception ex) { throw ex; } }
/// <summary> /// 公众号可以使用AppID和AppSecret调用本接口来获取access_token。AppID和AppSecret可在微信公众平台官网-开发者中心页中获得(需要已经成为开发者,且帐号没有异常状态)。注意调用所有微信接口时均需使用https协议。 /// </summary> /// <param name="grant_type">获取access_token填写client_credential</param> /// <param name="appid">第三方用户唯一凭证</param> /// <param name="secret">第三方用户唯一凭证密钥,即appsecret</param> /// <returns>正常情况下,微信会返回下述JSON数据包给公众号{"access_token":"ACCESS_TOKEN","expires_in":7200},错误时微信会返回错误码等信息,JSON数据包示例如下(该示例为AppID无效错误):{"errcode":40013,"errmsg":"invalid appid"}</returns> public BaseMsg getAccessToken(string grant_type, string appid, string secret) { try { String url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type={0}&appid={1}&secret={2}", grant_type, appid, secret); RequestSimulator Request = new RequestSimulator(); String jsonStr = Request.Get(url); ErrorCode errorCode = MsgFilter.filter(jsonStr); if (errorCode.errcode!=0) { return errorCode; } AccessToken accessToken = JsonHelper.parse<AccessToken>(jsonStr); return accessToken; } catch (Exception ex) { throw ex; } }
public BaseMsg getWxUserByOauth(string access_token, string openid) { try { String url = string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN", access_token, openid); RequestSimulator Request = new RequestSimulator(); String jsonStr = Request.Get(url); ErrorCode errorCode = MsgFilter.filter(jsonStr); if (errorCode.errcode != 0) { return errorCode; } WxUser obj = JsonHelper.parse<WxUser>(jsonStr); return obj; } catch (Exception ex) { throw ex; } }