微信服務(wù)號現(xiàn)在用的比較火,用戶可以通過微信號訂閱信息,有時候會用到模板消息。下面貼上代碼,有注釋寫的很詳細(xì)。在此@access_token 請調(diào)用 https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=@appid&secret=@secret 接口獲取。
具體代碼:
public static void Send()   {    dynamic postData = new ExpandoObject();    postData.touser = "OpenId";    postData.template_id = "template_id";    postData.url = string.Empty;    postData.topcolor = "#FF";    postData.data = new ExpandoObject();    var data = new[]    {     new Tuple<string, string, string>("title", "航班延誤通知", "#FF"),     new Tuple<string, string, string>("trainNumber", "分鐘", "#FF"),     new Tuple<string, string, string>("fromto", "上海-北京", "#FF"),     new Tuple<string, string, string>("formerTime", "http:// ::", "#FF"),     new Tuple<string, string, string>("Time", "http:// ::", "#FF"),     new Tuple<string, string, string>("number", "分鐘", "#FF"),     new Tuple<string, string, string>("reason", "天氣原因", "#FF"),     new Tuple<string, string, string>("remark", "請關(guān)注我們的微信通知", "#FF")    };    var dataDict = (IDictionary<string, object>)postData.data;    foreach (var item in data)    {     dataDict.Add(item.Item, new { value = item.Item, color = item.Item });    }    string json = ((object)postData).Serialize();    Console.WriteLine(json);    var r = NetUtils.CreateHttpResponse(@"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=@access_token", json);    Console.WriteLine(r);   }以上就是本文針對微信服務(wù)號推送模板消息接口的全部內(nèi)容,希望對大家有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選