|
- private void ts_01(string title, string content, string userIds)
- {
- string AppId = "";///这两个在api概览里面
- string AppKey = "";
- string formData = String.Format("title={0}&content={1}&type={2}&platform={3}&userIds={4}", title, content, 1, 0, userIds);
- //标题1 内容2 消息1/通知2 平台0全部1ios2案桌 制定用户5 (还可以制定群组)
- string url = String.Format("https://p.apicloud.com/api/push/message");
- **.**.HttpWebRequest request =**.**.HttpWebRequest.Create(url) as**.**.HttpWebRequest;
- request.Method = "POST";
- request.Headers.Add("X-APICloud-AppId", AppId);
- request.Headers.Add("X-APICloud-AppKey", GetSHA1Key(AppId, AppKey));
- //aha1加密
- request.ContentType = "application/x-www-form-urlencoded";
- byte[] postData = System.Text.Encoding.UTF8.GetBytes(formData);
- request.ContentLength = postData.Length;
- using (System.IO.Stream reqStream = request.GetRequestStream())
- {
- //StreamWriter reqWriter = new StreamWriter(reqStream);
- reqStream.Write(postData, 0, postData.Length);
- //reqWriter.Write(formData);
- using (var response = request.GetResponse() as**.**.HttpWebResponse)
- {
- using (System.IO.Stream respSream = response.GetResponseStream())
- {
- System.IO.StreamReader respReader = new System.IO.StreamReader(respSream);
- string result = respReader.ReadToEnd();
- //Console.WriteLine(result);
- }
- }
- }
- }
- //sha1加密
- static String GetSHA1Key(String AppId, String AppKey)
- {
- long longTime = (long)(DateTime.Now - new DateTime(1970, 01, 01)).TotalMilliseconds;
- String value = String.Format("{0}UZ{1}UZ{2}", AppId, AppKey, longTime);
- byte[] buffer = System.Security.Cryptography.SHA1.Create().ComputeHash(System.Text.Encoding.UTF8.GetBytes(value));
- System.Text.StringBuilder builder = new System.Text.StringBuilder();
- foreach (byte num in buffer)
- {
- builder.AppendFormat("{0:x2}", num);
- }
- return builder.ToString() + "." + longTime;
- }
- }
复制代码 |
|