说白了其实就是如何使用云之家的消息接口{:6_164:}
参考文档:云之家API文档
var openIdList = new List<string>(); openIdList.Add("用户openID"); MessageObject messageObject = new MessageObject() { Eid = "团队EID", Pub = "公众号ID", PubSercet = "公众号密钥", Nonce = new Guid().ToString("N"), Time = (DateTime.Now.Ticks -Convert.ToDateTime("1970-01-0100:00:00").Ticks) /10000, RequestUrl = "https://do.yunzhijia.com/pubacc/pubsend", AppId = "10037", Title = "tip", Text = "test message", RedirectUrl = "跳转链接" };
string requestUrl =messageObject.RequestUrl; string no = messageObject.Eid; string pub = messageObject.Pub; string time = messageObject.Time.ToString(); string nonce = messageObject.Nonce; string pubSercet = messageObject.PubSercet; string[] array = { no, pub, pubSercet, nonce, time}; string pubToken = string.Format("{0}{1}{2}{3}{4}", array[0], array[1], array[2],array[3], array[4]); SHA1 sha1 = SHA1.Create(pubToken); string title = messageObject.Title; string text = messageObject.Text; string date = string.Format("{0:G}", DateTime.Now); string url = messageObject.RedirectUrl; string appid = messageObject.AppId; string openIdStr = ""; foreach (var openId in openIdList) { openIdStr += "\"" + openId + "\","; } if (openIdStr == "") return false; openIdStr = openIdStr.Substring(0,openIdStr.Length - 1); string json = "{\"from\":{\"no\":\"" + no + "\",\"pub\":\"" + pub + "\",\"time\":\"" + time + "\",\"nonce\":\"" + nonce + "\",\"pubtoken\":\"" + sha1 + "\"},\"to\":[{\"no\":\"" + no + "\",\"user\":[" + openIdStr + "]}],\"type\":\"5\",\"msg\":{\"model\":\"1\",\"todo\":\"1\",\"list\":[{\"date\":\"" + date + "\",\"title\":\"" + title + "\",\"text\":\"" + text + "\",\"url\":\"" + url + "\",\"appid\":\"" + appid + "\"}]}}"; HttpWebRequest request =(HttpWebRequest)WebRequest.Create(requestUrl); request.Method = "POST"; request.ContentType = "application/json;charset=utf-8"; request.ContentLength =Encoding.UTF8.GetBytes(json).Length; Stream writer =request.GetRequestStream(); writer.Write(Encoding.UTF8.GetBytes(json), 0, Encoding.UTF8.GetBytes(json).Length); HttpWebResponse response =(HttpWebResponse)request.GetResponse(); string encoding = response.ContentEncoding; if (string.IsNullOrEmpty(encoding)) { encoding = "UTF-8"; } StreamReader reader = new StreamReader(response.GetResponseStream(),Encoding.GetEncoding(encoding)); string ret = reader.ReadToEnd();
public class MessageObject { public string RequestUrl { get; set; } public string Eid { get; set; } public string Pub { get; set; } public string PubSercet { get; set; } public string Nonce { get; set; } public long Time { get; set; } public string AppId { get; set; } public string Title { get; set; } public string Text { get; set; } public string RedirectUrl { get; set; } }
type
2:纯文本信息
5:文本链接信息
6:图文混排信息
todo
1:待办任务
2:公众号消息
推荐阅读