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,安卓)的更多相关文章

  1. iOS开发中怎么样使用激光推送

    1.注册激光推送的账号 ----> 创建应用 2.上传推送测试和发布的p12文件  注意密码的填写 3.下载sdk并拖进工程里 4.在build setting 搜索search   把路径改一 ...

  2. react-native android 和ios 集成 jpush-react-native 激光推送

    安装 $ npm install jpush-react-native --save # jpush-react-native 版本以后需要同时安装 jcore-react-native $ npm ...

  3. 阿里云移动推送 ios项目添加SDK步骤

    添加阿里云Pods仓库和各产品SDK Pod依赖,配置步骤如下: 1. CocoaPods集成添加阿里云Pods仓库,Podfile添加: source 'https://github.com/ali ...

  4. 1.NSNotification|远程通知|本地通知|激光推送

    1.   通知在iOS中应用非常广泛,合理的应用通知可以减少冗余代码,使我们的代码层次结构变了更加的清晰明了,利于程序猿读写.它主要分为不可见通知可见通知两种: 1.1 不可见通知,主要是有系统发出的 ...

  5. 推送 iOS 10

    1:APNs通知与应用内消息对比 极光文档上面是这么写的 后来更直接的说法是: 2:下面是介绍app不同状态下面接受到通知调用的方法: // iOS 10 Support,这个是程序在前台接受到通知是 ...

  6. 【转载自友盟消息推送iOS文档】在appDelegate中注册推送

    1.2   基本功能集成指南 提示 请先在友盟的消息推送管理后台中创建App,获得AppKey和AppSecret 导入SDK 下载 UMessage_Sdk_All_x.x.x.zip并解压缩 导入 ...

  7. 百度云推送----iOS

    前言 记录一下这几天学习的百度推送,觉得这个东西弄的还挺糟心的,好多注意的地方 正文 1.先申请一个百度开发者账号 http://push.baidu.com/fc 2.创建一个新应用,并应用配置 3 ...

  8. 远程推送-----iOS

    前言 说一下我了解的推送 正文 APNs--------Apple Push Notification service 1 远程推送的大概流程及其原理 我们的设备联网时(无论是蜂窝联网还是Wi-Fi联 ...

  9. 极光推送iOS SDK教程

    iOS SDK 调试指南 iOS 调试思维导图 2 确认证书 请到"应用详情页面"确认证书可用性: 3 开发环境测试 在对  JPush iOS 开发环境进行测试前,请确保 3 个 ...

随机推荐

  1. R语言学习——数据合并及绘制密度分布曲线图

    setwd("E:/08_cooperation/07_X-lab/06-Crosstalk/Aadapter_primer")# 读取lane01.txt,并对其按列进行相加处理 ...

  2. golang web实战之二(iris)

    之前写了一篇为:golang web实战之一(beego,mvc postgresql) 听说iris更好: 1.  iris hello world package main import &quo ...

  3. css display和vertical-align 属性

    display 定义和用法 display 属性规定元素应该生成的框的类型. 实例 <html> <head> <style type="text/css&qu ...

  4. CentOS7.x搭建时间同步服务器

    关于chrony Chrony是一个开源的自由软件,像CentOS7或基于RHEL 7操作系统,已经是默认服务,默认配置文件在 /etc/chrony.conf 它能保持系统时间与时间服务器(NTP) ...

  5. 【原创】从Rest到Graphql

    引言 开局两张图,内容全靠编- ok,如图所示,我在去年曾经写过一篇文章<闲侃前后端分离的必要性>.嗯,我知道肯定很多人没看过.所以我做一个总结,其实啰里八嗦了一篇文章,就是想说一下现在的 ...

  6. django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'. Did you install mysqlclient or MySQL-python?

    Error msg: Unhandled exception in thread started by <function check_errors.<locals>.wrapper ...

  7. npm包--rimraf

    含义 rimraf 包的作用:以包的形式包装rm -rf命令,用来删除文件和文件夹的,不管文件夹是否为空,都可删除. 安装 npm install rimraf --save-dev 使用 const ...

  8. 关于ES6的module的循环加载

    今天写js时,碰到了一个模块循环加载的错误,下面时例子: // testa.mjs import testb from './testb.mjs'; const {b} = testb; const ...

  9. Java的基本类型和包装类型

    测试的JDK版本:java version "1.7.0_79".Java的9中基本类型:void.char.boolean.byte.short.int.long.float.d ...

  10. MySQL select into outfile 和 load data infile数据跨库转移

    select into outfile用法 SELECT ... FROM TABLE_A INTO OUTFILE "/path/to/file" FIELDS TERMINAT ...