123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Web;
- namespace Ant.Common
- {
- /// <summary>
- /// 激光推送
- /// </summary>
- public class JPUSH
- {
- /// <summary>
- ///
- /// </summary>
- /// <param name="aliass"></param>
- /// <param name="msg"></param>
- public static void sendRequest(string aliass, string msg)
- {
- String app_key = ConfigurationManager.AppSettings["JPushKey"];
- String master_secret = ConfigurationManager.AppSettings["JPushSecret"];
- byte[] bytes = Encoding.Default.GetBytes((app_key + ":" + master_secret));
- string auth = Convert.ToBase64String(bytes);
- String url = "https://api.jpush.cn/v3/push";
- string pushmsg = "{\"platform\":\"all\",\"audience\":{\"alias\":" + aliass + "},\"notification\":{\"alert\":" + msg + ",\"android\":{},\"ios\":{\"sound\":\"sound.caf\",\"badge\":1}},\"options\":{\"apns_production\":false}}";
- HttpWebRequest myReq = null;
- HttpWebResponse response = null;
- try
- {
- myReq = (HttpWebRequest)WebRequest.Create(url);
- myReq.Method = "POST";
- myReq.ContentType = "application/json";
- myReq.Headers.Add("Authorization", "Basic " + auth);
- byte[] bs = UTF8Encoding.UTF8.GetBytes(pushmsg);
- myReq.ContentLength = bs.Length;
- using (Stream reqStream = myReq.GetRequestStream())
- {
- reqStream.Write(bs, 0, bs.Length);
- reqStream.Close();
- }
- myReq.GetResponse();
- //string res = "";
- //response = (HttpWebResponse)myReq.GetResponse();
- //HttpStatusCode statusCode = response.StatusCode;
- //if (Equals(response.StatusCode, HttpStatusCode.OK))
- //{
- // using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
- // {
- // res = reader.ReadToEnd();
- // }
- //}
- //res = res + "";
- }
- catch{}
- finally
- {
- if (response != null)
- {
- response.Close();
- }
- if (myReq != null)
- {
- myReq.Abort();
- }
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="aliass"></param>
- /// <param name="msg"></param>
- public static void sendRequest_app(string aliass, string msg)
- {
- String app_key = ConfigurationManager.AppSettings["JpushKey_us"];
- String master_secret = ConfigurationManager.AppSettings["JpushSecret_us"];
- byte[] bytes = Encoding.Default.GetBytes((app_key + ":" + master_secret));
- string auth = Convert.ToBase64String(bytes);
- String url = "https://api.jpush.cn/v3/push";
- string pushmsg = "{\"platform\":\"all\",\"audience\":{\"alias\":" + aliass + "},\"notification\":{\"alert\":" + msg + ",\"android\":{},\"ios\":{\"sound\":\"sound.caf\",\"badge\":1}},\"options\":{\"apns_production\":false}}";
- HttpWebRequest myReq = null;
- HttpWebResponse response = null;
- try
- {
- myReq = (HttpWebRequest)WebRequest.Create(url);
- myReq.Method = "POST";
- myReq.ContentType = "application/json";
- myReq.Headers.Add("Authorization", "Basic " + auth);
- byte[] bs = UTF8Encoding.UTF8.GetBytes(pushmsg);
- myReq.ContentLength = bs.Length;
- using (Stream reqStream = myReq.GetRequestStream())
- {
- reqStream.Write(bs, 0, bs.Length);
- reqStream.Close();
- }
- myReq.GetResponse();
- //string res = "";
- //response = (HttpWebResponse)myReq.GetResponse();
- //HttpStatusCode statusCode = response.StatusCode;
- //if (Equals(response.StatusCode, HttpStatusCode.OK))
- //{
- // using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
- // {
- // res = reader.ReadToEnd();
- // }
- //}
- //res = res + "";
- }
- catch { }
- finally
- {
- if (response != null)
- {
- response.Close();
- }
- if (myReq != null)
- {
- myReq.Abort();
- }
- }
- }
- //Common.JPUSH.sendRequest(("[\"" + note.CM_USERID + "\"]"), ("\"用户#" + username + "#回复了您的帖子\""));
- //aliass = "[\"18888888888\",\"17777777777\"]";
- //msg = "\"晚上带你抢银行\"";
- //response = (HttpWebResponse)myReq.GetResponse();
- //HttpStatusCode statusCode = response.StatusCode;
- //if (Equals(response.StatusCode, HttpStatusCode.OK))
- //{
- // using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
- // {
- // res = reader.ReadToEnd();
- // }
- //}
- }
- }
|