public bool SendAndroidCustomizedcastFile(string title, string msg, string fileIds) { MyPushClient pushClient = new MyPushClient(); string fileId = pushClient.uploadContents(APP_ANDROID_KEY, APP_ANDROID_SECRET, fileIds + "alias"); MyUmengBaseNotification umengNotification = new MyUmengBaseNotification(); umengNotification.appkey = APP_ANDROID_KEY; umengNotification.production_mode = "true"; umengNotification.alias_type = "jadeMember"; umengNotification.type = "customizedcast"; umengNotification.file_id = fileId; var body = new { text = msg, title = title, ticker = "收到一条张寿宴玉雕消息通知", after_open = "go_app", }; var payload = new { body = body, display_type = "notification" }; umengNotification.payload = payload; return(pushClient.send(umengNotification, APP_ANDROID_SECRET)); }
public bool SendAndroidCustomizedcastFile(string title, string msg, string fileIds, string activity, string url) { MyPushClient pushClient = new MyPushClient(); string fileId = pushClient.uploadContents(APP_ANDROID_KEY, APP_ANDROID_SECRET, fileIds + "alias"); MyUmengBaseNotification umengNotification = new MyUmengBaseNotification(); umengNotification.appkey = APP_ANDROID_KEY; umengNotification.production_mode = "true"; umengNotification.alias_type = "jadeMember"; umengNotification.type = "customizedcast"; umengNotification.file_id = fileId; var body = new { text = msg, title = title, ticker = "收到一条张寿宴玉雕消息通知", after_open = "go_activity", activity = "com.android.zhangsy.H5urlActivity" }; if (String.IsNullOrEmpty(url) == false) { var extra = new { theme_url = url }; var payload = new { body = body, display_type = "notification", extra = extra }; umengNotification.payload = payload; } else { var payload = new { body = body, display_type = "notification", theme_url = url }; umengNotification.payload = payload; } return(pushClient.send(umengNotification, APP_ANDROID_SECRET)); }
public bool send(MyUmengBaseNotification msg, string appMasterSecret) { HttpWebResponse response = null; Stream receiveStream = null; StreamReader readStream = null; MemoryStream postStream = new MemoryStream(); try { // Construct the result HttpRequestResult result = new HttpRequestResult(); string timestamp = GetTimeStamp().ToString(); msg.timestamp = timestamp; // Construct the json string string postBody = JsonConvert.SerializeObject(msg); string url = host + postPath; string sign = IOHelper.GetMD5HashFromString("POST" + url + postBody + appMasterSecret); url = url + "?sign=" + sign; // Construct the request HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Method = "POST"; request.UserAgent = USER_AGENT; byte[] bs = Encoding.UTF8.GetBytes(postBody); request.ContentLength = bs.Length; using (Stream reqStream = request.GetRequestStream()) { reqStream.Write(bs, 0, bs.Length); reqStream.Close(); } response = (HttpWebResponse)request.GetResponse(); receiveStream = response.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); readStream = new StreamReader(receiveStream, encode); result.Content = readStream.ReadToEnd(); if (response.StatusCode == HttpStatusCode.OK) { return(true); } else { return(false); } } catch (WebException ex) { HttpWebResponse res = (HttpWebResponse)ex.Response; Stream myResponseStream = res.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8")); string retString = myStreamReader.ReadToEnd(); Debug.Assert(false, retString); throw; } catch (Exception ex) { Debug.Assert(false, ex.Message); throw; } finally { if (response != null) { response.Close(); } if (receiveStream != null) { receiveStream.Close(); } if (readStream != null) { readStream.Close(); } if (postStream != null) { postStream.Close(); } } }