|
|
|
@ -6,13 +6,8 @@ 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.PushChannel; |
|
|
|
|
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.AndroidDTO; |
|
|
|
|
import com.getui.push.v2.sdk.dto.req.message.android.GTNotification; |
|
|
|
|
import com.getui.push.v2.sdk.dto.req.message.android.ThirdNotification; |
|
|
|
|
import com.getui.push.v2.sdk.dto.req.message.android.Ups; |
|
|
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
@ -31,9 +26,9 @@ public class UniPushService { |
|
|
|
|
System.setProperty("http.maxConnections", "200"); |
|
|
|
|
GtApiConfiguration apiConfiguration = new GtApiConfiguration(); |
|
|
|
|
//填写应用配置
|
|
|
|
|
apiConfiguration.setAppId("JwvQulOIsq8kcFGey8fxo4"); |
|
|
|
|
apiConfiguration.setAppKey("ERpW23I6gn8jo8NVcjP8H1"); |
|
|
|
|
apiConfiguration.setMasterSecret("t6HsZ4qwfK7YiBknIeaWy2"); |
|
|
|
|
apiConfiguration.setAppId("9LTgsDR5Y26MTWpN1uBhb1"); |
|
|
|
|
apiConfiguration.setAppKey("GV7qmZoFh1AaqD4uDfH857"); |
|
|
|
|
apiConfiguration.setMasterSecret("JX9m0F92tZ5ciBtrfiJu93"); |
|
|
|
|
// 接口调用前缀,请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId
|
|
|
|
|
apiConfiguration.setDomain("https://restapi.getui.com/v2/"); |
|
|
|
|
// 实例化ApiHelper对象,用于创建接口对象
|
|
|
|
@ -51,73 +46,31 @@ public class UniPushService { |
|
|
|
|
* @Param [uniPushModel] |
|
|
|
|
* @Return void |
|
|
|
|
*/ |
|
|
|
|
public static void androidTemplate(JSONObject object) { |
|
|
|
|
public static String pushToSingleByCid(JSONObject object) { |
|
|
|
|
|
|
|
|
|
PushApi pushApi = createClient(); |
|
|
|
|
|
|
|
|
|
/*设置接收人信息*/ |
|
|
|
|
//根据cid进行单推
|
|
|
|
|
PushDTO<Audience> pushDTO = new PushDTO<Audience>(); |
|
|
|
|
PushDTO<Audience> pushDTO = new PushDTO<>(); |
|
|
|
|
// 设置推送参数
|
|
|
|
|
pushDTO.setRequestId(System.currentTimeMillis() + ""); |
|
|
|
|
/**** 设置个推通道参数 *****/ |
|
|
|
|
// 设置个推通道参数
|
|
|
|
|
PushMessage pushMessage = new PushMessage(); |
|
|
|
|
pushDTO.setPushMessage(pushMessage); |
|
|
|
|
GTNotification notification = new GTNotification(); |
|
|
|
|
pushMessage.setNotification(notification); |
|
|
|
|
notification.setTitle(object.getString("title")); |
|
|
|
|
notification.setBody(object.getString("body")); |
|
|
|
|
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(object.getString("title")); |
|
|
|
|
thirdNotification.setBody(object.getString("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厂商参数结束,更多参数请查看文档或对象源码*/ |
|
|
|
|
|
|
|
|
|
pushMessage.setTransmission(object.getString("body")); |
|
|
|
|
/*设置接收人信息*/ |
|
|
|
|
Audience audience = new Audience(); |
|
|
|
|
pushDTO.setAudience(audience); |
|
|
|
|
audience.addCid(object.getString("cid")); |
|
|
|
|
/*设置接收人信息结束*/ |
|
|
|
|
/**** 设置厂商相关参数,更多参数请查看文档或对象源码 ****/ |
|
|
|
|
|
|
|
|
|
// 进行cid单推
|
|
|
|
|
ApiResult<Map<String, Map<String, String>>> apiResult = pushApi.pushToSingleByCid(pushDTO); |
|
|
|
|
System.out.println("===========================================" + apiResult); |
|
|
|
|
if (apiResult.isSuccess()) { |
|
|
|
|
return apiResult.getData().toString(); |
|
|
|
|
// success
|
|
|
|
|
System.out.println(apiResult.getData()); |
|
|
|
|
} else { |
|
|
|
|
return "code:" + apiResult.getCode() + ", msg: " + apiResult.getMsg(); |
|
|
|
|
// failed
|
|
|
|
|
System.out.println("code:" + apiResult.getCode() + ", msg: " + apiResult.getMsg()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|