hbuilder APP服务器端(C#)推送
实现推送有多种方法和技术手段,我这边是使用三方“个推”去实现对特定用户的推送。我自己是关联业务,对下一步任务代办人进行消息通知。
1 、个推账号申请和配置
1.1、IOS需要推送证书 参考网址:http://www.applicationloader.net/blog/zh/397.html
1.2 、"Hbuilder”“ 个推”配置参考:http://ask.dcloud.net.cn/article/34
2、代码处理
2.1 C#后端
private static String HOST = "http://sdk.open.api.igexin.com/apiex.htm";
//https的域名
//private static String HOST = "https://api.getui.com/apiex.htm";
private static String APPID = ConfigurationManager.AppSettings["TSAPPID"].ToString();//"djNkkiQUDN7fmNwS0Lhr1";
private static String APPKEY = ConfigurationManager.AppSettings["TSAPPKEY"].ToString();//"FMxsRBtmx1As7wHtaPeb43";
private static String MASTERSECRET = ConfigurationManager.AppSettings["TSMASTERSECRET"].ToString();//"3KKqkvwLzW8zrLmCvNC0S7"; public static void GetClientid(string code, string title, string text)
{
WriteLog("*****************************APP信息推送*****************************************");
WriteLog("用户:" + code);
WriteLog(title + "内容:" + text); using (var db = new DbBase())
{
string sql = string.Format("select top 1 code,clientid,billDate,company from SYSTEM_PUSH_ALIAS where code='{0}' order by billDate desc", code); var dt = RepositoryBase.ExecuteDataTable(db, sql);
if (dt.Rows.Count > )
{
foreach (DataRow item in dt.Rows)
{
PushMessage(item["clientid"].ToString(), title, text);
}
}
else
{ WriteLog("用户:" + code + " 无对应clientid");
}
}
} public static object PushMessage(string CLIENTID, string title, string text)
{
return JObject.Parse(PushMessageToSingle(CLIENTID, title, text));
} /// <summary>
/// 用户对于的 推送CLIENTID
/// </summary>
/// <param name="CLIENTID"></param>
private static string PushMessageToSingle(string CLIENTID, string title, string text)
{ IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET); TransmissionTemplate template = TransmissionTemplateDemo(title, text); // 单推消息模型
SingleMessage message = new SingleMessage();
message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选
message.OfflineExpireTime = * * ; // 离线有效时间,单位为毫秒,可选
message.Data = template;
//判断是否客户端是否wifi环境下推送,2为4G/3G/2G,1为在WIFI环境下,0为不限制环境
message.PushNetWorkType = ; com.igetui.api.openservice.igetui.Target target = new com.igetui.api.openservice.igetui.Target();
target.appId = APPID;
target.clientId = CLIENTID;
//target.alias = ALIAS;
try
{
String pushResult = push.pushMessageToSingle(message, target); WriteLog("-----------------------------------------------");
WriteLog("----------------服务端返回结果:" + pushResult);
return pushResult;
}
catch (RequestException e)
{
String requestId = e.RequestId;
//发送失败后的重发
String pushResult = push.pushMessageToSingle(message, target, requestId); WriteLog("-----------------------------------------------");
WriteLog("----------------服务端返回结果:" + pushResult);
return pushResult;
}
} //通知透传模板动作内容
public static NotificationTemplate NotificationTemplateDemo(string title, string text)
{ NotificationTemplate template = new NotificationTemplate();
template.AppId = APPID;
template.AppKey = APPKEY;
//通知栏标题
template.Title = title;
//通知栏内容
template.Text = text;
//通知栏显示本地图片
template.Logo = "";
//通知栏显示网络图标
template.LogoURL = "";
//应用启动类型,1:强制应用启动 2:等待应用启动
template.TransmissionType = "";
//透传内容
template.TransmissionContent = text;
//接收到消息是否响铃,true:响铃 false:不响铃
template.IsRing = true;
//接收到消息是否震动,true:震动 false:不震动
template.IsVibrate = true;
//接收到消息是否可清除,true:可清除 false:不可清除
template.IsClearable = true; //APNPayload apnpayload = new APNPayload();
//SimpleAlertMsg alertMsg = new SimpleAlertMsg(text);
//apnpayload.AlertMsg = alertMsg;
//// apnpayload.Badge = 11;
//apnpayload.ContentAvailable = 1;
//apnpayload.addCustomMsg("payload", "payload"); //APN高级推送
APNPayload apnpayload = new APNPayload();
DictionaryAlertMsg alertMsg = new DictionaryAlertMsg();
alertMsg.Body = text;
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 = 10;
apnpayload.ContentAvailable = ;
//apnpayload.Category = "";
//apnpayload.Sound = "test1.wav";
apnpayload.addCustomMsg("payload", "payload"); template.setAPNInfo(apnpayload); template.setAPNInfo(apnpayload);
//设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟)
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;
} //透传模板动作内容
public static TransmissionTemplate TransmissionTemplateDemo(string title, string text)
{
TransmissionTemplate template = new TransmissionTemplate();
template.AppId = APPID;
template.AppKey = APPKEY;
//应用启动类型,1:强制应用启动 2:等待应用启动
template.TransmissionType = "";
//透传内容
template.TransmissionContent = "{\"title\":\"" + title + "\",\"content\":\"" + text + "\",\"payload\":\"payload\"}";
//设置通知定时展示时间,结束时间与开始时间相差需大于6分钟,消息推送后,客户端将在指定时间差内展示消息(误差6分钟)
//设置客户端展示时间 //iOS简单推送
APNPayload apnpayload = new APNPayload();
SimpleAlertMsg alertMsg = new SimpleAlertMsg(text);
apnpayload.AlertMsg = alertMsg;
// apnpayload.Badge = 11;
apnpayload.ContentAvailable = ;
//apnpayload.Category = "";
apnpayload.Sound = "default";
apnpayload.addCustomMsg("payload", "payload");
template.setAPNInfo(apnpayload);
//APN高级推送
//APNPayload apnpayload = new APNPayload();
//DictionaryAlertMsg alertMsg = new DictionaryAlertMsg();
//apnpayload.ContentAvailable = 1;
//alertMsg.Body = "您有订单需要审核";
//alertMsg.ActionLocKey = "ActionLocKey";
//alertMsg.LocKey = "LocKey";
//alertMsg.addLocArg("LocArg");
//alertMsg.LaunchImage = "LaunchImage";
//iOS8.2支持字段
//alertMsg.Title = "订单提醒";
//alertMsg.TitleLocKey = "TitleLocKey";
//alertMsg.addTitleLocArg("TitleLocArg"); 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;
} private static void WriteLog(string log)
{
CommonHelper.WriteLog(log, "_pushLog.txt");
}
2.2 hbuilder app端代码:
登录后必须给每个用户绑定一个“clientId”,此ID要存储在服务器。在服务器给APP推送消息的时候需要更加用户信息找到“clientId”:
ClientInfo =plus.push.getClientInfo();
mui.getJSON(Url,{code:user.code,cli:ClientInfo.clientid},function(json){ });
IOS 应用在前台的时候,在服务器推送消息APP端是没有提示的。需要在代码上做些处理。在登录后的第一个页面添加西门监听事件:
if (mui.os.ios) {
mui.plusReady(function(){
plus.push.addEventListener("receive", function( msg ) {
if (msg.payload !=null && msg.payload!="") {
plus.push.createMessage(msg.content)
}
}, false );
});
}
hbuilder APP服务器端(C#)推送的更多相关文章
- APP的消息推送(极光推送)
APP的消息推送,使用的第三方平台是极光推送 简单案例(以Thinkphp为例): 1.下载下载PHPSDK 2.把PHPSDK目录下的jpush-api-php-client-3.5.1\src\J ...
- 【SpringBoot】服务器端主动推送SSE技术讲解
=====================16.高级篇幅之SpringBoot2.0服务器端主动推送SSE技术讲解 ============================ 1.服务端推送常用技术介绍 ...
- springboot实现服务器端消息推送(websocket + sockjs + stomp)
服务器端推送技术在web开发中比较常用,可能早期很多人的解决方案是采用ajax向服务器轮询消息,这种方式的轮询频率不好控制,所以大大增加了服务器的压力,后来有了下面的方案:当客户端向服务器发送请求时, ...
- 服务器端实时推送技术之SseEmitter的用法
这是SpringMVC提供的一种技术,可以实现服务端向客户端实时推送数据.用法非常简单,只需要在Controller提供一个接口,创建并返回SseEmitter对象,发送数据可以在另一个接口调用其se ...
- android app 集成 信鸽推送
推送其实挺中意小米推送的,并经用户群占比还是比较大的,奈何拗不过php后端哥们的选型,就只好用信鸽推送了,期间接入过程中也是遇到不少问题,所以记录下来,以后如果还是用信鸽推送的话,估计看看以前的博客, ...
- springboot实现服务器端消息推送(H5原生支持)
随着互联网的发展,传统的HTTP协议已经很难满足Web应用日益复杂的需求了.近年来,随着HTML5的诞生,WebSocket协议被提出,它实现了浏览器与服务器的全双工通信,扩展了浏览器与服务端的通信功 ...
- SpringBoot2.x服务器端主动推送技术
一.服务端推送常用技术介绍 服务端主流推送技术:websocket.SSE等 1.客户端轮询:ajax定时拉取后台数据 js setInterval定时函数 + ajax异步加载 定时向服务 ...
- APP如何实现推送功能
一.推送功能的集成 (1)在Umeng开发者中心,申请新应用,开通推送功能.此时需要上传开发推送证书和生产推送证书的p12文件. 申请证书的流程如下: >>1 创建开发推送证书 >& ...
- App集成极光推送开发流程[关键步骤]
1.客户端集成SDK 1.1初始化 JPushInterface.setDebugMode(true); // 设置开启日志,发布时请关闭日志 JPushInterface.init(this); / ...
随机推荐
- windows下 Memcache cpu占用过高
分析应该是memcache的内存大小还是默认配置,已经满足不了当前的大数据量的需要了,大量的新缓存需要进入,同时大量的旧缓存又需要被淘汰出来,一进一出导致CPU占用过多. 进入注册表,找到:HKEY_ ...
- JavaScript 中的 NaN 和 isNaN
1.NaN NaN 即 Not a Number , 不是一个数字.那么 NaN 到底是什么呢? 在 JavaScript 中,整数和浮点数都统称为 Number 类型 .除此之外,Number 类型 ...
- DNA甲基化检测服务
DNA甲基化检测服务 DNA甲基化是最早发现的基因表观修饰方式之一,真核生物中的甲基化仅发生于胞嘧啶,即在DNA甲基化转移酶(DNMTs)的作用下使CpG二核苷酸5'-端的胞嘧啶转变为5'-甲基胞嘧啶 ...
- dir/
dos窗口输入dir命令是显示磁盘目录命令: addslashes()使用反斜线转义字符串: exec($command,$output,$return)执行一个外部程序 $command:要执行的命 ...
- httpclient之基本类
HttpHost类 主机类 主要属性有域名和端口. HttpRoute类 路由类 主要属性有targetHost(目标主要).proxyChain[]代理链 RouteTracker类 和H ...
- app怎么测试性能
性能测试一般来说 都是代码能力相对薄弱的测试人员 进阶的一个方向:但是当你成为一个真正的全栈人才的时候你就不得不学习代码: APP 或者安卓手机 或者iOS 一本测试他的性能的话都是采用:手机安装一 ...
- 【Linux】Memcached安装
Memcached概念 Memcached是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载. MemCache的工作流程如下:先检查客户端的请求数据是否在memcached中, ...
- 【Maven】Nexus配置和使用
Nexus安装 nexus安装,可以参照:[Maven]Nexus(Maven仓库私服)下载与安装 Nexus简单说明 用途:指定私服的中央地址.将自己的Maven项目指定到私服地址.从私服下载中央库 ...
- 2018.09.25 bzoj2286: [Sdoi2011]消耗战(虚树+树形dp)
传送门 又一道虚树入门题. 这个dp更简单啊. 直接记录每个点到1的距离,简单转移就行了. 代码: #include<bits/stdc++.h> #define N 250005 #de ...
- hdu-1179(匈牙利算法)
题目链接: 思路:找n个巫师和m个魔棒匹配的问题,匈牙利算法模板 匈牙利算法:https://blog.csdn.net/sunny_hun/article/details/80627351 #inc ...