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. 使用git提交代码到github,每次都要输入用户名和密码的解决方法

    自从使用git提交代码到github后,发现自己使用git的功力增长了不少,但也遇到不少问题.比如,使用git提交代码到github的时候,经常要求输入用户名和密码,类似这种: 网上有这么一种解决方法 ...

  2. IDEA导入项目jar包红线、依赖问题....

    一般遇到这种情况用以下两种方式解决....... 1.reimport包 2.清缓存重启 针对1方法: a.确实不缺包: 可以先注释掉pom文件中的jar包, 此时idea会提示import, 那就i ...

  3. java中String的final类原因

    public final class String implements java.io.Serializable, Comparable<String>, CharSequence { ...

  4. JS 设计模式四 -- 模块模式

    概念 模块模式的思路 就是 就是单例模式添加私有属性和私有方法,减少全局变量的使用. 简单的代码结构: var singleMode = (function(){ // 创建私有变量 var priv ...

  5. springboot整合Quartz实现定时任务

    1.maven依赖: <!--quartz--> <dependency> <groupId>org.quartz-scheduler</groupId> ...

  6. AOP - 2 实例(SpringBoot 注解方式)

    1.创建Spring Boot项目 创建一个Spring Boot 项目,然后pom中引入web 模块与AOP相关依赖. <dependency> <groupId>org.s ...

  7. Flutter获取点击元素的位置与大小

    使用 WidgetsBindingObserver获取 class CloseTap extends StatefulWidget { @override _CloseTapTapState crea ...

  8. git常用命令二、:git stash

    Git stash 储藏工作现场(当你不得不新建分支,或者切换分支,但是当前工作区的修改并不想提交) git stash Saved working directory and index state ...

  9. odoo10 addon开发流程

    odoo addon开发流程 创建一个addon(插件) 命令如下 python odoo-bin scaffold 插件名 路径 # 例如 python odoo-bin scaffold hh_t ...

  10. gulp 入门使用

      gulp 入门使用 使用场景 相信大家在传统的开发模式下 都是 html + css + js 然后静态文件不经过任何处理 部署到服务器,这样会有很多漏洞例如: 1.在网站上查看F12 就可以看到 ...