/// <summary> /// 关注者列表,每次最多拉取10000人 /// </summary> /// <param name="token"></param> /// <param name="next_openid"></param> /// <returns></returns> public static UserListModel SubscribeList(string token, string next_openid) { string url = "https://api.weixin.qq.com/cgi-bin/user/get"; url += "?access_token=" + token; url += "&next_openid=" + next_openid; var res = new AppUtils.HttpUtil( ).Get(url); Log.Logger.Log("[wx: SubscribeList] " + url + "#" + res); try { UserListModel wx_userlist = JsonUtil.FromJson <UserListModel>(res); if (wx_userlist != null && wx_userlist.errcode == 0) { return(wx_userlist); } else { Log.Logger.Log("[wx: SubscribeList Failed] " + url + "#" + res); return(null); } } catch (Exception ex) { Log.Logger.Log("[wx: SubscribeList Exception] " + url + "#" + ex.Message); return(null); } }
/// <summary> /// 长连接转短链接 /// 使用场景:将生成二维码的长连接转成短链接之后,再生成二维码,可提高扫码速度和成功率 /// </summary> /// <param name="token"></param> /// <param name="url"></param> /// <returns></returns> public static string ShortURL(string token, string long_url) { string url = "https://api.weixin.qq.com/cgi-bin/shorturl"; url += "?access_token=" + token; var postdata = new { action = "long2short", long_url = long_url, }; var res = new AppUtils.HttpUtil( ).PostJson(url, AppUtils.JsonUtil.ToJson(postdata)); Log.Logger.Log("[wx: 长连接转短链接] " + url + "#" + res); try { ShortURLResultModel wx_shorturl = JsonUtil.FromJson <ShortURLResultModel>(res); if (wx_shorturl != null && wx_shorturl.errcode == 0) { return(wx_shorturl.short_url); } else { Log.Logger.Log("[wx: 长连接转短链接 Failed] " + url + "#" + res); return(null); } } catch (Exception ex) { Log.Logger.Log("[wx: 长连接转短链接 Exception] " + url + "#" + ex.Message); return(null); } }
/// <summary> /// 获取关注者的基本信息 /// </summary> /// <param name="token"></param> /// <param name="openid"></param> public static SubscribeUserInfoModel SubscribeUserInfo(string token, string openid) { string url = "https://api.weixin.qq.com/cgi-bin/user/info"; url += "?access_token=" + token; url += "&openid=" + openid; url += "&lang=zh_CN"; var res = new AppUtils.HttpUtil( ).Get(url); Log.Logger.Log("[wx: SubscribeUserInfo] " + url + "#" + res); try { SubscribeUserInfoModel wx_userinfo = JsonUtil.FromJson <SubscribeUserInfoModel>(res); if (wx_userinfo != null && wx_userinfo.errcode == 0) { return(wx_userinfo); } else { Log.Logger.Log("[wx: SubscribeUserInfo Failed] " + url + "#" + res); return(null); } } catch (Exception ex) { Log.Logger.Log("[wx: SubscribeUserInfo Exception] " + url + "#" + ex.Message); return(null); } }
/// <summary> /// 获取黑名单列表 /// </summary> /// <param name="token"></param> /// <param name="begin_openid"></param> /// <returns></returns> public static UserListModel GetBlackList(string token, string begin_openid) { string url = "https://api.weixin.qq.com/cgi-bin/tags/members/getblacklist"; url += "?access_token=" + token; var postdata = new { begin_openid = begin_openid }; var res = new AppUtils.HttpUtil( ).PostJson(url, AppUtils.JsonUtil.ToJson(postdata)); Log.Logger.Log("[wx: GetBlackList] " + url + "#" + res); try { UserListModel wx_balcklist = JsonUtil.FromJson <UserListModel>(res); if (wx_balcklist != null && wx_balcklist.errcode == 0) { return(wx_balcklist); } else { Log.Logger.Log("[wx: GetBlackList Failed] " + url + "#" + res); return(null); } } catch (Exception ex) { Log.Logger.Log("[wx: GetBlackList Exception] " + url + "#" + ex.Message); return(null); } }
/// <summary> /// 获取tag列表 /// </summary> /// <param name="token"></param> /// <returns></returns> public static GetTagResult Get(string token) { string url = "https://api.weixin.qq.com/cgi-bin/tags/get"; url += "?access_token=" + token; var res = new AppUtils.HttpUtil( ).Get(url); Log.Logger.Log("[wx: GetTag] " + url + "#" + res); try { GetTagResult wx_tag = JsonUtil.FromJson <GetTagResult>(res); if (wx_tag != null && wx_tag.errcode == 0) { return(wx_tag); } else { Log.Logger.Log("[wx: GetTag Failed] " + url + "#" + res); return(null); } } catch (Exception ex) { Log.Logger.Log("[wx: GetTag Exception] " + url + "#" + ex.Message); return(null); } }
/// <summary> /// 获取永久二维码ticket /// </summary> /// <param name="token"></param> /// <param name="sceneId">场景值</param> /// <returns></returns> public static GetTicketResultModel GetQRCodeTicket(string token, string sceneId) { string url = "https://api.weixin.qq.com/cgi-bin/qrcode/create"; url += "?access_token=" + token; var postdata = new { action_name = "QR_LIMIT_STR_SCENE", action_info = new { scene = new { scene_str = sceneId, } }, }; var res = new AppUtils.HttpUtil( ).PostJson(url, AppUtils.JsonUtil.ToJson(postdata)); Log.Logger.Log("[wx: 获取永久二维码] " + url + "#" + res); try { GetTicketResultModel wx_ticket = JsonUtil.FromJson <GetTicketResultModel>(res); if (wx_ticket != null && wx_ticket.errcode == 0) { return(wx_ticket); } else { Log.Logger.Log("[wx: 获取永久二维码 Failed] " + url + "#" + res); return(null); } } catch (Exception ex) { Log.Logger.Log("[wx: 获取永久二维码 Exception] " + url + "#" + ex.Message); return(null); } }
/// <summary> /// 批量获取用户基本信息 /// </summary> /// <param name="token"></param> /// <param name="openids"></param> public static BatchSubscribeUserInfoModel BatchGetUserInfo(string token, List <string> openids) { string url = "https://api.weixin.qq.com/cgi-bin/user/info/batchget"; url += "?access_token=" + token; var list = new { user_list = openids.Select(qu => new { openid = qu, lang = "zh_CN", }).ToList( ) }; var json = AppUtils.JsonUtil.ToJson(list); var res = new AppUtils.HttpUtil( ).PostJson(url, json); Log.Logger.Log("[wx: BatchGetUserInfo] " + url + "#" + res); try { BatchSubscribeUserInfoModel wx_userinfo = JsonUtil.FromJson <BatchSubscribeUserInfoModel>(res); if (wx_userinfo != null && wx_userinfo.errcode == 0) { return(wx_userinfo); } else { Log.Logger.Log("[wx: BatchGetUserInfo Failed] " + url + "#" + res); return(null); } } catch (Exception ex) { Log.Logger.Log("[wx: BatchGetUserInfo Exception] " + url + "#" + ex.Message); return(null); } }
//todo: 编辑标签 /// <summary> /// 删除标签 /// </summary> /// <param name="token"></param> /// <param name="id">标签id</param> /// <returns>是否删除成功</returns> public static bool Delete(string token, int id) { string url = "https://api.weixin.qq.com/cgi-bin/tags/delete"; url += "?access_token=" + token; var tag = new { tag = new { id = id } }; var res = new AppUtils.HttpUtil( ).PostJson(url, AppUtils.JsonUtil.ToJson(tag)); Log.Logger.Log("[wx: DeleteTag] " + url + "#" + res); try { WxError wx_tag = JsonUtil.FromJson <WxError>(res); if (wx_tag != null && wx_tag.errcode == 0) { return(true); } else { Log.Logger.Log("[wx: DeleteTag Failed] " + url + "#" + res); return(false); } } catch (Exception ex) { Log.Logger.Log("[wx: DeleteTag Exception] " + url + "#" + ex.Message); return(false); } }
/// <summary> /// 创建标签 /// </summary> /// <param name="token"></param> /// <param name="name">标签名</param> /// <returns>是否创建成功</returns> public static bool Create(string token, string name) { string url = "https://api.weixin.qq.com/cgi-bin/tags/create"; url += "?access_token=" + token; //post { "tag" : { "name" : "广东"//标签名 } }; var tag = new { tag = new { name = name, } }; var res = new AppUtils.HttpUtil( ).PostJson(url, AppUtils.JsonUtil.ToJson(tag)); Log.Logger.Log("[wx: CreateTag] " + url + "#" + res); try { CreateTagResult wx_tag = JsonUtil.FromJson <CreateTagResult>(res); if (wx_tag != null && wx_tag.errcode == 0) { return(true); } else { Log.Logger.Log("[wx: CreateTag Failed] " + url + "#" + res); return(false); } } catch (Exception ex) { Log.Logger.Log("[wx: CreateTag Exception] " + url + "#" + ex.Message); return(false); } }
/// <summary> /// 取消黑名单 /// </summary> /// <param name="token"></param> /// <param name="openids"></param> /// <returns></returns> public static bool BatchUnblockList(string token, List <string> openids) { string url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchunblacklist"; url += "?access_token=" + token; var list = new { openid_list = openids, }; var json = AppUtils.JsonUtil.ToJson(list); var res = new AppUtils.HttpUtil( ).PostJson(url, json); Log.Logger.Log("[wx: BatchUnblockList] " + url + "#" + res); try { WxError wx_status = JsonUtil.FromJson <WxError>(res); if (wx_status != null && wx_status.errcode == 0) { return(true); } else { Log.Logger.Log("[wx: BatchUnblockList Failed] " + url + "#" + res); return(false); } } catch (Exception ex) { Log.Logger.Log("[wx: BatchUnblockList Exception] " + url + "#" + ex.Message); return(false); } }