/// <summary> /// 自定义菜单创建接口 /// </summary> /// <param name="jsonData"></param> /// <param name="accessToken"></param> /// <returns></returns> public static WxJsonResult CreateMenu(List <Menu> menu, string accessToken) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}", accessToken); dynamic jsonData = new { button = menu.Select(a => new { type = a.type, name = a.name, key = a.key, url = a.url, media_id = a.media_id, sub_button = a.sub_button.Select(b => new { type = b.type, name = b.name, key = b.key, url = b.url, media_id = b.media_id }).ToList() }).ToList() }; dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); WxJsonResult wxResult = EntityHelper.GetJsonResultToEntity <WxJsonResult>(result); return(wxResult); }
/// <summary> /// 发送图文消息(点击跳转到外链) 图文消息条数限制在8条以内,注意,如果图文数超过8,则将会无响应。 /// </summary> /// <param name="accessToken"></param> /// <param name="openId"></param> /// <param name="articles"></param> /// <returns></returns> public static WxJsonResult CustomSendNewsMsg(string accessToken, string openId, List <Article> articles) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}", accessToken); dynamic jsonData = new { touser = openId, msgtype = "news", news = new { articles = articles.Select(a => new { title = a.Title, description = a.Description, url = a.Url, picurl = a.PicUrl }).ToList() } }; dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); WxJsonResult wxResult = EntityHelper.GetJsonResultToEntity <WxJsonResult>(result); return(wxResult); }
/// <summary> /// 获取用户列表 /// 一次拉取调用最多拉取10000个关注者的OpenID /// </summary> /// <param name="accessToken"></param> /// <param name="next_openid">第一个拉取的OPENID,不填默认从头开始拉取</param> /// <returns></returns> public static GetUserResult GetUserList(string accessToken, string next_openid) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/get?access_token={0}&next_openid={1}", accessToken, next_openid); string result = HttpService.Get(url); GetUserResult wxResult = EntityHelper.GetJsonResultToEntity <GetUserResult>(result); return(wxResult); }
/// <summary> /// 获取设置的行业信息 /// </summary> /// <param name="accessToken"></param> /// <param name="industry_id1"></param> /// <param name="industry_id2"></param> /// <returns></returns> public static GetIndustry TemplateGetIndustry(string accessToken, int industry_id1, int industry_id2) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/template/get_industry?access_token={0}", accessToken); dynamic result = HttpService.Get(url); GetIndustry wxResult = EntityHelper.GetJsonResultToEntity <GetIndustry>(result); return(wxResult); }
/// <summary> /// 发送模板消息-jsonData-to be continued /// </summary> /// <param name="accessToken"></param> /// <param name="openid"></param> /// <param name="template_id"></param> /// <param name="jsonData"></param> /// <returns></returns> public static MsgId SendTemplateMessage(string accessToken, string openid, string template_id, dynamic jsonData) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}", accessToken); dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); MsgId wxResult = EntityHelper.GetJsonResultToEntity <MsgId>(result); return(wxResult); }
/// <summary> /// 删除当前使用的自定义菜单。另请注意,在个性化菜单时,调用此接口会删除默认菜单及全部个性化菜单。 /// </summary> /// <param name="accessToken"></param> /// <returns></returns> public static WxJsonResult DeleteMenu(string accessToken) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/menu/delete?access_token={0}", accessToken); string result = HttpService.Get(url); WxJsonResult wxResult = EntityHelper.GetJsonResultToEntity <WxJsonResult>(result); return(wxResult); }
/// <summary> /// 获取公众号已创建的标签 /// </summary> /// <param name="accessToken"></param> /// <returns></returns> public static TagsResult GetUserTag(string accessToken) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/tags/get?access_token={0}", accessToken); dynamic result = HttpService.Get(url); TagsResult wxResult = EntityHelper.GetJsonResultToEntity <TagsResult>(result); return(wxResult); }
/// <summary> /// 获取用户基本信息 /// </summary> /// <param name="accessToken"></param> /// <param name="openid"></param> /// <param name="lang"></param> /// <returns></returns> public static UserInfoResult GetUserInfo(string accessToken, string openid, string lang = "zh_CN") { string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang={2}", accessToken, openid, lang); string result = HttpService.Get(url); UserInfoResult wxResult = EntityHelper.GetJsonResultToEntity <UserInfoResult>(result); return(wxResult); }
/// <summary> /// 获取微信服务器IP地址 /// </summary> /// <param name="accessToken">access_token</param> /// <returns></returns> public static IpList GetCallbackIP(string accessToken) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token={0}", accessToken); string result = HttpService.Get(url); IpList wxResult = EntityHelper.GetJsonResultToEntity <IpList>(result); return(wxResult); }
/// <summary> /// 新增永久素材 /// </summary> /// <param name="accessToken"></param> /// <param name="fileName">文件路径</param> /// <param name="type"></param> /// <returns></returns> public static MediaResult UploadPermanentMedia(string accessToken, string fileName, MediaType type) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/material/add_material?access_token={0}&type={1}", accessToken, type); dynamic result = HttpService.WeChatPostForm(url, fileName); MediaResult wxResult = EntityHelper.GetJsonResultToEntity <MediaResult>(result); return(wxResult); }
/// <summary> /// 获取在线客服接待信息 /// 结合客服基本信息,可以开发例如“指定客服接待”等功能;结合会话记录,可以开发”在线客服实时服务质量监控“等功能。 /// </summary> /// <param name="accessToken"></param> public static KFListOnlineResult GetOnlineCustomAccountList(string accessToken) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist?access_token={0}", accessToken); string result = HttpService.Get(url); KFListOnlineResult wxResult = EntityHelper.GetJsonResultToEntity <KFListOnlineResult>(result); return(wxResult); }
/// <summary> /// 上传图文消息内的图片获取URL【订阅号与服务号认证后均可用】 /// </summary> /// <param name="accessToken"></param> /// <param name="image"></param> /// <returns></returns> public static Url UploadImgGetUrl(string accessToken, string fileName) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token={0}", accessToken); dynamic result = HttpService.WeChatPostForm(url, fileName); Url wxResult = EntityHelper.GetJsonResultToEntity <Url>(result); return(wxResult); }
/// <summary> /// 获取素材总数 /// </summary> /// <param name="accessToken"></param> /// <returns></returns> public static MediaCountResult GetMediaCount(string accessToken) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token={0}", accessToken); string result = HttpService.Get(url); MediaCountResult wxResult = EntityHelper.GetJsonResultToEntity <MediaCountResult>(result); return(wxResult); }
/// <summary> /// 设置客服帐号的头像 /// </summary> /// <param name="accessToken"></param> /// <param name="kf_account">完整客服账号,格式为:账号前缀@公众号微信号</param> /// <param name="fileName">文件完整路径</param> /// <returns></returns> public static WxJsonResult SetCustomAccountHeadImg(string accessToken, string kf_account, string fileName) { string url = string.Format("http://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token={0}&kf_account={1}", accessToken, kf_account); dynamic result = HttpService.WeChatPostForm(url, fileName);//post/form提交图片 WxJsonResult wxResult = EntityHelper.GetJsonResultToEntity <WxJsonResult>(result); return(wxResult); }
/// <summary> /// 获取模板列表 /// </summary> /// <param name="accessToken"></param> /// <returns></returns> public static TemplateList GetTemplateList(string accessToken) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token={0}", accessToken); dynamic result = HttpService.Get(url); TemplateList wxResult = EntityHelper.GetJsonResultToEntity <TemplateList>(result); return(wxResult); }
/// <summary> /// 生成带参数的二维码 /// </summary> /// <param name="accessToken"></param> /// <param name="expire_seconds">该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。</param> /// <param name="qrCodeType">二维码类型,QR_SCENE为临时,QR_LIMIT_SCENE为永久,QR_LIMIT_STR_SCENE为永久的字符串参数值</param> /// <param name="scene_id">场景值ID,临时二维码时为32位非0整型,永久二维码时最大值为100000(目前参数只支持1--100000)</param> /// <param name="scene_str">场景值ID(字符串形式的ID),字符串类型,长度限制为1到64,仅永久二维码支持此字段 </param> public static CreateQRCodeResult CreateQRCode(string accessToken, QRCodeType qrCodeType, string expire_seconds = null, string scene_id = null, string scene_str = null) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}", accessToken); dynamic jsonData = null; if (qrCodeType == QRCodeType.QR_SCENE) { jsonData = new { expire_seconds = expire_seconds, action_name = "QR_SCENE", action_info = new { scene = new { scene_id = scene_id } } }; } else if (qrCodeType == QRCodeType.QR_LIMIT_SCENE) { jsonData = new { action_name = "QR_LIMIT_SCENE", action_info = new { scene = new { scene_id = scene_id } } }; } else if (qrCodeType == QRCodeType.QR_LIMIT_STR_SCENE) { jsonData = new { action_name = "QR_LIMIT_STR_SCENE", action_info = new { scene = new { scene_str = scene_str } } }; } else { Log.Debug("CreateQRCode", "无该类型的QRCodeType"); } dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); CreateQRCodeResult wxResult = EntityHelper.GetJsonResultToEntity <CreateQRCodeResult>(result); return(wxResult); }
/// <summary> /// 获取accessToken /// </summary> /// <param name="AppId">应用ID</param> /// <param name="Secret">应用密钥</param> /// <returns></returns> public static AccessToken GetAccessToken(string AppId = "wxc4e7d610398a338b", string Secret = "3ac9745d1943cc10c1f5cf767a8dd90c") { //var AppId = "wxc4e7d610398a338b";//换成你 的信息 //var Secret = "3ac9745d1943cc10c1f5cf767a8dd90c";//换成你的信息 string url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", AppId, Secret); string result = HttpService.Get(url); AccessToken wxResult = EntityHelper.GetJsonResultToEntity <AccessToken>(result); return(wxResult); }
/// <summary> /// 查询设备ID申请审核状态 /// </summary> /// <param name="apply_id">批次ID,申请设备ID时所返回的批次ID</param> /// <param name="accessToken"></param> /// <returns></returns> public static ShakeAroundApplyStatusResult ApplyStatus(int apply_id, string accessToken) { string url = string.Format("https://api.weixin.qq.com/shakearound/device/applystatus?access_token={0}", accessToken); dynamic jsonData = new { apply_id = apply_id, }; string result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); ShakeAroundApplyStatusResult wxResult = EntityHelper.GetJsonResultToEntity <ShakeAroundApplyStatusResult>(result); return(wxResult); }
/// <summary> /// 删除页面 /// 只有页面与设备没有关联关系时,才可被删除。 /// </summary> /// <param name="page_id"></param> /// <param name="accessToken"></param> /// <returns></returns> public static ShakeAroundAddPageResult DeletePage(int page_id, string accessToken) { string url = string.Format("https://api.weixin.qq.com/shakearound/page/delete?access_token={0}", accessToken); dynamic jsonData = new { page_id = page_id }; string result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); ShakeAroundAddPageResult wxResult = EntityHelper.GetJsonResultToEntity <ShakeAroundAddPageResult>(result); return(wxResult); }
/// <summary> /// 删除个性化菜单 /// </summary> /// <param name="accessToken"></param> /// <param name="menuid">menuid为菜单id,可以通过自定义菜单查询接口获取。</param> /// <returns></returns> public static WxJsonResult DeleteConditionalMenu(string accessToken, string menuId) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token={0}", accessToken); dynamic jsonData = new { menuid = menuId }; dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); WxJsonResult wxResult = EntityHelper.GetJsonResultToEntity <WxJsonResult>(result); return(wxResult); }
/// <summary> /// 删除模板 /// </summary> /// <param name="accessToken"></param> /// <param name="template_id"> 公众帐号下模板消息ID</param> /// <returns></returns> public static WxJsonResult DeleteTemplate(string accessToken, string template_id) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token={0}", accessToken); dynamic jsonData = new { template_id = template_id }; dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); WxJsonResult wxResult = EntityHelper.GetJsonResultToEntity <WxJsonResult>(result); return(wxResult); }
/// <summary> /// 获得模板ID /// </summary> /// <param name="accessToken"></param> /// <param name="template_id_short"></param> /// <returns></returns> public static TemplateId TemplateGetIndustry(string accessToken, string template_id_short) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/template/get_industry?access_token={0}", accessToken); dynamic jsonData = new { template_id_short = template_id_short }; dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); TemplateId wxResult = EntityHelper.GetJsonResultToEntity <TemplateId>(result); return(wxResult); }
/// <summary> /// 删除永久素材 /// 1、请谨慎操作本接口,因为它可以删除公众号在公众平台官网素材管理模块中新建的图文消息、语音、视频等素材(但需要先通过获取素材列表来获知素材的media_id) /// 2、临时素材无法通过本接口删除 /// 3、调用该接口需https协议 /// </summary> /// <param name="accessToken"></param> /// <param name="media_id"></param> /// <returns></returns> public static WxJsonResult DeletePermanentMedia(string accessToken, string media_id) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/material/del_material?access_token={0}", accessToken); dynamic jsonData = new { media_id = media_id }; dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); WxJsonResult wxResult = EntityHelper.GetJsonResultToEntity <WxJsonResult>(result); return(result); }
/// <summary> /// 获取用户身上的标签列表 /// </summary> /// <param name="accessToken"></param> /// <param name="openid"></param> /// <returns></returns> public static TagListResult GetTagList(string accessToken, string openid) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/tags/getidlist?access_token={0}", accessToken); dynamic jsonData = new { openid = openid }; dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); TagListResult wxResult = EntityHelper.GetJsonResultToEntity <TagListResult>(result); return(wxResult); }
/// <summary> /// 查询群发消息发送状态【订阅号与服务号认证后均可用】 /// </summary> /// <param name="accessToken"></param> /// <param name="msg_id"></param> /// <returns></returns> public static SendStatus GetSendStatus(string accessToken, string msg_id) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/message/mass/get?access_token={0}", accessToken); dynamic jsonData = new { msg_id = msg_id }; dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); SendStatus wxResult = EntityHelper.GetJsonResultToEntity <SendStatus>(result); return(wxResult); }
/// <summary> /// 设置所属行业 /// </summary> /// <param name="accessToken"></param> /// <param name="industry_id1"> 公众号模板消息所属行业编号</param> /// <param name="industry_id2"> 公众号模板消息所属行业编号</param> /// <returns></returns> public static WxJsonResult TemplateSetIndustry(string accessToken, int industry_id1, int industry_id2) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token={0}", accessToken); dynamic jsonData = new { industry_id1 = industry_id1, industry_id2 = industry_id2 }; dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); WxJsonResult wxResult = EntityHelper.GetJsonResultToEntity <WxJsonResult>(result); return(wxResult); }
/// <summary> /// 增改删客服账号 /// </summary> /// <param name="url"></param> /// <param name="kf_account">完整客服账号,格式为:账号前缀@公众号微信号</param> /// <param name="nickname">客服昵称,最长6个汉字或12个英文字符</param> /// <param name="password">客服账号登录密码,格式为密码明文的32位加密MD5值。该密码仅用于在公众平台官网的多客服功能中使用,若不使用多客服功能,则不必设置密码</param> /// <returns></returns> private static WxJsonResult CustomAccountHelper(string url, string kf_account, string nickname, string password) { dynamic jsonData = new { kf_account = kf_account, nickname = nickname, password = password }; dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); WxJsonResult wxResult = EntityHelper.GetJsonResultToEntity <WxJsonResult>(result); return(wxResult); }
/// <summary> /// 设置用户备注名 /// </summary> /// <param name="accessToken"></param> /// <param name="openid"></param> /// <param name="remark">设置备注名</param> /// <returns></returns> public static WxJsonResult RemarkUser(string accessToken, string openid, string remark) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token={0}", accessToken); dynamic jsonData = new { openid = openid, remark = remark }; dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); WxJsonResult wxResult = EntityHelper.GetJsonResultToEntity <WxJsonResult>(result); return(wxResult); }
/// <summary> /// 批量为用户取消标签 /// 标签功能目前支持公众号为用户打上最多三个标签。 /// </summary> /// <param name="accessToken"></param> /// <param name="openid_list">粉丝列表</param> /// <param name="tagid"></param> /// <returns></returns> public static WxJsonResult BatchUnTagging(string accessToken, string[] openid_list, string tagid) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token={0}", accessToken); dynamic jsonData = new { openid_list = openid_list.ToList(), tagid = tagid }; dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); WxJsonResult wxResult = EntityHelper.GetJsonResultToEntity <WxJsonResult>(result); return(wxResult); }
/// <summary> /// 获取标签下粉丝列表 /// </summary> /// <param name="accessToken"></param> /// <param name="tagid"></param> /// <param name="next_openid"></param> /// <returns></returns> public static TagUserResult GetUserTagUser(string accessToken, string tagid, string next_openid) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token={0}", accessToken); dynamic jsonData = new { tagid = tagid, next_openid = next_openid }; dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); TagUserResult wxResult = EntityHelper.GetJsonResultToEntity <TagUserResult>(result); return(wxResult); }