Uni-Java_unipushjava后端详解unipush的集成
1.集成maven包:
gexin-rp-sdk-http
4.1.0.4
getui-nexus
2.unipush 通过应⽤包,官⽹⾃动⽣成 appId,appKey,masterSecret 以及对应的包名 io.dcloud.*****
3.开始演⽰java代码:
package com.s.utils.jpush;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
in.rp.sdk.ba.IPushResult;
in.rp.sdk.ba.impl.SingleMessage;
in.rp.sdk.ba.impl.Target;
in.rp.ify.Notify;
in.rp.sdk.ba.payload.APNPayload;
in.rp.sdk.ba.payload.APNPayload.DictionaryAlertMsg;
in.rp.sdk.ba.payload.MultiMedia;
in.rp.sdk.ba.payload.MultiMedia.MediaType;
in.rp.sdk.dto.GtReq;
in.ptions.RequestException;
in.rp.sdk.http.IGtPush;
in.plate.NotificationTemplate;
in.plate.TransmissionTemplate;
in.plate.style.Style0;
滁州西涧唐韦应物le.gson.JsonObject;
import com.s.utils.UUIDUtils;
public class PushtoSingle {
private static final Logger logger = Logger(PushtoSingle.class);
// 详见【概述】-【服务端接⼊步骤】-【STEP1】说明,获得的应⽤配置
//应⽤配置的id
private static String appId = "xxx";
两数相乘
private static String appKey = "xxxx";
private static String masterSecret = "xxx";
// 别名推送⽅式
// static String Alias = "";
static String host = "sdk.open./apiex.htm";
//初始化连接
private static IGtPush push = new IGtPush(host, appKey, masterSecret);;
/***
* 测试推送
* @param args
*/
public static void main(String[] args){
String title = "收车";
String text = "⽹标价:23.5 万元!成都发布本⽥雅阁混合动⼒2.0L旗舰版。请尽快查看>>"; JsonObject josn = new JsonObject();
josn.addProperty("type", "rerve");
josn.addProperty("id", 52);
//这⾥cid需要应⽤⽣成⼀个⼿机对应⼀个id,以下都是我的测试⽅法
String an = "x'x'x'x";
String ios = "x'x'x'x";
String an1 = "x'x'x'x";
//ios
//uniPushOffLine(ios, title, text, josn);
//安卓
uniPushOffLine(an, title, text, josn);
//uniPushOnline(an, title, text, String());
//uniPushOnline(an, title, text, String());
}
/***
* 离线模板处理,⼚商通道
* @param title
* @param text
* @param paramJosn
* @return
*/
public static TransmissionTemplate offLinetransmissionTemplate(String title,String text,JsonObject paramJosn){
//⼚商通道离线推送注意类的使⽤,在线和离线使⽤不同
TransmissionTemplate template = new TransmissionTemplate();
template.tAppId(appId);
template.tAppkey(appKey);
Notify notify = new Notify();
notify.tTitle(title);
notify.tContent(text);
//这是⼚商通道连接,其中注意参数 component=/io.dcloud.PandoraEntry,有xxx是你的包名,S.payload这个值是你
要穿透的内容,注意连接的长度,过长⼚商通道会失效。
//android.intent.action.oppopush;launchFlags=0x14000000;component=/io.dcloud.PandoraEntry;S.UP-OL-
SU=true;S.title=收车;S.content=收车;在
String intent =
"intent:#Intent;action=android.intent.action.oppopush;launchFlags=0x14000000;component=io.dcloud.UNI59F5329/io.dcloud.Pand OL-SU=true;S.title=收车;S.content=收车;"
+ "S.payload="+ String() +";end";
System.out.println(intent);
notify.tIntent(intent);
notify.tType(GtReq.NotifyInfo.Type._intent);
template.t3rdNotifyInfo(notify);//设置第三⽅通知
//ios处理通知消息
APNPayload payload = new APNPayload();
payload.tAutoBadge("+1");
招商工作总结payload.tContentAvailable(0);
payload.tSound("default");
for (String key : paramJosn.keySet()) {
//System.out.println(key +":" + (key).getAsString());
payload.addCustomMsg(key, (key).getAsString());
}
DictionaryAlertMsg alertMsg = new DictionaryAlertMsg();
alertMsg.tTitle(title);
alertMsg.tBody(text);
payload.tAlertMsg(alertMsg);
//ios
template.tAPNInfo(payload);
//这⾥也可设置穿透内容
template.String());鱼子酱好吃吗
template.tTransmissionType(1);
return template;
}
/***
* 离线通道推送主⽅法
* @param cid
* @param title
* @param text
出生年月计算年龄
* @param paramJosn
*/
public static void uniPushOffLine(String cid,String title,String text,JsonObject paramJosn){ TransmissionTemplate template = offLinetransmissionTemplate(title, text, paramJosn); SingleMessage message = new SingleMessage();
message.tOffline(true);
// 离线有效时间,单位为毫秒
message.tOfflineExpireTime(24 * 3600 * 1000);
message.tData(template);
// 可选,1为wifi,0为不限制⽹络环境。根据⼿机处于的⽹络情况,决定是否下发
message.tPushNetWorkType(0);
Target target = new Target();
target.tAppId(appId);
target.tClientId(cid);
//target.tAlias(Alias);
IPushResult ret = null;
try {
英语励志格言
ret = push.pushMessageToSingle(message, target);
} catch (RequestException e) {
e.printStackTrace();
ret = push.pushMessageToSingle(message, target, e.getRequestId());
}
封神演义读后感if (ret != null) {
logger.info("推送成功,第三⽅返回:" + Respon().toString());
} el {
<("推送时第三⽅服务器响应异常");
}
}
/***
* unipush 在线推送
* @param cid
* @param title
* @param text
* @param penetrateParam
*/
public static void uniPushOnline(String cid,String title,String text,String penetrateParam){ NotificationTemplate template = onlineNotificationTemplate(title,text,penetrateParam);; SingleMessage message = new SingleMessage();
message.tOffline(true);
// 离线有效时间,单位为毫秒
message.tOfflineExpireTime(24 * 3600 * 1000);
message.tData(template);
// 可选,1为wifi,0为不限制⽹络环境。根据⼿机处于的⽹络情况,决定是否下发
message.tPushNetWorkType(0);
Target target = new Target();
target.tAppId(appId);
target.tClientId(cid);
//target.tAlias(Alias);
IPushResult ret = null;
try {
ret = push.pushMessageToSingle(message, target);
} catch (RequestException e) {
e.printStackTrace();
ret = push.pushMessageToSingle(message, target, e.getRequestId());
巴门尼德
}
if (ret != null) {
logger.info("推送成功,第三⽅返回:" + Respon().toString());
} el {