微信服務號推送模板消息接口
更新時間:2015年08月03日 17:14:28 作者:-Xu-Zhao-
這篇文章主要介紹了微信服務號推送模板消息接口,需要的朋友可以參考下
微信服務號現在用的比較火,用戶可以通過微信號訂閱信息,有時候會用到模板消息。下面貼上代碼,有注釋寫的很詳細。在此@access_token 請調用 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", "請關注我們的微信通知", "#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);
}
以上就是本文針對微信服務號推送模板消息接口的全部內容,希望對大家有所幫助。

