/// <summary> /// 更改卡券信息 /// </summary> /// <param name="access_token">公众号access token</param> /// <param name="card_type">卡券类型 全大写</param> /// <param name="card_id">卡券id</param> /// <param name="data">卡券数据</param> /// <returns></returns> public JsonResult <bool> UpdateCard(string access_token, string card_type, string card_id, BaseCard data) { DynamicDictionary dic = new DynamicDictionary(); dic.SetMember("card_id", card_id); dic.SetMember(card_type.ToLower(), data); string url = $"{Config.WxApi}card/update?access_token={access_token}"; return(WxAPI.RequestData <bool>(url, dic.GetMembers(), Method.POST)); }
private MassResult Mass(string access_token, string route, DynamicDictionary data, string clientmsgid) { //https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=ACCESS_TOKEN //https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=ACCESS_TOKEN if (!string.IsNullOrEmpty(clientmsgid)) { data.SetMember("clientmsgid", clientmsgid); } string url = $"{Config.WxApi}cgi-bin/message/mass/{route}?access_token={access_token}"; return(WxAPI.Request <MassResult>(url, data.GetMembers(), Method.POST)); }
/// <summary> /// 核销Code接口 /// </summary> /// <param name="access_token">公众号access token</param> /// <param name="card_id">卡券ID</param> /// <param name="code">需核销的Code码。创建卡券时use_custom_code填写true时必填。非自定义Code不必填写。</param> /// <returns></returns> public ConsumerCodeResult ConsumerCode(string access_token, string card_id, string code) { DynamicDictionary dic = new DynamicDictionary(); dic.SetMember("card_id", card_id); if (!string.IsNullOrEmpty(code)) { dic.SetMember("code", code); } string url = $"{Config.WxApi}card/code/consume?access_token={access_token}"; return(WxAPI.Request <ConsumerCodeResult>(url, dic.GetMembers(), Method.POST)); }
private QRCodeResult Create(string access_token, string actionName, object action, int?expire_seconds = null) { DynamicDictionary dic = new DynamicDictionary(); if (expire_seconds != null && expire_seconds.HasValue) { dic.SetMember("expire_seconds", expire_seconds.Value); } dic.SetMember("action_name", actionName); dic.SetMember("action_info", action); string url = $"{Config.WxApi}cgi-bin/qrcode/create?access_token={access_token}"; return(WxAPI.Request <QRCodeResult>(url, dic.GetMembers(), Method.POST)); }
/// <summary> /// 创建卡券 /// </summary> /// <param name="access_token">公众号access token</param> /// <param name="card_type">卡券类型</param> /// <param name="data">卡券数据</param> /// <returns>data字段为card_id</returns> public JsonResult <string> CreateCard(string access_token, string card_type, BaseCard data) { DynamicDictionary dic = new DynamicDictionary(); dic.SetMember("card_type", card_type?.ToUpper()); dic.SetMember(card_type?.ToLower(), data); var obj = new { card = dic.GetMembers() }; string url = $"{Config.WxApi}card/create?access_token={access_token}"; return(WxAPI.RequestData <string>(url, obj, Method.POST)); }
/// <summary> /// 设置卡券失效 /// </summary> /// <param name="access_token">公众号access token</param> /// <param name="card_id">卡券ID</param> /// <param name="code">设置失效的Code码</param> /// <param name="reason">失效理由</param> /// <returns></returns> public JsonResult Unavailable(string access_token, string card_id, string code, string reason) { DynamicDictionary dic = new DynamicDictionary(); dic.SetMember("card_id", card_id); if (!string.IsNullOrEmpty(code)) { dic.SetMember("code", code); } if (!string.IsNullOrEmpty(reason)) { dic.SetMember("reason", reason); } string url = $"{Config.WxApi}card/code/unavailable?access_token={access_token}"; return(WxAPI.Request <JsonResult>(url, dic.GetMembers(), Method.POST)); }
/// <summary> /// 下架-礼品卡货架 /// </summary> /// <param name="access_token">公众号access token</param> /// <param name="page_id">需要下架的page_id</param> /// <param name="maintain"></param> /// <param name="all">所有的货架设置为下架</param> /// <returns></returns> public JsonResult <GiftCardShelvesControl> Obtained(string access_token, string page_id, bool maintain, bool?all) { DynamicDictionary dic = new DynamicDictionary(); if (!string.IsNullOrEmpty(page_id)) { dic.SetMember("page_id", page_id); } if (all != null) { dic.SetMember("all", all.Value); } dic.SetMember("maintain", maintain); string url = $"{Config.WxApi}card/giftcard/maintain/set?access_token={access_token}"; return(WxAPI.RequestData <GiftCardShelvesControl>(url, dic.GetMembers(), Method.POST)); }
private Dictionary <string, object> GetMassFilter(string tag_id) { DynamicDictionary filter = new DynamicDictionary(); bool is_to_all = false; if (string.IsNullOrEmpty(tag_id)) { is_to_all = true; } else { filter.SetMember("tag_id", tag_id); } filter.SetMember("is_to_all", is_to_all); Dictionary <string, object> dic = filter.GetMembers(); return(dic); }
/// <summary> /// 设置自助核销接口 /// </summary> /// <param name="access_token">公众号access token</param> /// <param name="card_id">卡券ID</param> /// <param name="is_open">是否开启自助核销功能,填true/false,默认为false</param> /// <param name="need_verify_cod">用户核销时是否需要输入验证码, 填true/false, 默认为false</param> /// <param name="need_remark_amount">用户核销时是否需要输入验证码, 填true/false, 默认为false</param> /// <returns></returns> public JsonResult SetSelfConsumerCell(string access_token, string card_id, bool is_open, bool?need_verify_cod, bool?need_remark_amount) { DynamicDictionary dic = new DynamicDictionary(); dic.SetMember("card_id", card_id); dic.SetMember("is_open", is_open); if (need_verify_cod != null && need_verify_cod.HasValue) { dic.SetMember("need_verify_cod", need_verify_cod.Value); } if (need_remark_amount != null && need_remark_amount.HasValue) { dic.SetMember("need_remark_amount", need_remark_amount.Value); } string url = $"https://api.weixin.qq.com/card/selfconsumecell/set?access_token={access_token}"; return(WxAPI.Request <JsonResult>(url, dic.GetMembers(), Method.POST)); }
/// <summary> /// 查询Code接口 /// </summary> /// <param name="access_token">公众号access token</param> /// <param name="card_id">卡券ID</param> /// <param name="code">单张卡券的唯一标准</param> /// <param name="check_consume">是否校验code核销状态,填入true和false时的code异常状态返回数据不同。</param> /// <param name="is_expire_dynamic_code">是否查询过期动态码,设置该参数为true时,开发者可以查询到超时的动态码,用于处理因断网导致的积压订单。默认为false</param> /// <returns></returns> public CodeStateResult GetCardCode(string access_token, string card_id, string code, bool?check_consume, bool?is_expire_dynamic_code) { DynamicDictionary dic = new DynamicDictionary(); dic.SetMember("card_id", card_id); dic.SetMember("code", code); if (check_consume != null) { dic.SetMember("check_consume", check_consume.Value); } if (is_expire_dynamic_code != null) { dic.SetMember("is_expire_dynamic_code", is_expire_dynamic_code.Value); } string url = $"{Config.WxApi}card/code/get?access_token={access_token}"; return(WxAPI.Request <CodeStateResult>(url, dic.GetMembers(), Method.POST)); }
/// <summary> /// 客服接口-发消息 /// </summary> /// <param name="access_token">公众号access token</param> /// <param name="msgtype">消息类型</param> /// <param name="touser">消息接收人openid</param> /// <param name="send_value">需要发送的消息体, /// 文本消息: string 类型字符串 /// 图片|语音|图文: 素材库中的media id /// 视频消息:<see cref="Msg.Customer.KFVideoMsg"/> /// 音乐消息:<see cref="Msg.Customer.KFMusicMsg"/> /// 外链图文:<see cref="Msg.Customer.KFArticleMsg"/> /// 菜单消息:<see cref="Msg.Customer.KFMsgMenuMsg"/> /// 小程序 :<see cref="Msg.Customer.KFMiniprogramMsg"/> /// </param> /// <param name="kf_account">如果需要以某个客服帐号来发消息则填写</param> /// <returns></returns> public JsonResult SendMsg(string access_token, CustomerMsgType msgtype, string touser, object send_value, string kf_account) { DynamicDictionary dic = new DynamicDictionary(); string smsgType = msgtype.ToString(); dic.SetMember("touser", touser); dic.SetMember("msgtype", msgtype.ToString()); switch (msgtype) { case CustomerMsgType.text: dic.SetMember(smsgType, new { content = send_value }); break; case CustomerMsgType.image: case CustomerMsgType.voice: case CustomerMsgType.mpnews: dic.SetMember(smsgType, new { media_id = send_value }); break; case CustomerMsgType.wxcard: dic.SetMember(smsgType, new { card_id = send_value }); break; case CustomerMsgType.video: case CustomerMsgType.music: case CustomerMsgType.news: case CustomerMsgType.msgmenu: case CustomerMsgType.miniprogrampage: dic.SetMember(smsgType, send_value); break; } if (!string.IsNullOrEmpty(kf_account)) { dic.SetMember("customservice", new { kf_account }); } string url = $"{Config.WxApi}cgi-bin/message/custom/send?access_token={access_token}"; return(WxAPI.Request <JsonResult>(url, dic.GetMembers(), Method.POST)); }
/// <summary> /// 设置跟随推荐 /// </summary> /// <param name="access_token">公众号access token</param> /// <param name="card_id">会员卡id</param> /// <param name="data">需要设置的类型</param> public JsonResult SetFollowRecommendation(string access_token, string card_id, RecommendationData data) { object operation = null; if (data is ActivateMsgOperation) { operation = new { activate_msg_operation = data } } ; else if (data is ModifyMsgOperation) { operation = new { modify_msg_operation = data } } ; DynamicDictionary dic = new DynamicDictionary(); dic.SetMember("card_id", card_id); dic.SetMember("member_card", operation); string url = $"{Config.WxApi}card/update?access_token={access_token}"; return(WxAPI.Request <JsonResult>(url, dic.GetMembers(), Method.POST)); }
/// <summary> /// 预览接口 /// </summary> /// <param name="access_token">公众号access token</param> /// <param name="type">预览消息类型</param> /// <param name="send_value">需要发送的值</param> /// <param name="touser">根据openid发送, towxname和touser同时赋值时,以towxname优先</param> /// <param name="towxname">根据微信号发送, towxname和touser同时赋值时,以towxname优先</param> /// <returns></returns> private MassResult Preview(string access_token, MassType type, string send_value, string touser, string towxname) { DynamicDictionary dic = new DynamicDictionary(); string msgtype = type.ToString(); if (!string.IsNullOrEmpty(touser)) { dic.SetMember("touser", touser); } if (!string.IsNullOrEmpty(towxname)) { dic.SetMember("towxname", towxname); } switch (msgtype) { case "text": dic.SetMember("text", new { content = send_value }); break; case "wxcard": dic.SetMember("wxcard", new { card_id = send_value }); break; case "mpvideo": VideoConvertResult result = this.ConvertVideo(access_token, send_value, "", ""); dic.SetMember("mpvideo", new { media_id = send_value }); break; default: dic.SetMember(msgtype, new { media_id = send_value }); break; } dic.SetMember("msgtype", msgtype); string url = $"{Config.WxApi}cgi-bin/message/mass/preview?access_token={access_token}"; return(WxAPI.Request <MassResult>(url, dic.GetMembers(), Method.POST)); }