下载个推SDK,找到这两个dll直接引用。

using引用

using com.gexin.rp.sdk.dto;
using com.igetui.api.openservice;
using com.igetui.api.openservice.igetui;
using com.igetui.api.openservice.igetui.template;
using com.igetui.api.openservice.igetui.template.notify;
using com.igetui.api.openservice.payload;

两种方案获取到这些参数。

public const string HOST = "http://sdk.open.api.igexin.com/apiex.htm";
public const string APPID = "xxxxxxxxxxxxx";
public const string APPKEY = "xxxxxxxxxxxxx";
public const string AppSecret = "xxxxxxxxxxxxx";
public const string MASTERSECRET = "xxxxxxxxxxxxx";

1,使用unipush   https://dev.dcloud.net.cn/uni/push  在unipush里面申请一个帐号,开通推送就能得到这些参数。

2,去个推注册并且配置相关参数

说明:UniPush由DCloud与个推联合打造。AppSecret和MasterSecret由个推保存,DCloud并不保存。个推是A股上市公司,开发者可放心使用UniPush业务

unipush并不是专门为uniapp所使用,可以单独使用unipush功能,其相关配置和操作页面个人感觉比个推的好用。

透传页面使用,相关参数说明一目了然。

1.1配置 推送需要2步,配置应用平台。

1.2 配置安卓厂商通道

 

2 推送方法

2.1推送单个用户
        /// <summary>
/// 推送单个用户
/// </summary>
/// <param name="title">标题 例如 迪信通 抢购会</param>
/// <param name="content">内容 例如 华为Mate30 5G抢购</param>
/// <param name="url">APP跳转地址 商品单页 活动页 或者其它页面</param>
/// <param name="cid">数据库pushclientid字段</param>
/// <returns>推送结果</returns>
public static string PushMessageToSingle(string title, string content, string url, string cid)
{
IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);
TransmissionTemplate template = TransmissionTemplateAndroidiOS(title, content, url);
//单推消息模型
SingleMessage message = new SingleMessage();
//当用户不在线 是否离线存储
message.IsOffline = true;
//离线有效时间
message.OfflineExpireTime = * * ;
message.Data = template;
//当前网络 1wifi 2-234G 0不限制
message.PushNetWorkType = ;
com.igetui.api.openservice.igetui.Target target = new
com.igetui.api.openservice.igetui.Target(); target.appId = APPID;
target.clientId = cid; String pushResult = push.pushMessageToSingle(message, target); return pushResult;
}

2.2 推送一批用户

        /// <summary>
/// 推送一批用户
/// </summary>
/// <param name="title">标题 例如 抢购会</param>
/// <param name="content">内容 例如 华为Mate30 5G抢购 </param>
/// <param name="url">APP跳转地址 商品单页 活动页 或者其它页面</param>
/// <param name="cids">数据库pushclientid字段集合</param>
/// <returns>推送结果</returns>
public static string pushMessageToList(string title, string content, string url, string[] cids)
{
IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);
ListMessage message = new ListMessage();
NotificationTemplate template = NotificationTemplateAndroidiOS(title, content, url);
message.IsOffline = true;
message.OfflineExpireTime = * * ;
message.Data = template;
message.PushNetWorkType = ;
List<com.igetui.api.openservice.igetui.Target> targetList = new
List<com.igetui.api.openservice.igetui.Target>(); for (int i = ; i < cids.Length; i++)
{
com.igetui.api.openservice.igetui.Target target1 = new
com.igetui.api.openservice.igetui.Target();
target1.appId = APPID;
target1.clientId = cids[i];
targetList.Add(target1);
}
String contentId = push.getContentId(message);
String pushResult = push.pushMessageToList(contentId, targetList);
return pushResult;
}

2.3 根据条件推送到某些条件用户

        /// <summary>
