消息通知

This commit is contained in:
lzh
2023-03-16 23:49:04 +08:00
parent cfffca82fa
commit 9afc113da3
9 changed files with 299 additions and 25 deletions

View File

@@ -0,0 +1,138 @@
package com.zscat.mallplus.unipush;
import com.getui.push.v2.sdk.ApiHelper;
import com.getui.push.v2.sdk.GtApiConfiguration;
import com.getui.push.v2.sdk.api.PushApi;
import com.getui.push.v2.sdk.common.ApiResult;
import com.getui.push.v2.sdk.dto.req.Audience;
import com.getui.push.v2.sdk.dto.req.message.PushDTO;
import com.getui.push.v2.sdk.dto.req.message.PushMessage;
import com.getui.push.v2.sdk.dto.req.message.android.GTNotification;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Map;
@Component
public class UniPushService {
// @Value("${unipush.appid:UBUIDJ8NQm50rGJsB6LYx1}")
// private String appid;
private static String apiurl = "https://restapi.getui.com/v2/";
private static String appid = "UBUIDJ8NQm50rGJsB6LYx1";
private static String appkey = "RS3UZfeS509hcNEkmfS6R";
private static String appsecret = "6QuFcPWFga8DQzSa03ruR7";
private static String mastersecret = "6fjUinwRfDA3BcEnDQvTl5";
private static String apppackage = "org.jbase.yxt.yyd.pyw";
private static PushApi pushApi = null;
private PushApi singlePushApi() {
if (pushApi == null) {
System.setProperty("http.maxConnections", "200");
GtApiConfiguration apiConfiguration = new GtApiConfiguration();
//填写应用配置
apiConfiguration.setAppId(appid);
apiConfiguration.setAppKey(appkey);
apiConfiguration.setMasterSecret(mastersecret);
// 接口调用前缀,请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId
apiConfiguration.setDomain(apiurl);
// 实例化ApiHelper对象用于创建接口对象
ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
// 创建对象建议复用。目前有PushApi、StatisticApi、UserApi
pushApi = apiHelper.creatApi(PushApi.class);
}
return pushApi;
}
public void test() {
// 设置httpClient最大连接数当并发较大时建议调大此参数。或者启动参数加上 -Dhttp.maxConnections=200
System.setProperty("http.maxConnections", "200");
GtApiConfiguration apiConfiguration = new GtApiConfiguration();
//填写应用配置
apiConfiguration.setAppId("UBUIDJ8NQm50rGJsB6LYx1");
apiConfiguration.setAppKey("RS3UZfeS509hcNEkmfS6R");
apiConfiguration.setMasterSecret("6fjUinwRfDA3BcEnDQvTl5");
// 接口调用前缀,请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId
apiConfiguration.setDomain("https://restapi.getui.com/v2/");
// 实例化ApiHelper对象用于创建接口对象
ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
// 创建对象建议复用。目前有PushApi、StatisticApi、UserApi
PushApi pushApi = apiHelper.creatApi(PushApi.class);
//根据cid进行单推
PushDTO<Audience> pushDTO = new PushDTO<Audience>();
// 设置推送参数
pushDTO.setRequestId(System.currentTimeMillis() + "");
/**** 设置个推通道参数 *****/
PushMessage pushMessage = new PushMessage();
pushDTO.setPushMessage(pushMessage);
GTNotification notification = new GTNotification();
pushMessage.setNotification(notification);
notification.setTitle("测试TitleXXX");
notification.setBody("测试BodyXXXXXX");
String payload = "{\"title\":\"liutitle\",\"body\":\"liubody\",\"name\":\"hao\",\"userid\":101,\"msgtitle\":\"haha\"}";
notification.setPayload(payload);
notification.setClickType("payload");
// notification.setClickType("url");
// notification.setUrl("https://www.getui.com");
/**** 设置个推通道参数,更多参数请查看文档或对象源码 *****/
// /**** 设置厂商相关参数 ****/
// PushChannel pushChannel = new PushChannel();
// pushDTO.setPushChannel(pushChannel);
// /*配置安卓厂商参数*/
// AndroidDTO androidDTO = new AndroidDTO();
// pushChannel.setAndroid(androidDTO);
// Ups ups = new Ups();
// androidDTO.setUps(ups);
// ThirdNotification thirdNotification = new ThirdNotification();
// ups.setNotification(thirdNotification);
// thirdNotification.setTitle("厂商title");
// thirdNotification.setBody("厂商body");
// thirdNotification.setClickType("url");
// thirdNotification.setUrl("https://www.getui.com");
// // 两条消息的notify_id相同新的消息会覆盖老的消息取值范围0-2147483647
// // thirdNotification.setNotifyId("11177");
// /*配置安卓厂商参数结束,更多参数请查看文档或对象源码*/
// /*设置ios厂商参数*/
// IosDTO iosDTO = new IosDTO();
// pushChannel.setIos(iosDTO);
// // 相同的collapseId会覆盖之前的消息
// iosDTO.setApnsCollapseId("xxx");
// Aps aps = new Aps();
// iosDTO.setAps(aps);
// Alert alert = new Alert();
// aps.setAlert(alert);
// alert.setTitle("ios title");
// alert.setBody("ios body");
// /*设置ios厂商参数结束更多参数请查看文档或对象源码*/
/*设置接收人信息*/
Audience audience = new Audience();
pushDTO.setAudience(audience);
audience.addCid("89e286aee78d38faf748a690e603b1a3");
/*设置接收人信息结束*/
/**** 设置厂商相关参数,更多参数请查看文档或对象源码 ****/
// 进行cid单推
ApiResult<Map<String, Map<String, String>>> apiResult = pushApi.pushToSingleByCid(pushDTO);
if (apiResult.isSuccess()) {
// success
System.out.println(apiResult.getData());
} else {
// failed
System.out.println("code:" + apiResult.getCode() + ", msg: " + apiResult.getMsg());
}
}
public static void main(String[] args) {
new UniPushService().test();
}
}

View File

@@ -82,4 +82,11 @@ jwt.secret=mySecret
jwt.expiration=604800
#JWT\u8D1F\u8F7D\u4E2D\u62FF\u5230\u5F00\u5934
jwt.tokenHead=Bearer
#===JWT end===
#===JWT end===
unipush.baseurl=https://restapi.getui.com/v2/UBUIDJ8NQm50rGJsB6LYx1
unipush.appid=UBUIDJ8NQm50rGJsB6LYx1
unipush.appkey=RS3UZfeS509hcNEkmfS6R
unipush.appsecret=6QuFcPWFga8DQzSa03ruR7
unipush.mastersecret=6fjUinwRfDA3BcEnDQvTl5
unipush.apppackage=org.jbase.yxt.yyd.pyw