/// <summary> /// 模板消息接口 /// </summary> /// <param name="accessTokenOrAppId"></param> /// <param name="openId"></param> /// <param name="templateId"></param> /// <param name="topcolor"></param> /// <param name="url"></param> /// <param name="data"></param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <returns></returns> public static SendTemplateMessageResult SendTemplateMessage(string accessTokenOrAppId, string openId, string templateId, string topcolor, string url, object data, int timeOut = Config.TIME_OUT) { return(ApiHandlerWapper.TryCommonApi(accessToken => { const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}"; var msgData = new TempleteModel() { touser = openId, template_id = templateId, topcolor = topcolor, url = url, data = data }; return CommonJsonSend.Send <SendTemplateMessageResult>(accessToken, urlFormat, msgData, timeOut: timeOut); }, accessTokenOrAppId)); }
/// <summary> /// 【异步方法】模板消息接口 /// </summary> /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param> /// <param name="openId"></param> /// <param name="templateId"></param> /// <param name="url"></param> /// <param name="data"></param> /// <param name="miniProgram">跳小程序所需数据,不需跳小程序可不用传该数据</param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <returns></returns> public static async Task <SendTemplateMessageResult> SendTemplateMessageAsync(string accessTokenOrAppId, string openId, string templateId, string url, object data, TempleteModel_MiniProgram miniProgram = null, int timeOut = Config.TIME_OUT) { return(await ApiHandlerWapper.TryCommonApiAsync(async accessToken => { const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}"; var msgData = new TempleteModel() { touser = openId, template_id = templateId, // topcolor = topcolor, url = url, miniprogram = miniProgram, data = data }; return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync <SendTemplateMessageResult>(accessToken, urlFormat, msgData, timeOut: timeOut); }, accessTokenOrAppId)); }
/// <summary> /// 模板消息接口 /// </summary> /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param> /// <param name="openId"></param> /// <param name="templateId"></param> /// <param name="url"></param> /// <param name="data"></param> /// <param name="miniProgram">跳小程序所需数据,不需跳小程序可不用传该数据</param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <returns></returns> public static SendTemplateMessageResult SendTemplateMessage(string accessTokenOrAppId, string openId, string templateId, string url, object data, TempleteModel_MiniProgram miniProgram = null, int timeOut = Config.TIME_OUT) { return(ApiHandlerWapper.TryCommonApi(accessToken => { string urlFormat = Config.ApiMpHost + "/cgi-bin/message/template/send?access_token={0}"; var msgData = new TempleteModel() { touser = openId, template_id = templateId, // topcolor = topcolor, url = url, miniprogram = miniProgram, data = data }; return CommonJsonSend.Send <SendTemplateMessageResult>(accessToken, urlFormat, msgData, timeOut: timeOut); }, accessTokenOrAppId)); }
/// <summary> /// 模板消息接口 /// </summary> /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param> /// <param name="openId">填接收消息的用户openid</param> /// <param name="templateId">订阅消息模板ID</param> /// <param name="url">(非必须)点击消息跳转的链接,需要有ICP备案</param> /// <param name="data">消息正文,value为消息内容文本(200字以内),没有固定格式,可用\n换行,color为整段消息内容的字体颜色(目前仅支持整段消息为一种颜色)</param> /// <param name="miniProgram">(非必须)跳小程序所需数据,不需跳小程序可不用传该数据</param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <returns></returns> public static SendTemplateMessageResult SendTemplateMessage(string accessTokenOrAppId, string openId, string templateId, string url, object data, TempleteModel_MiniProgram miniProgram = null, int timeOut = WxConfig.TIME_OUT) { //文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1500374289_66bvB return(ApiHandlerWapper.TryCommonApi(accessToken => { string urlFormat = WxConfig.ApiMpHost + "/cgi-bin/message/template/send?access_token={0}"; var msgData = new TempleteModel() { touser = openId, template_id = templateId, // topcolor = topcolor, url = url, miniprogram = miniProgram, data = data, }; return CommonJsonSend.Send <SendTemplateMessageResult>(accessToken, urlFormat, msgData, timeOut: timeOut); }, accessTokenOrAppId)); }