/// 根据条件推送到某些条件用户
/// </summary>
/// <param name="title">标题 例如 抢购会</param>
/// <param name="content">内容 例如 华为Mate30 5G抢购</param>
/// <param name="url">APP跳转地址 商品单页 活动页 或者其它页面</param>
/// <param name="provinces">省份s 北京_上海_河南 默认不传</param>
/// <param name="platform">ANDROID IOS ALL 3种值 默认ALL不传</param>
/// <returns>推送结果</returns>
public static string pushMessageToApp(string title, string content, string url, string provinces = "", string platform = "ALL")
{
IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);
AppMessage message = new AppMessage();
message.Speed = ;
TransmissionTemplate template = TransmissionTemplateAndroidiOS(title, content, url);
message.IsOffline = true;
message.OfflineExpireTime = * * ;
message.Data = template;
message.PushNetWorkType = ;
List<String> appIdList = new List<string>();
appIdList.Add(APPID);
//手机操作系统类型
List<String> phoneTypeList = new List<string>();
if (platform == "ALL")
{
phoneTypeList.Add("ANDROID");
phoneTypeList.Add("IOS");
}
else if (platform == "ANDROID")
{
phoneTypeList.Add("ANDROID");
}
else if (platform == "IOS")
{
phoneTypeList.Add("IOS");
} //地址
List<String> provinceList = new List<string>(); if (provinces.IsNotNullOrEmpty())
{
string[] provincesList = provinces.Split(new[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = ; i < provincesList.Length; i++)
{
provinceList.Add(provincesList[i]);
}
} //标签
List<String> tagList = new List<string>(); message.AppIdList = appIdList;
message.PhoneTypeList = phoneTypeList;
message.ProvinceList = provinceList;
message.TagList = tagList; String pushResult = push.pushMessageToApp(message);
return pushResult;
}

3.1

模版一
        /// <summary>
/// 模版一
/// </summary>
/// <param name="title">标题</param>
/// <param name="content">内容</param>
/// <param name="url">链接 APP中要跳转的页面</param>
/// <returns></returns>
public static NotificationTemplate NotificationTemplateAndroidiOS(string title, string content, string url)
{
NotificationTemplate template = new NotificationTemplate();
template.AppId = APPID;
template.AppKey = APPKEY;
template.Title = title;
template.Text = content;
template.Logo = "";
template.LogoURL = "";
template.TransmissionType = ;
template.TransmissionContent = "{\"url\":\"" + url + "\"}";
template.IsRing = true;
template.IsVibrate = true;
template.IsClearable = true; //安卓透传厂商通道
Notify notify = new Notify();
notify.Content = title;
notify.Title = content;
string newUrl = "{\"url\":\"" + url + "\"}";
notify.Intent = $"intent:#Intent;action=android.intent.action.oppopush;launchFlags=0x14000000;component=您的安卓包名/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title={title};S.content={content};S.payload={newUrl};end";
notify.Type = NotifyInfo.Types.Type._intent;
template.set3rdNotifyInfo(notify); //苹果透传配置
APNPayload apnpayload = new APNPayload();
DictionaryAlertMsg alertMsg = new DictionaryAlertMsg();
// IOS 的body用这个
alertMsg.Body = content;
alertMsg.ActionLocKey = "ActionLocKey";
alertMsg.LocKey = "LocKey";
alertMsg.addLocArg("LocArg");
alertMsg.LaunchImage = "LaunchImage";
//iOS8.2支持字段
alertMsg.Title = title;
alertMsg.TitleLocKey = "TitleLocKey";
alertMsg.addTitleLocArg("TitleLocArg"); apnpayload.AlertMsg = alertMsg;
//apnpayload.Badge = 0 +1;
apnpayload.ContentAvailable = ;
apnpayload.Sound = "default";
apnpayload.addCustomMsg("payload", "{\"url\":\"" + url + "\"}"); template.setAPNInfo(apnpayload); string begin = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string end = DateTime.Now.AddDays().ToString("yyyy-MM-dd HH:mm:ss");
template.setDuration(begin, end);
return template;
}

3.2

        /// <summary>
