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
- {
-
-
-
- public class JPUSH
- {
-
-
-
-
-
- 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();
-
-
-
-
-
-
-
-
-
-
-
- }
- catch{}
- finally
- {
- if (response != null)
- {
- response.Close();
- }
- if (myReq != null)
- {
- myReq.Abort();
- }
- }
- }
-
-
-
-
-
- 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();
-
-
-
-
-
-
-
-
-
-
-
- }
- catch { }
- finally
- {
- if (response != null)
- {
- response.Close();
- }
- if (myReq != null)
- {
- myReq.Abort();
- }
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
- }
- }
|