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. Linux环境下将Oracle11g数据库模式由非归档模式(Noarchivelog)修改为自动归档模式(archivelog)

    1.查看Oracle当前版本 select * from v$version 如图所示: 2.切换到Oracle用户 su - oracle 如图所示: 3.进入sqlplus(此时尚未登录oracl ...

  2. eclipse导入maven项目,但无法编译的问题

    同事今天从git 导入项目到eclipse 后,发现项目所依赖的包找不到依赖,初步判定是maven的依赖没有导入项目中. 最终发现,在项目中的.classpath 文件加入以下代码即可解决问题. &l ...

  3. 类 Random

    什么是Random类 此类的实例用于生成伪随机数 Random使用步骤 查看类 java.util.Random :该类需要 import导入使后使用. 查看构造方法 public Random() ...

  4. jdk8中的stream

    https://www.ibm.com/developerworks/cn/java/j-lo-java8streamapi/ Java 8 中的 Streams API 详解 Streams 的背景 ...

  5. Java规则之条件语句中做空判断时使用||和&&常犯的错误

    错误代码示例: public String bar(String string) { //error 1 if (string!=null || !string.equals("" ...

  6. Python_自定义递归的最大深度

    自定义递归的最大深度 python默认的最大递归深度为998,在有些情况下是不够用,需要我们自行设置.设置方式如下: import sys sys.setrecursionlimit(num) # n ...

  7. Jmeter二次开发代码(2)

    /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreem ...

  8. 目录树生成工具treer

    安装方法 $ npm install treer -g 生成结构 $ treer Desktop├─.DS_Store├─.localized├─dir2 | ├─file3 | └file4├─di ...

  9. 网络流学习(转载自ssw 的博客)

    众所周知,网络流是探究网络上运输的一种图论分支.但是大多数人在第一次接触这个题时都有些畏惧感(比如说我),大佬可以自信跳过.. 本文包括: 1.网络流的概念及基本性质 2.略谈 Edmonds-Kar ...

  10. Oracle 给予访问其他用户包的权限

    grant execute on apps.SPM_CON_INVOICE_INF_PKG to diq; grant  DEBUG on apps.SPM_CON_INVOICE_INF_PKG t ...