/// 模版二
/// </summary>
/// <param name="title">标题</param>
/// <param name="content">内容</param>
/// <param name="url">链接</param>
/// <returns></returns>
public static TransmissionTemplate TransmissionTemplateAndroidiOS(string title, string content, string url)
{
TransmissionTemplate template = new TransmissionTemplate();
template.AppId = APPID;
template.AppKey = APPKEY;
//应用启动类型,1:强制应用启动 2:等待应用启动
template.TransmissionType = ;
//透传内容
template.TransmissionContent = "{\"url\":\"" + url + "\"}"; //安卓透传厂商通道
Notify notify = new Notify();
notify.Content = title;
notify.Title = content;
string newUrl = "{\"url\":\"" + url + "\"}";
notify.Intent = $"intent:#Intent;action=android.intent.action.oppopush;launchFlags=0x14000000;component=您的安卓包名/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title={title};S.content={content};S.payload={newUrl};end";
notify.Type = NotifyInfo.Types.Type._intent;
template.set3rdNotifyInfo(notify); //苹果透传配置
APNPayload apnpayload = new APNPayload();
DictionaryAlertMsg alertMsg = new DictionaryAlertMsg();
// IOS 的body用这个
alertMsg.Body = content;
alertMsg.ActionLocKey = "ActionLocKey";
alertMsg.LocKey = "LocKey";
alertMsg.addLocArg("LocArg");
alertMsg.LaunchImage = "LaunchImage";
//iOS8.2支持字段
alertMsg.Title = title;
alertMsg.TitleLocKey = "TitleLocKey";
alertMsg.addTitleLocArg("TitleLocArg"); apnpayload.AlertMsg = alertMsg;
//apnpayload.Badge = 0 +1;
apnpayload.ContentAvailable = ;
apnpayload.Sound = "default";
apnpayload.addCustomMsg("payload", "{\"url\":\"" + url + "\"}"); template.setAPNInfo(apnpayload); string begin = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string end = DateTime.Now.AddDays().ToString("yyyy-MM-dd HH:mm:ss");
template.setDuration(begin, end); return template;
}

4.调用

        //调用案例
//string result = UniPush.PushMessageToSingle("通知", "华为Mate30 5G抢购", "/pages/product/product?pid=9871&cid=288", "cid", "20200221");
//string[] cids = { "cid" };
//string result = UniPush.pushMessageToList("通知", "华为抢购", "/pages/product/product?pid=10019&cid=288", cids, "20200221");
//string result = UniPush.pushMessageToApp("通知", "华为Mate30 5G抢购", "/pages/product/product?pid=9871&cid=288", "", "ALL");

5,测试结果

1,测试单推安卓APP。在线状态:无须透传秒到。 离线状态:看心情1秒-15分钟我都碰到过。

2,测试单推iOS APP。在线状态:无须透传秒到。 离线状态:APNs基本做到1-5秒到。

3,测试推集合,情况和1、2相同。

4,测试推全部,1的情况好一些、2的情况不变。

6,总结

国内安卓推送是一个混乱的市场,每个厂商的透传通道推送的效率各不相同,上架也比较多繁琐。iOS推送上架这一套服务很好用。

7,uniapp App.vue相关代码 直接写在onLaunch

       //监听click事件,用户从消息中心点击触发的
plus.push.addEventListener(
'click',
function(msg) {
//根据payload传递过来的数据,打开一个详情
var payload = msg.payload;
if (payload) {
// payload 按照规范是 Object,但实际推送过来有可能是 String,需要多一步处理;
if (typeof payload === 'string') {
payload = JSON.parse(payload);
}
if (typeof payload === 'object') {
if (payload.url) {
setTimeout(function(res) {
uni.navigateTo({
url: payload.url
});
}, );
}
}
}
},
false
);
        //监听receive事件
plus.push.addEventListener(
'receive',
function(msg) {
if (plus.os.name != 'iOS') {
plus.push.createMessage(msg.title, msg.payload);
}
//根据payload传递过来的数据,打开一个详情
var payload;
if (msg.payload) {
//如透传消息不符合格式,则“payload”属性为string类型
//这里的示例以json字符串去解析,实际上也可以做字符串匹配
if (typeof msg.payload == 'string') {
try {
payload = JSON.parse(msg.payload);
} catch (error) {}
} else if (typeof msg.payload == 'object') {
//iOS应用正处于前台运行时收到推送,也触发receive事件,此时payload为json对象
plus.push.createMessage(msg.title, msg.content);
}
}
},
false
);

