注意!注意!注意!
重要的事情提醒三遍
拿到主要修改一下几个数据 appId、appKey、masterSecret、CID
sdkConfigs修改一下appid、appkey、appsecret换成自己的
1、先添加pox
repositories放在project下
<repositories>
<repository>
<id>getui-nexus</id>
<url>http://mvn.gt.igexin.com/nexus/content/repositories/releases</url>
</repository>
</repositories>
<dependency>
<groupId>com.gexin.platform</groupId>
<artifactId>gexin-rp-sdk-http</artifactId>
<version>4.1.2.0</version>
</dependency>
2、测试代码
import com.gexin.rp.sdk.base.IPushResult;
import com.gexin.rp.sdk.base.impl.SingleMessage;
import com.gexin.rp.sdk.base.impl.Target;
import com.gexin.rp.sdk.exceptions.RequestException;
import com.gexin.rp.sdk.http.Constants;
import com.gexin.rp.sdk.http.IGtPush;
import com.gexin.rp.sdk.template.NotificationTemplate;
import com.gexin.rp.sdk.template.style.Style0;
public class AppPush {
//定义常量, appId、appKey、masterSecret 采用本文档 "第二步 获取访问凭证 "中获得的应用配置
private static String appId = "mrwyTKfpE5AjRy4BJex5U4";
private static String appKey = "avCa7NPjUZ5lqfzUcuRmC";
private static String masterSecret = "OQheWwcmY6AWz0VpcyVJ5";
// private static String url = "http://sdk.open.api.igexin.com/apiex.htm";
static String CID = "d7b62a371c2125d2db8ad82008a22c62";
// 别名推送方式
// static String Alias = "";
// 如果需要使用HTTPS,直接修改url即可
//private static String url = "https://api.getui.com/apiex.htm";
static String host = "http://api.getui.com/apiex.htm";
public static void main(String[] args) throws Exception {
// 设置后,根据别名推送,会返回每个cid的推送结果
System.setProperty(Constants.GEXIN_PUSH_SINGLE_ALIAS_DETAIL, "false");
IGtPush push = new IGtPush(host, appKey, masterSecret);
NotificationTemplate template = getNotificationTemplate();
SingleMessage message = new SingleMessage();
message.setOffline(true);
// 离线有效时间,单位为毫秒
message.setOfflineExpireTime(24 * 3600 * 1000);
message.setData(template);
// 可选,1为wifi,0为不限制网络环境。根据手机处于的网络情况,决定是否下发
message.setPushNetWorkType(0);
// 厂商通道下发策略
message.setStrategyJson("{\"default\":4,\"ios\":4,\"st\":4}");
Target target = new Target();
target.setAppId(appId);
target.setClientId(CID);
//target.setAlias(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) {
System.out.println(ret.getResponse().toString());
} else {
System.out.println("服务器响应异常");
}
}
public static NotificationTemplate getNotificationTemplate() {
NotificationTemplate template = new NotificationTemplate();
// 设置APPID与APPKEY
template.setAppId(appId);
template.setAppkey(appKey);
Style0 style = new Style0();
// 设置通知栏标题与内容
style.setTitle("请输入通知栏标题");
style.setText("请输入通知栏edada内容");
System.out.println("1....");
// 配置通知栏图标
style.setLogo("icon.png");
// 配置通知栏网络图标
style.setLogoUrl("");
// 设置通知是否响铃,震动,或者可清除
style.setRing(true);
style.setVibrate(true);
style.setClearable(true);
style.setChannel("通知渠道id");
style.setChannelName("通知渠道名称");
style.setChannelLevel(3); //设置通知渠道重要性
template.setStyle(style);
template.setTransmissionType(1); // 透传消息接受方式设置,1:立即启动APP,2:客户端收到消息后需要自行处理
template.setTransmissionContent("请输入您要透传的内容");
//template.setAPNInfo(getAPNPayload()); //详见【推送模板说明】iOS通知样式设置
return template;
}
}
3、在uniapp中的manifest.json修改sdkConfigs下的push
"push" : {
"igexin" : {
"appid" : "mrwyTKfpE5AjRy4BJex5U4",
"appkey" : "avCa7NPjUZ5lqfzUcuRmC",
"appsecret" : "PgOhwwgALo71vB4PMJfX29"
}
},
按照这种操作就可以用了