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); / ...
随机推荐
- NPOI创建doc
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- SQL Cursor 基本用法[用两次FETCH NEXT FROM INTO语句?]
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> ...
- 品味性能之道<三>:方法论
自顶向下的性能优化方法论 系统优化是包括系统设计.开发.产品上线.平台优化的全过程,不同阶段的优化工作对全系统所带来的效益是不同的.理想的性能优化论应该采用自顶向下的优化方法,即在项目设计.开发和上线 ...
- mstsc本地驱动器
mstsc 可以把本地驱动器 挂载到服务器上
- [ Laravel 5.5 文档 ] 底层原理 —— 一次 Laravel 请求的生命周期
Posted on 2018年3月5日 by 学院君 简介 当我们使用现实世界中的任何工具时,如果理解了该工具的工作原理,那么用起来就会得心应手,应用开发也是如此.当你理解了开发工具如何工作,用起 ...
- jQuery DataTables插件分页允许输入页码跳转
背景说明 项目中使用jQuery DataTables插件来实现分页表格,但是默认的分页样式不能输入页码进行跳转,在页数非常多的时候使用很不方便,最主要的还是没有达到产品部门的设计要求,所以我需要寻找 ...
- 2018.08.16 洛谷P2029 跳舞(线性dp)
传送门 简单的线性dp" role="presentation" style="position: relative;">dpdp. 直接推一推 ...
- 2018.08.04 spoj TTM to the moon(主席树)
spoj传送门 vjudge传送门 主席树板子题. 支持历史版本的区间和,区间和,区间修改和时光倒流. 其中新奇一点的也只有区间修改了,这个东西直接标记永久化就行了. 如果想下传标记的话也行,需要在p ...
- Django入门与实践 1-16章总结
注意事项:随时备份.随时记录.从宏观到微观 不闻不若闻之,闻之不若见之,见之不若知之,知之不若行之:学至于行之止矣 安装 Python 3.6.2 pip install django==1.11.4 ...
- Wifi小车资料
下位机代码 #include <avr/wdt.h> #include <SoftwareSerial.h> #include <EEPROM.h> //设置系统启 ...