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); / ...
随机推荐
- rubber
rubber - 必应词典 美['rʌbər]英['rʌbə(r)] n.橡胶:橡皮:黑板擦 v.涂橡胶于…:〈美俚〉同“rubberneck” 网络橡皮擦:胶皮:橡皮轮胎 变形复数:rubbers:
- swift - 代码创建 pickerView 显示或隐藏横线
import UIKit class VC1: UIViewController { fileprivate lazy var pickerV : UIPickerView = { let v = U ...
- 使用maven管理引入jdk1.8
需要在配置文件settings.xml中加入: <profile> <id>jdk-1.8</id> <activation> <activeBy ...
- win10下docker安装和配置镜像仓库
初学docker记录一下流程 1.首先安装直接官网下载 DockerToolbox 即可,安装过程傻瓜式下一步即可.(这个集成了虚拟机,果然安装过的可以去掉) 2.安装好后双击Docker Quick ...
- js Array Map and Set
Array slice slice()就是对应String的substring()版本,它截取Array的部分元素,然后返回一个新的Array: var arr = ['A', 'B', 'C', ' ...
- 菜刀连接webshell
中国菜刀,一个非常好用而又强大的webshell,它可不是用来切菜的做饭的道具哦,是一款专业的网站管理软件,大小只有300多KB,真是小巧实用啊!不过被不法分子利用到,就是一个黑站的利器了.我记得以前 ...
- Linux下使用openssl生成证书
利用OpenSSL生成库和命令程序,在生成的命令程序中包括对加/解密算法的测试,openssl程序,ca程序.利用openssl,ca可生成用于C/S模式的证书文件以及CA文件. 参考:http:// ...
- 如何用Mockplus快速做一个手风琴菜单?
手风琴菜单是一种比较常用的菜单形式,利用原型工具来做这种菜单通常要用到中继器.即使是功能强大的Axure,想实现该效果也比较麻烦.但如果你对Mockplus有所了解,你一定知道,利用Mockplus的 ...
- 8.15 session 有效时间, session在数据查询中最后不用
1.在tomcat-->conf-->conf/web.xm中的<session-config>中设置: <session-config> <session- ...
- jQuery DataTables插件分页允许输入页码跳转
背景说明 项目中使用jQuery DataTables插件来实现分页表格,但是默认的分页样式不能输入页码进行跳转,在页数非常多的时候使用很不方便,最主要的还是没有达到产品部门的设计要求,所以我需要寻找 ...