下载个推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. c#数字图像处理(十)图像缩放

    图像几何变换(缩放.旋转)中的常用的插值算法 在图像几何变换的过程中,常用的插值方法有最邻近插值(近邻取样法).双线性内插值和三次卷积法. 最邻近插值: 这是一种最为简单的插值方法,在图像中最小的单位 ...

  2. MyBatis-Plus学习笔记(1):环境搭建以及基本的CRUD操作

    MyBatis-Plus是一个 MyBatis的增强工具,在 MyBatis 的基础上只做增强不做改变,使用MyBatis-Plus时,不会影响原来Mybatis方式的使用. SpringBoot+M ...

  3. applyColorMap 在OpenCV中对灰度图进行颜色映射,实现数据的色彩化

    什么是色彩映射: 说直白点就是将各种数据映射成颜色信息,例如:温度,高度,压力,密度,湿度,城市拥堵数据等等 色彩化后更加直观表达 在OpenCV里可以使用 Mat im_gray = imread( ...

  4. jdk for centos7

    https://www.cnblogs.com/chy123/p/6750351.html

  5. centos7+ docker 实践部署docker及配置direct_lvm

    转载于博客园:http://www.cnblogs.com/Andrew-XinFei/p/6245330.html 前言 Docker现在在后端是那么的火热..尤其当笔者了解了docker是什么.能 ...

  6. SonarQube代码管理

    一 搭建过程不详细说 二 配合jenkins使用,jenkins搭建过程这里不详细说 三 jenkins项目配置,需要安装sonarqube-jenkins插件 sonar.projectKey=a6 ...

  7. Spring AOP源码分析--代理方式的选择

    能坚持别人不能坚持的,才能拥有别人未曾拥有的.关注编程大道公众号,让我们一同坚持心中所想,一起成长!! 年前写了一个面试突击系列的文章,目前只有redis相关的.在这个系列里,我整理了一些面试题与大家 ...

  8. <背包>solution_CF366C_Dima and Salad

    Dima and Salad Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. T ...

  9. java编写杨辉三角

    import java.util.Scanner; /* *计算杨辉三角: * 规律:两边都是1 * 从第三行开始,上一行的前一个元素+与其并排的元素等于下面的元素 * 例如: * 1 * 11 * ...

  10. 使用vscode进行远程开发

    1.前置条件,安装SSH客户端.OpenSSH或者Git两者任选其一即可,本文使用的是Git 2.安装 Remote Development 扩展包 官方地址为:https://marketplace ...