項目要用到微信提醒 ,加上調轉到小程式頁面,或者 指定url 用到 RestSharp、Senparc.Weixin 類庫 一開始直接照著微信示例直接post進去 發現一直提示 47001 ,估計是我姿勢水平不太夠,還是用個類庫操作吧 ...
項目要用到微信提醒 ,加上調轉到小程式頁面,或者 指定url
用到 RestSharp、Senparc.Weixin 類庫
一開始直接照著微信示例直接post進去 發現一直提示 47001 ,估計是我姿勢水平不太夠,還是用個類庫操作吧
using RestSharp; using Senparc.Weixin.MP.AdvancedAPIs.TemplateMessage; using System; namespace TemplateApp1 { class Program { public static string OpenId = ""; public static string Template_id = ""; public static string AccessToken = GetACCESS_TOKEN(); static void Main(string[] args) { //網頁跳轉 SendTemplateMessageResult T = SendTemplateURL(AccessToken, OpenId, Template_id); //小程式跳轉 SendTemplateMessageResult T1 = SendTemplatMiniProgram(AccessToken, OpenId, Template_id); Console.WriteLine(T+"\n"+T1); Console.ReadKey(); } /// <summary> /// 網頁跳轉 /// </summary> /// <param name="openId"></param> /// <param name="template_id"></param> /// <returns></returns> public static SendTemplateMessageResult SendTemplateURL(string accessToken, string openId,string template_id) { var data = new { first = new TemplateDataItem("網頁跳轉"), keyword1 = new TemplateDataItem("keyword1"), keyword2 = new TemplateDataItem(DateTime.Now.ToString("yyyy年MM月dd日 HH:mm")), remark = new TemplateDataItem("remark"), }; string url = "https://baidu.com"; return Senparc.Weixin.MP.AdvancedAPIs.TemplateApi.SendTemplateMessage(accessToken, openId, template_id, url, data,null); } /// <summary> /// 小程式跳轉 /// </summary> /// <param name="openId"></param> /// <param name="template_id"></param> /// <returns></returns> public static SendTemplateMessageResult SendTemplatMiniProgram(string accessToken,string openId, string template_id) { var data = new { first = new TemplateDataItem("小程式跳轉"), keyword1 = new TemplateDataItem("keyword1"), keyword2 = new TemplateDataItem(DateTime.Now.ToString("yyyy年MM月dd日 HH:mm")), remark = new TemplateDataItem("remark"), }; // 小程式 TempleteModel_MiniProgram miniProgram = new TempleteModel_MiniProgram { appid = "", pagepath = "" }; string url = string.Empty; return Senparc.Weixin.MP.AdvancedAPIs.TemplateApi.SendTemplateMessage(accessToken, openId, template_id, url, data, miniProgram); } /// <summary> /// 獲取 AccessToken 需保存 有次數限制 /// </summary> /// <returns></returns> public static string GetACCESS_TOKEN() { string url = ""; var request = new RestRequest("", Method.GET); RestClient restClient = new RestClient(url); return restClient.Execute(request).Content; } } }