C#个推SDK推送安卓+iOS的更多相关文章

  1. 李洪强iOS之集成极光推送一iOS SDK概述

    李洪强iOS之集成极光推送一iOS SDK概述 JPush iOS 从上图可以看出,JPush iOS Push 包括 2 个部分,APNs 推送(代理),与 JPush 应用内消息. 红色部分是 A ...

  2. 李洪强iOS之集成极光推送三iOS集成指南

    李洪强iOS之集成极光推送三iOS集成指南 SDK说明 适用版本 本文匹配的 SDK版本:r2.1.5 以后.查看最近更新了解最新的SDK更新情况.使用Xcode 6及以上版本可以使用新版Push S ...

  3. 李洪强iOS之集成极光推送二iOS 证书 设置指南

    李洪强iOS之集成极光推送二iOS 证书 设置指南 创建应用程序ID 登陆 iOS Dev Center 选择进入iOS Provisioning Portal. 在 iOS Provisioning ...

  4. 私有Pods封装个推SDK功能(解决方案)

    一:运用场景 公司中同时有好几个APP在开发,而且每个APP都有使用到集成个推SDK来处理消息的功能,以前的做法是每个APP都去集成并在AppDelegate处理一些SDK的代码,包含个推基础配置.消 ...

  5. SDK接入(3)之iOS内支付(In-App Purchase)接入

    SDK接入(3)之iOS内支付(In-App Purchase)接入 继整理了Android平台的SDK接入过程.再来分享下iOS平台的内支付(In-App Purchase)接入,作为笔者在游戏开发 ...

  6. .net 安卓IOS跨平台des加解密双向的(可以互相加解密)

    #region 跨平台加解密(c# 安卓 IOS) // public static string sKey = "12345678"; // /// // /// 解密 // / ...

  7. 关于 调用 JNI JAR 的说明和注意事项,调用第三方 JAR SDK 和 翻译 安卓 JAVA 代码 的说明 V2015.6.10

    关于 调用 JNI JAR 的说明和注意事项,调用第三方 JAR SDK 和 翻译 安卓 JAVA 代码 的说明 V2015.6.10 转载请标明出处,否则死全家.选择[复制链接]即可得到出处. (* ...

  8. 安卓ios和angularjs相互调用解决首次调用ios传递标题失败的问题

    1.angular 调用客户端方法放在 try catch中 try { js_invoke.showShareDialog(angular.toJson(obj));  // 在这里放客户端的方法即 ...

  9. 安卓ios各版本及分辨率占比

    Google Play 安装统计数据 只有安卓的 https://developer.android.com/about/dashboards/index.html?hl=zh-cn 腾讯移动分析 安 ...

随机推荐

  1. [组合数学][多项式][拉格朗日插值]count

    源自 ditoly 大爷的 FJ 省队集训课件 Statement 有 \(m\) 个正整数变量,求有多少种取值方案 使得所有变量的和不超过 \(S\) 并且前 \(n\) 个变量的值都不超过 \(t ...

  2. 【java面试】网络通信篇

    1.说一下HTTP协议 HTTP协议是超文本传输协议,属于应用层协议,规定了客户端与服务端传输数据的格式:它是无状态的,对于前面传送过的信息没有记录:请求方式有GET,POST,HEAD,PUT,DE ...

  3. linux 网络有关的5个命令

    1:ifconfig 2:ifdown & ifup 3:route 4:traceroute 5:iptables 6

  4. 看透Spring MVC:源代码分析与实践 (Web开发技术丛书)

    第一篇 网站基础知识 第1章 网站架构及其演变过程2 1.1 软件的三大类型2 1.2 基础的结构并不简单3 1.3 架构演变的起点5 1.4 海量数据的解决方案5 1.4.1 缓存和页面静态化5 1 ...

  5. Frameworks.Entity.Core 1

    CommonEnums 1系统模块BlockType 2证件类型IDType 3在线支付类型OnLineType 4操作权限,支持位移运算OperatorAuthority 5订单状态: 1000-待 ...

  6. 个人第三次作业——结对编程 (姜玖林&于丁)

    博客要求 Github项目地址:https://github.com/zhibihuayue/PairProgramming 作业地址 : https://www.cnblogs.com/cheris ...

  7. [计算几何+图论]doge

    题意 在平面直角坐标系上,你有一只doge在原点处.doge被绳子拴住了,绳子不会打结,没有弹性(但很柔软),并且长度为L.平面上有一些目标,因此你的doge会按照顺序去捡起它们,但是doge只能走直 ...

  8. oracle问题之数据库恢复(三)

    可能很多人在做数据库恢复时,都遇到过如下错误: SQL> recover database; ORA: recovery session canceled due to errors ORA: ...

  9. 死磕mysql(6)

    再写数据库作业的时候,发现了一个问题,如果存在主键外键的约束,数据就删不掉 --set foreign_key_checks=0; 关掉外键约束 用好了再打开 --set foreign_key_ch ...

  10. mybatis缓存,从一个“灵异”事件说起

    刚准备下班走人,被一开发同事叫住,让帮看一个比较奇怪的问题:Mybatis同一个Mapper接口的查询方法,第一次返回与第二次返回结果不一样,百思不得其解! 问题 Talk is cheap. Sho ...