unipush推送

https://ask.dcloud.net.cn/article/35622

2.创建 unipush账号,必须实名认证
3.下载hbuliderx
4.在hbuliderx中新建uniapp项目

5.云打包(包名要记下来)
6.
7.密码123456
8.在unipush后台找到该应用,并测试透传消息,成功则安卓前台已经好了
9.Ios端在线和安卓一样都是走的个推通道
10.Ios端需要下载ios推送证书密码123456或者123:这里网上搜,而且可以先在线测试下http://www.hema.im/certificate
11.下面需要验证ios推送证书是否正确:
先打包iosapp,然后登录,获取clientid,然后根据cid获取token

下面测试,并且必须要测试成功才行:

接下来在unipush中推送ios的透传消息,页面最下面的部分就是离线部分
12.服务器代码:这里仔细看注释就行,模板采用TransmissionTemplate
先引入依赖
com.gexin.platform
gexin-rp-sdk-http
4.1.2.1




getui-nexus
http://mvn.gt.getui.com/nexus/content/repositories/releases/

然后java代码:强烈建议这里对应着unipush中的透传消息看,注意?号,和我们的代码中的字段有关(也可以看api)
IGtPush push = new IGtPush(url, appKey, masterSecret);
List userIdList = new ArrayList<>(userIdSet);
List clientIds = sysUserService.getClientIdsByUserIdList(userIdList);
String alarmTypeName = dictItemService.getDictItemNameByRedcAndCode(“ALARMTYPE”,alarm.getAlarmType());
String alarmAreaName = dictItemService.getDictItemNameByTypeAndCode(“CAMERAAREA”,alarm.getAlarmArea());
//透传消息对象
PushAlarmMessage pushAlarmMessage = new PushAlarmMessage();
pushAlarmMessage.setAlarmId(alarm.getId());
pushAlarmMessage.setAlarmNum(alarm.getAlarmNum());
pushAlarmMessage.setAlarmTypeName(alarmTypeName);
pushAlarmMessage.setAlarmAreaName(alarmAreaName);
pushAlarmMessage.setAlarmTime(alarm.getAlarmTime());
pushAlarmMessage.setCameraId(alarm.getAlarmDevice());
pushAlarmMessage.setTitleInfo(“AI平安校园”);
pushAlarmMessage.setContentInfo(alarmAreaName+“发生”+alarmTypeName+",请及时处理!");

    // STEP4:选择透传模板
    TransmissionTemplate template = new TransmissionTemplate();
    template.setAppId(appId);
    template.setAppkey(appKey);
    // 1:收到通知直接激活app,2:客服端自行处理
    template.setTransmissionType(2);
    // 传递透传消息
    template.setTransmissionContent(JSONObject.toJSONString(pushAlarmMessage));
    APNPayload.DictionaryAlertMsg alertMsg = new APNPayload.DictionaryAlertMsg();
    alertMsg.setBody(alarmAreaName+"发生"+alarmTypeName+",请及时处理!");         //通知文本消息字符串
    alertMsg.setActionLocKey("");
    alertMsg.setLocKey("");
    alertMsg.addLocArg("");
    alertMsg.setLaunchImage("");//指定启动界面图片名
    //IOS8.2支持字段
    alertMsg.setTitle("AI平安校园");     //通知标题
    alertMsg.setTitleLocKey("");
    alertMsg.addTitleLocArg("");
    APNPayload payload = new APNPayload();
    payload.setAlertMsg(alertMsg);
    //在已有数字基础上加1显示,设置为-1时,在已有数字上减1显示,设置为数字时,显示指定数字

// payload.setAutoBadge("+1");
payload.setContentAvailable(0);//推送直接带有透传数据
//ios 12.0 以上可以使用 Dictionary 类型的 sound
payload.setSound(“default”);
payload.setCategory("$由客户端定义");//在客户端通知栏触发特定的action和button显示
payload.addCustomMsg(“payload”, JSONObject.toJSONString(pushAlarmMessage));//增加自定义的数据,Key-Value形式
//简单模式APNPayload.SimpleMsg
// payload.setAlertMsg(new APNPayload.SimpleAlertMsg(pushAlarmMessage.getContentInfo()));//通知消息体 SimpleAlertMsg: 通知文本消息字符串
template.setAPNInfo(payload); //ios消息推送,用于设置标题、内容、语音、多媒体、VoIP(基于IP的语音传输)等。离线走APNs时起效果
String intent = “intent:#Intent;action=android.intent.action.oppopush;launchFlags=0x14000000;component=com.linkage.ai.school;S.UP-OL-SU=true;S.title=AI平安校园;S.content=”+alarmAreaName+“发生”+alarmTypeName+";S.payload="+JSONObject.toJSONString(pushAlarmMessage)+";end";
Notify notify = new Notify();
// 通知栏显示标题
notify.setTitle(“AI平安校园”);
// 通知栏内容
notify.setContent(alarmAreaName+“发生”+alarmTypeName);
notify.setIntent(intent);
// 设置第三方通知
template.set3rdNotifyInfo(notify);
// STEP5:定义"AppMessage"类型消息对象,设置推送消息有效期等推送参数
// 采用toList方案,定义ListMessage消息类型
ListMessage message = new ListMessage();
message.setData(template);
message.setOffline(true);
message.setOfflineExpireTime(1000 * 600); // 时间单位为毫秒
String contentId = push.getContentId(message);
// 获取推送目标
List targets = new ArrayList<>();
for (String clientId : clientIds) {
Target target = new Target();
target.setAppId(appId);
target.setClientId(clientId);
targets.add(target);
}
// STEP6:执行推送,不采用toApp方案,采用toList方案
IPushResult ret = push.pushMessageToList(contentId, targets);
System.out.println(ret.getResponse().toString());
注意:ios离线推送的问题大部分都是证书出了问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值