实现推送有多种方法和技术手段,我这边是使用三方“个推”去实现对特定用户的推送。我自己是关联业务,对下一步任务代办人进行消息通知。

 

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#)推送的更多相关文章

  1. APP的消息推送(极光推送)

    APP的消息推送,使用的第三方平台是极光推送 简单案例(以Thinkphp为例): 1.下载下载PHPSDK 2.把PHPSDK目录下的jpush-api-php-client-3.5.1\src\J ...

  2. 【SpringBoot】服务器端主动推送SSE技术讲解

    =====================16.高级篇幅之SpringBoot2.0服务器端主动推送SSE技术讲解 ============================ 1.服务端推送常用技术介绍 ...

  3. springboot实现服务器端消息推送(websocket + sockjs + stomp)

    服务器端推送技术在web开发中比较常用,可能早期很多人的解决方案是采用ajax向服务器轮询消息,这种方式的轮询频率不好控制,所以大大增加了服务器的压力,后来有了下面的方案:当客户端向服务器发送请求时, ...

  4. 服务器端实时推送技术之SseEmitter的用法

    这是SpringMVC提供的一种技术,可以实现服务端向客户端实时推送数据.用法非常简单,只需要在Controller提供一个接口,创建并返回SseEmitter对象,发送数据可以在另一个接口调用其se ...

  5. android app 集成 信鸽推送

    推送其实挺中意小米推送的,并经用户群占比还是比较大的,奈何拗不过php后端哥们的选型,就只好用信鸽推送了,期间接入过程中也是遇到不少问题,所以记录下来,以后如果还是用信鸽推送的话,估计看看以前的博客, ...

  6. springboot实现服务器端消息推送(H5原生支持)

    随着互联网的发展,传统的HTTP协议已经很难满足Web应用日益复杂的需求了.近年来,随着HTML5的诞生,WebSocket协议被提出,它实现了浏览器与服务器的全双工通信,扩展了浏览器与服务端的通信功 ...

  7. SpringBoot2.x服务器端主动推送技术

    一.服务端推送常用技术介绍 服务端主流推送技术:websocket.SSE等 1.客户端轮询:ajax定时拉取后台数据 js   setInterval定时函数  +  ajax异步加载  定时向服务 ...

  8. APP如何实现推送功能

    一.推送功能的集成 (1)在Umeng开发者中心,申请新应用,开通推送功能.此时需要上传开发推送证书和生产推送证书的p12文件. 申请证书的流程如下: >>1 创建开发推送证书 >& ...

  9. App集成极光推送开发流程[关键步骤]

    1.客户端集成SDK 1.1初始化 JPushInterface.setDebugMode(true); // 设置开启日志,发布时请关闭日志 JPushInterface.init(this); / ...

随机推荐

  1. css3自定义placeholder字体颜色

    ::-webkit-input-placeholder{color:#f00;} ::-moz-placeholder{color:#f00;} :-moz-placeholder{color:#f0 ...

  2. [leetcode]139. Word Break单词能否拆分

    Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine ...

  3. 3.滑雪-深搜&dp

    //Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道载一个区域中最长底滑 ...

  4. Linq select 语法

    文档:https://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b 1.可以对查询出来的结果做一些转换,下面的例子在数组中查找以"B&q ...

  5. JavaScript 中的 NaN 和 isNaN

    1.NaN NaN 即 Not a Number , 不是一个数字.那么 NaN 到底是什么呢? 在 JavaScript 中,整数和浮点数都统称为 Number 类型 .除此之外,Number 类型 ...

  6. 大乐透 Java随机码

    package suijishu; import java.util.Random; // TODO Auto-generated method stub public class Xuanqi { ...

  7. window安装设置

    https://jingyan.baidu.com/article/73c3ce28ed7d92e50243d96c.html

  8. org.apache.hadoop.ipc.RemoteException: java.io.IOException:XXXXXXXXXXX could only be replicated to 0 nodes, instead of 1

    原因:Configured Capacity也就是datanode 没用分配容量 [root@dev9106 bin]# ./hadoop dfsadmin -report Configured Ca ...

  9. 实现KbmMw web server 支持https

    在以前的文章里面介绍过kbmmw 做web server. 前几天红鱼儿非要我给他做一个支持https 的web server. 其实kbmmw 支持https 有好几种方法: 1. 使用isapi ...

  10. 2018.10.15 loj#6013. 「网络流 24 题」负载平衡(费用流)

    传送门 费用流sb题. 直接从sss向每个点连边,容量为现有物品量. 然后从ttt向每个点连边,容量为最后库存量. 由于两个点之间可以互相任意运送物品,因此相邻的直接连infinfinf的边就行了. ...