激光推送(ios,安卓)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO.Compression; using System.IO; using System.Net;
namespace demo { class MD5 { public static string MD5Encrypt(string strSource) {
return MD5Encrypt(strSource, 32);
}
/// <summary>
/// </summary>
/// <param name="strSource">待加密字串</param>
/// <param name="length">16或32值之一,其它则采用.net默认MD5加密算法</param>
/// <returns>加密后的字串</returns>
public static string MD5Encrypt(string strSource, int length) {
byte[] bytes = Encoding.ASCII.GetBytes(strSource);
byte[] hashValue = ((System.Security.Cryptography.HashAlgorithm)System.Security.Cryptography.CryptoConfig.CreateFromName("MD5")).ComputeHash(bytes);
StringBuilder sb = new StringBuilder();
switch (length) {
case 16:
for (int i = 4; i < 12; i++)
sb.Append(hashValue[i].ToString("x2"));
break;
case 32:
for (int i = 0; i < 16; i++) {
sb.Append(hashValue[i].ToString("x2"));
}
break;
default:
for (int i = 0; i < hashValue.Length; i++) {
sb.Append(hashValue[i].ToString("x2"));
}
break;
}
return sb.ToString();
}
public static string doSend() {
IDictionary<string, string> parameters = new Dictionary<string, string>();
string html = string.Empty;
int sendno = 1;
string receiverValue = "eric";//这个是一个别名
int receiverType = 4;
string appkeys = "51b45123b7313212ba35123dcc7e303123257eb";
String input = sendno.ToString() + receiverType + "" + "5232135e230314a412321312bb2fb12133d27c845";
string verificationCode = MD5Encrypt(input);
string content = "{\"n_content\":\"" + receiverValue + "\",\"n_builder_id\":\"1\"}"; //发送的内容
string loginUrl = "http://api.jpush.cn:8800/sendmsg/v2/sendmsg";
parameters.Add("sendno", sendno.ToString());
parameters.Add("app_key", appkeys);
parameters.Add("receiver_type", receiverType.ToString());
parameters.Add("verification_code", verificationCode); //MD5
parameters.Add("msg_type", "1");
parameters.Add("msg_content", content); //内容
parameters.Add("platform", "android,ios");
HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(loginUrl, parameters, null, null, Encoding.UTF8, null);
if (response != null) {
// 得到返回的数据流
Stream receiveStream = response.GetResponseStream();
// 如果有压缩,则进行解压
if (response.ContentEncoding.ToLower().Contains("gzip")) {
receiveStream = new GZipStream(receiveStream, CompressionMode.Decompress);
}
// 得到返回的字符串
html = new StreamReader(receiveStream).ReadToEnd();
}
return html;
}
} }
byte[] data = Encoding.UTF8.GetBytes(buffer.ToString());
using (Stream stream = request.GetRequestStream()) {
stream.Write(data, 0, data.Length);
}
}
return request.GetResponse() as HttpWebResponse;
}
private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) {
return true; //总是接受
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO; using System.IO.Compression;
namespace demo { class Program { public static string MD5Encrypt(string strSource) {
return MD5Encrypt(strSource, 32);
} public static string MD5Encrypt(string strSource, int length) {
byte[] bytes = Encoding.ASCII.GetBytes(strSource);
byte[] hashValue = ((System.Security.Cryptography.HashAlgorithm)System.Security.Cryptography.CryptoConfig.CreateFromName("MD5")).ComputeHash(bytes);
StringBuilder sb = new StringBuilder();
switch (length) {
case 16:
for (int i = 4; i < 12; i++)
sb.Append(hashValue[i].ToString("x2"));
break;
case 32:
for (int i = 0; i < 16; i++) {
sb.Append(hashValue[i].ToString("x2"));
}
break;
default:
for (int i = 0; i < hashValue.Length; i++) {
sb.Append(hashValue[i].ToString("x2"));
}
break;
}
return sb.ToString();
} public static string doSend() {
IDictionary<string, string> parameters = new Dictionary<string, string>();
string html = string.Empty;
int sendno = 1;
string receiverValue = "863094010028545";//这个是一个别名 如果使用别名需要加参数 parameters.Add("receiver_value", receiverValue.ToString()); 否则去掉这行代码
int receiverType = 3;//3是使用别名,4是使用广播
string appkeys = "6749f40904629f928a5c28e4"; string appkeysCode = "ed55187688f7ba184d34cb97";//极光推送portal 上分配的 appKey 的验证串(masterSecret) String input = sendno.ToString() + receiverType + receiverValue + appkeysCode;
string verificationCode = MD5Encrypt(input); string strcontent = "测试"; string content = "{\"n_content\":\"" + strcontent + "\",\"n_builder_id\":\"1\"}"; //发送的内容
string loginUrl = "http://api.jpush.cn:8800/sendmsg/v2/sendmsg";
parameters.Add("sendno", sendno.ToString());
parameters.Add("app_key", appkeys);
parameters.Add("receiver_type", receiverType.ToString()); parameters.Add("receiver_value", receiverValue.ToString()); parameters.Add("verification_code", verificationCode); //MD5
parameters.Add("msg_type", "1");
parameters.Add("msg_content", content); //内容
parameters.Add("platform", "android,ios");
HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(loginUrl, parameters, null, null, Encoding.UTF8, null);
if (response != null) {
// 得到返回的数据流
Stream receiveStream = response.GetResponseStream();
// 如果有压缩,则进行解压
if (response.ContentEncoding.ToLower().Contains("gzip")) {
receiveStream = new GZipStream(receiveStream, CompressionMode.Decompress);
}
// 得到返回的字符串
html = new StreamReader(receiveStream).ReadToEnd();
}
Console.WriteLine("{0}", html); return html;
} static void Main(string[] args) { doSend(); Console.ReadKey(); } } }
}
激光推送(ios,安卓)的更多相关文章
- iOS开发中怎么样使用激光推送
1.注册激光推送的账号 ----> 创建应用 2.上传推送测试和发布的p12文件 注意密码的填写 3.下载sdk并拖进工程里 4.在build setting 搜索search 把路径改一 ...
- react-native android 和ios 集成 jpush-react-native 激光推送
安装 $ npm install jpush-react-native --save # jpush-react-native 版本以后需要同时安装 jcore-react-native $ npm ...
- 阿里云移动推送 ios项目添加SDK步骤
添加阿里云Pods仓库和各产品SDK Pod依赖,配置步骤如下: 1. CocoaPods集成添加阿里云Pods仓库,Podfile添加: source 'https://github.com/ali ...
- 1.NSNotification|远程通知|本地通知|激光推送
1. 通知在iOS中应用非常广泛,合理的应用通知可以减少冗余代码,使我们的代码层次结构变了更加的清晰明了,利于程序猿读写.它主要分为不可见通知可见通知两种: 1.1 不可见通知,主要是有系统发出的 ...
- 推送 iOS 10
1:APNs通知与应用内消息对比 极光文档上面是这么写的 后来更直接的说法是: 2:下面是介绍app不同状态下面接受到通知调用的方法: // iOS 10 Support,这个是程序在前台接受到通知是 ...
- 【转载自友盟消息推送iOS文档】在appDelegate中注册推送
1.2 基本功能集成指南 提示 请先在友盟的消息推送管理后台中创建App,获得AppKey和AppSecret 导入SDK 下载 UMessage_Sdk_All_x.x.x.zip并解压缩 导入 ...
- 百度云推送----iOS
前言 记录一下这几天学习的百度推送,觉得这个东西弄的还挺糟心的,好多注意的地方 正文 1.先申请一个百度开发者账号 http://push.baidu.com/fc 2.创建一个新应用,并应用配置 3 ...
- 远程推送-----iOS
前言 说一下我了解的推送 正文 APNs--------Apple Push Notification service 1 远程推送的大概流程及其原理 我们的设备联网时(无论是蜂窝联网还是Wi-Fi联 ...
- 极光推送iOS SDK教程
iOS SDK 调试指南 iOS 调试思维导图 2 确认证书 请到"应用详情页面"确认证书可用性: 3 开发环境测试 在对 JPush iOS 开发环境进行测试前,请确保 3 个 ...
随机推荐
- Windows下Oracle 11g的安装
Windows下Oracle 11g的安装 Windows下Oracle 11g的安装: Windows:64位, Oracle 11g版本:win64_11gR2_database_1of2(安装包 ...
- windows 和linux 路径解析的区别
windows下使用的是“\”作为分隔符,而linux则反其道而行之使用"/"作为分隔符.所以在windows 环境中获取路径常见 C:\windows\system 的形式,而l ...
- docker 容器的启动方式
1.Docker 优势: .更高效利用系统资源:由于容器不需要进行硬件虚拟以及运行完整操作系统等额外开销,Docker 对系统资源的利用率更高.无论是应用执行速度.内存损耗或者文件存储速度,都要比传统 ...
- dataTables 插件学习整理
在项目中使用了dataTables 插件,学习整理一下. dataTables 的官方中文网站 http://www.datatables.club 引入文件: 所有的都要引入 jq文件 1. dat ...
- DELPHI中build和compile有什么区别?
Build编译全部与工程相关联的文件,可包括版本信息及工程中的预编译变量等:Compile只重新编译更改过的相关单元及文件,调试是Compile就可以了,若是发布,则Build为好 BUILD =C ...
- 图片的HTML
Code <center> <img style="border-radius: 0.3125em; box-shadow: 0 2px 4px 0 rgba(34,36, ...
- UOJ14 UER #1 DZY Loves Graph(最小生成树+并查集)
显然可以用可持久化并查集实现.考虑更简单的做法.如果没有撤销操作,用带撤销并查集暴力模拟即可,复杂度显然可以均摊.加上撤销操作,删除操作的复杂度不再能均摊,但注意到我们在删除时就可以知道他会不会被撤销 ...
- 「洛谷4197」「BZOJ3545」peak【线段树合并】
题目链接 [洛谷] [BZOJ]没有权限号嘤嘤嘤.题号:3545 题解 窝不会克鲁斯卡尔重构树怎么办??? 可以离线乱搞. 我们将所有的操作全都存下来. 为了解决小于等于\(x\)的操作,那么我们按照 ...
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 0: ordinal not in range(128)
- [debian]use ISO as debian apt source / 使用ISO文件作为apt源
准备文件: debian-9.8.0-amd64-DVD-1.iso debian-9.8.0-amd64-DVD-2.iso debian-9.8.0-amd64-DVD-3.iso 挂载: roo ...