激光推送(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 个 ...
随机推荐
- drools规则引擎与kie-wb和kie-server远程执行规则(7.18.0.Final)
最近研究了一下规则引擎drools. 这篇博客带你搭建并运行一个可在线编辑,在线打包,远程执行的规则引擎(drools) 本篇博客同时参考https://blog.csdn.net/chinrui/a ...
- vue项目报错webpackJsonp is not defined
在vue单页面应用中,我们大概都会使用CommonsChunkPlugin这个插件. 传送门 CommonsChunkPlugin 但是在项目经过本地测试没有任何问题,打包上线后却会报错 webpac ...
- Linux新手随手笔记1.3
shell脚本的编写(划重点) #!/bin/bash 脚本的声明信息 #sjsjdhsjdhh 脚本的注释 ls -l ...
- 第一次java作业
学习了c语言半个学期,好像刚开始并不担心Java,因为Java也是类同于C语言的一种语言,可是Java学到现在也将近一个月,在我脑子里现在却还没有一个框架,有点着急了.
- 【原创】小说:我是一条DQL
SQL执行流程图如下 本文改编自<高性能Mysql>,烟哥用小说的形式来讲这个内容. 序章 自我介绍 我是一条sql,就是一条长长的字符串,不要问我长什么样,因为我比较傲娇. 额~~不是我 ...
- netcore开发windows普通服务(非Web)并一键发布到服务器
如何开发并一键发布WindowsService项目(netcore普通项目) netcore下开发windows服务如果是web项目的话,由于aspnetcore本身是支持的,把默认的host.Run ...
- 关于Math.round()方法
先上结论: 1.参数的小数点后第一位<5,运算结果为参数整数部分. 2.参数的小数点后第一位>5,运算结果为参数整数部分绝对值+1,符号(+ or -)不变. 3.参数的小数点后第一位=5 ...
- 说说我心中的Linux系统
我不知道在阅读此篇文章的你,是一个什么样的人,或许你只是偶然看到此篇文章的路人,或许是对linux有兴趣但没接触过linux的圈外人,或许是已经入行没多久的菜鸟,或许是喜欢linux却学习不下去预备放 ...
- iOS CATransition 自定义转场动画
https://www.jianshu.com/p/39c051cfe7dd CATransition CATransition 是CAAnimation的子类(如下图所示),用于控制器和控制器之间的 ...
- webmagic爬虫框架抽取元素