Commit 8c45e14a by fz

1.统一请求参数,按照业务区分通知服务接口以及相关配置

2.添加终端的通知跳转
1 parent 7f73444c
...@@ -2,7 +2,7 @@ package com.glsx.modules.notify.controller; ...@@ -2,7 +2,7 @@ package com.glsx.modules.notify.controller;
import com.glsx.modules.notify.model.BaseRequest; import com.glsx.modules.notify.model.BaseRequest;
import com.glsx.modules.notify.model.param.NotifyReqParam; import com.glsx.modules.notify.model.param.NotifyReqParam;
import com.glsx.modules.notify.service.PushService; import com.glsx.modules.notify.service.CarHomePushService;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -19,10 +19,10 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -19,10 +19,10 @@ import org.springframework.web.bind.annotation.RestController;
*/ */
@RestController @RestController
@RequestMapping("/push") @RequestMapping("/push")
@Api(value = "终端推送API", tags = {"通知或者消息推送"}) @Api(value = "车家智能推送API", tags = {"通知或者消息推送"})
public class PushController { public class CarHomePushController {
@Autowired @Autowired
private PushService pushService; private CarHomePushService pushService;
/** /**
* 推送通知给终端 * 推送通知给终端
......
package com.glsx.modules.notify.factory.strategy; package com.glsx.modules.notify.factory.strategy;
import com.alibaba.fastjson.JSON;
import com.aliyuncs.IAcsClient; import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException; import com.aliyuncs.exceptions.ServerException;
...@@ -12,7 +13,6 @@ import com.google.gson.Gson; ...@@ -12,7 +13,6 @@ import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.HashMap; import java.util.HashMap;
...@@ -21,20 +21,7 @@ import java.util.Map; ...@@ -21,20 +21,7 @@ import java.util.Map;
//aliyun移动推送策略 //aliyun移动推送策略
@Slf4j @Slf4j
@Component @Component
public class AliYunStrategy extends BaseStrategy implements PushStrategy { public class AliYunStrategy implements PushStrategy {
@Value("${aliyun.android.appKey}")
private String appKey_android;
@Value("${aliyun.ios.appKey}")
private String appKey_ios;
@Value("${aliyun.android.NotificationChannel}")
private String androidNotificationChannel;
@Value("${aliyun.ios.ApnsEnv}")
private String apnsEnv;
@Autowired @Autowired
private IAcsClient client; private IAcsClient client;
...@@ -73,25 +60,27 @@ public class AliYunStrategy extends BaseStrategy implements PushStrategy { ...@@ -73,25 +60,27 @@ public class AliYunStrategy extends BaseStrategy implements PushStrategy {
public PushResponse pushAndroidNotify(BaseRequest request) { public PushResponse pushAndroidNotify(BaseRequest request) {
PushRequest pushRequest = new PushRequest(); PushRequest pushRequest = new PushRequest();
pushRequest.setAppKey(Long.valueOf(appKey_android));
buildBaseRequest(pushRequest, request); buildBaseRequest(pushRequest, request);
//安卓默认设置 //安卓默认设置
//离线保存,ExpireTime默认72小时 //离线保存,ExpireTime默认72小时
pushRequest.setStoreOffline(true); pushRequest.setStoreOffline(true);
//设置NotificationChannel参数,兼容Android 8.0以上设备通知接收不到。
pushRequest.setAndroidNotificationChannel(androidNotificationChannel);
return sendRequest(pushRequest); return sendRequest(pushRequest);
} }
public PushResponse pushIOSNotify(BaseRequest request) { public PushResponse pushIOSNotify(BaseRequest request) {
PushRequest pushRequest = new PushRequest(); PushRequest pushRequest = new PushRequest();
pushRequest.setAppKey(Long.valueOf(appKey_ios));
buildBaseRequest(pushRequest, request); buildBaseRequest(pushRequest, request);
//IOS默认设置 //IOS默认设置
pushRequest.setIOSApnsEnv(apnsEnv); //ios通知跳转
Map map=new HashMap();
map.put("type",request.getType());
String extParameters= JSON.toJSONString(map);
pushRequest.setIOSExtParameters(extParameters);
//设置开发环境
pushRequest.setIOSApnsEnv(request.getTestMode());
return sendRequest(pushRequest); return sendRequest(pushRequest);
} }
...@@ -111,10 +100,11 @@ public class AliYunStrategy extends BaseStrategy implements PushStrategy { ...@@ -111,10 +100,11 @@ public class AliYunStrategy extends BaseStrategy implements PushStrategy {
protected void buildBaseRequest(PushRequest request, BaseRequest baseRequest) { protected void buildBaseRequest(PushRequest request, BaseRequest baseRequest) {
request.setRegionId("cn-hangzhou"); request.setRegionId("cn-hangzhou");
request.setAppKey(Long.valueOf(baseRequest.getAppKey()));
request.setPushType(baseRequest.getPushType()); request.setPushType(baseRequest.getPushType());
request.setDeviceType(baseRequest.getDeviceType()); request.setDeviceType(baseRequest.getDeviceType());
request.setTarget(baseRequest.getTarget()); request.setTarget(baseRequest.getTarget());
request.setTargetValue(baseRequest.getTargetValue()); request.setTargetValue(baseRequest.getAlias());
request.setBody(baseRequest.getBody()); request.setBody(baseRequest.getBody());
request.setTitle(baseRequest.getTitle()); request.setTitle(baseRequest.getTitle());
} }
......
package com.glsx.modules.notify.factory.strategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class BaseStrategy {
}
package com.glsx.modules.notify.factory.strategy; package com.glsx.modules.notify.factory.strategy;
import com.aliyuncs.push.model.v20160801.PushResponse;
import com.glsx.modules.notify.factory.PushStrategy; import com.glsx.modules.notify.factory.PushStrategy;
import com.glsx.modules.notify.model.BaseRequest; import com.glsx.modules.notify.model.BaseRequest;
import com.glsx.modules.notify.push.BroadCastService; import com.glsx.modules.notify.push.BroadCastService;
...@@ -24,7 +23,6 @@ public class YouMengStrategy implements PushStrategy { ...@@ -24,7 +23,6 @@ public class YouMengStrategy implements PushStrategy {
return R.error("终端类型DeviceType不能为空"); return R.error("终端类型DeviceType不能为空");
} }
log.info("====="+deviceType);
//iOS:iOS设备 //iOS:iOS设备
//ANDROID:Android设备 //ANDROID:Android设备
if (deviceType.equals("ANDROID")) { if (deviceType.equals("ANDROID")) {
...@@ -39,7 +37,7 @@ public class YouMengStrategy implements PushStrategy { ...@@ -39,7 +37,7 @@ public class YouMengStrategy implements PushStrategy {
} }
private R pushIOSNotify(BaseRequest request) { private R pushIOSNotify(BaseRequest request) {
return null; return R.error("ios友盟推送还未实现对接");
} }
private R pushAndroidNotify(BaseRequest request) { private R pushAndroidNotify(BaseRequest request) {
......
...@@ -8,12 +8,23 @@ public class BaseRequest { ...@@ -8,12 +8,23 @@ public class BaseRequest {
/** /**
* 1.阿里云,2.友盟 * 1.阿里云,2.友盟
*/ */
private Integer type; private Integer platformType;
/** /**
* 平台的AppKey(分安卓ios) * DEV:表示开发环境。
* PRODUCT:表示生产环境
*/ */
private Long appKey; private String testMode;
/**
* 平台的AppKey(安卓ios的key不相同)
*/
private String appKey;
/**
* 平台的AppKey(友盟需要传)
*/
private String appMasterSecret;
/** /**
* 推送类型 * 推送类型
...@@ -60,5 +71,20 @@ public class BaseRequest { ...@@ -60,5 +71,20 @@ public class BaseRequest {
* Target=ALL,值为ALL。 * Target=ALL,值为ALL。
* Target=TBD,值为TBD。 * Target=TBD,值为TBD。
*/ */
private String targetValue; private String alias;
/**
* 该参数只对友盟有意义(alias,aliasType)
*/
private String aliasType;
/**
* 点击通知后跳转,android相关为activity值
*/
private String activity;
/**
* 点击通知后跳转,ios相关为type值
*/
private String type;
} }
...@@ -7,18 +7,18 @@ import lombok.Data; ...@@ -7,18 +7,18 @@ import lombok.Data;
@Data @Data
@ApiModel("推送参数") @ApiModel("推送参数")
public class NotifyReqParam { public class NotifyReqParam {
@ApiModelProperty(value = "1:阿里云(其他暂未实现)",required = true,example = "1") @ApiModelProperty(value = "终端类型 iOS:iOS设备,ANDROID:Android设备",required = true,example = "ANDROID")
private Integer type; private String deviceType;
@ApiModelProperty(value = "iOS:iOS设备,ANDROID:Android设备 ",required = true,example = "ANDROID") @ApiModelProperty(value = "推送平台 1:阿里推送,2:友盟推送",required = true,example = "1")
private String DeviceType; private Integer platformType;
@ApiModelProperty(value = "这里传别名,即用户ID",required = true)
private String alias;
@ApiModelProperty(value = "Android/iOS推送时的消息/通知标题",required = true) @ApiModelProperty(value = "Android/iOS推送时的消息/通知标题",required = true)
private String Title; private String title;
@ApiModelProperty(value = "Android/iOS推送时的消息/通知内容,推送的内容大小是有限制的",required = true) @ApiModelProperty(value = "Android/iOS推送时的消息/通知内容,推送的内容大小是有限制的",required = true)
private String Body; private String body;
@ApiModelProperty(value = "这里传别名,即用户ID",required = true)
private String TargetValue;
} }
package com.glsx.modules.notify.push; package com.glsx.modules.notify.push;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.glsx.modules.notify.model.BaseRequest; import com.glsx.modules.notify.model.BaseRequest;
import com.glsx.modules.notify.push.android.AndroidBroadcast;
import com.glsx.modules.notify.push.android.AndroidCustomizedcast; import com.glsx.modules.notify.push.android.AndroidCustomizedcast;
import com.glsx.modules.notify.push.android.AndroidGroupcast;
import com.glsx.modules.notify.push.android.AndroidUnicast;
import com.glsx.modules.notify.push.ios.IOSBroadcast;
import com.glsx.modules.notify.push.ios.IOSCustomizedcast;
import com.glsx.modules.notify.push.ios.IOSGroupcast;
import com.glsx.modules.notify.push.ios.IOSUnicast;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class BroadCastService { public class BroadCastService {
@Value("${youmeng.appkey}") @Autowired
private String appkey; private PushClient client;
@Value("${youmeng.appMasterSecret}")
private String appMasterSecret;
@Value("${youmeng.android.testMode}") public R sendAndroidCustomizedcast(BaseRequest baseRequest) throws Exception {
private String testMode; AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(baseRequest.getAppKey(), baseRequest.getAppMasterSecret());
// TODO Set your alias here, and use comma to split them if there are multiple alias.
// And if you have many alias, you can also upload a file containing these alias, then
// use file_id to send customized notification.
@Value("${youmeng.android.aliasType}") //addAlias("你与后台商定的用来区分用户的不能相同的", "可以是写死的别名项目名随意"
private String aliasType; customizedcast.setAlias(baseRequest.getAlias(), baseRequest.getAliasType());
//通知栏提示文字
customizedcast.setTicker(baseRequest.getTitle());
//通知标题
customizedcast.setTitle(baseRequest.getTitle());
//通知文字描述
customizedcast.setText(baseRequest.getBody());
@Autowired //通知跳转,如果activity为空,默认跳转应用,否则跳转指定activity
private PushClient client; String activity = baseRequest.getActivity();
if (StringUtils.isEmpty(activity))
customizedcast.goAppAfterOpen();
else
customizedcast.goActivityAfterOpen(activity);
customizedcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
// TODO Set 'production_mode' to 'false' if it's a test device.
// For how to register a test device, please see the developer doc.
if (baseRequest.getTestMode().equals("DEV"))
customizedcast.setTestMode();
else
customizedcast.setProductionMode();
public void sendAndroidBroadcast() throws Exception { //todo 厂商通道相关参数
customizedcast.setChannelActivity("your channel activity");
customizedcast.setChannelProperties("abc");
return client.send(customizedcast);
}
/*public void sendAndroidBroadcast() throws Exception {
AndroidBroadcast broadcast = new AndroidBroadcast(appkey, appMasterSecret); AndroidBroadcast broadcast = new AndroidBroadcast(appkey, appMasterSecret);
broadcast.setTicker("Android broadcast ticker"); broadcast.setTicker("Android broadcast ticker");
broadcast.setTitle("中文的title"); broadcast.setTitle("中文的title");
...@@ -71,7 +87,7 @@ public class BroadCastService { ...@@ -71,7 +87,7 @@ public class BroadCastService {
public void sendAndroidGroupcast() throws Exception { public void sendAndroidGroupcast() throws Exception {
AndroidGroupcast groupcast = new AndroidGroupcast(appkey, appMasterSecret); AndroidGroupcast groupcast = new AndroidGroupcast(appkey, appMasterSecret);
/* TODO *//* TODO
* Construct the filter condition: * Construct the filter condition:
* "where": * "where":
* { * {
...@@ -81,7 +97,7 @@ public class BroadCastService { ...@@ -81,7 +97,7 @@ public class BroadCastService {
* {"tag":"Test"} * {"tag":"Test"}
* ] * ]
* } * }
*/ *//*
JSONObject filterJson = new JSONObject(); JSONObject filterJson = new JSONObject();
JSONObject whereJson = new JSONObject(); JSONObject whereJson = new JSONObject();
JSONArray tagArray = new JSONArray(); JSONArray tagArray = new JSONArray();
...@@ -108,36 +124,8 @@ public class BroadCastService { ...@@ -108,36 +124,8 @@ public class BroadCastService {
groupcast.setChannelActivity("your channel activity"); groupcast.setChannelActivity("your channel activity");
groupcast.setChannelProperties("abc"); groupcast.setChannelProperties("abc");
client.send(groupcast); client.send(groupcast);
} }*/
public R sendAndroidCustomizedcast(BaseRequest baseRequest) throws Exception {
AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(appkey, appMasterSecret);
// TODO Set your alias here, and use comma to split them if there are multiple alias.
// And if you have many alias, you can also upload a file containing these alias, then
// use file_id to send customized notification.
//addAlias("你与后台商定的用来区分用户的不能相同的", "可以是写死的别名项目名随意"
customizedcast.setAlias(baseRequest.getTargetValue(), aliasType);
//通知栏提示文字
customizedcast.setTicker(baseRequest.getTitle());
//通知标题
customizedcast.setTitle(baseRequest.getTitle());
//通知文字描述
customizedcast.setText(baseRequest.getBody());
customizedcast.goAppAfterOpen();
customizedcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
// TODO Set 'production_mode' to 'false' if it's a test device.
// For how to register a test device, please see the developer doc.
if (testMode.equals("true"))
customizedcast.setTestMode();
else
customizedcast.setProductionMode();
//厂商通道相关参数
customizedcast.setChannelActivity("your channel activity");
customizedcast.setChannelProperties("abc");
return client.send(customizedcast);
}
//public void sendAndroidCustomizedcastFile() throws Exception { //public void sendAndroidCustomizedcastFile() throws Exception {
// AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(appkey,appMasterSecret); // AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(appkey,appMasterSecret);
...@@ -176,7 +164,7 @@ public class BroadCastService { ...@@ -176,7 +164,7 @@ public class BroadCastService {
// client.send(filecast); // client.send(filecast);
//} //}
public void sendIOSBroadcast() throws Exception { /*public void sendIOSBroadcast() throws Exception {
IOSBroadcast broadcast = new IOSBroadcast(appkey, appMasterSecret); IOSBroadcast broadcast = new IOSBroadcast(appkey, appMasterSecret);
//alert值设置为字符串 //alert值设置为字符串
//broadcast.setAlert("IOS 广播测试"); //broadcast.setAlert("IOS 广播测试");
...@@ -211,7 +199,7 @@ public class BroadCastService { ...@@ -211,7 +199,7 @@ public class BroadCastService {
public void sendIOSGroupcast() throws Exception { public void sendIOSGroupcast() throws Exception {
IOSGroupcast groupcast = new IOSGroupcast(appkey, appMasterSecret); IOSGroupcast groupcast = new IOSGroupcast(appkey, appMasterSecret);
/* TODO *//* TODO
* Construct the filter condition: * Construct the filter condition:
* "where": * "where":
* { * {
...@@ -220,7 +208,7 @@ public class BroadCastService { ...@@ -220,7 +208,7 @@ public class BroadCastService {
* {"tag":"iostest"} * {"tag":"iostest"}
* ] * ]
* } * }
*/ *//*
JSONObject filterJson = new JSONObject(); JSONObject filterJson = new JSONObject();
JSONObject whereJson = new JSONObject(); JSONObject whereJson = new JSONObject();
JSONArray tagArray = new JSONArray(); JSONArray tagArray = new JSONArray();
...@@ -259,18 +247,18 @@ public class BroadCastService { ...@@ -259,18 +247,18 @@ public class BroadCastService {
client.send(customizedcast); client.send(customizedcast);
} }
//public void sendIOSFilecast() throws Exception { public void sendIOSFilecast() throws Exception {
// IOSFilecast filecast = new IOSFilecast(appkey,appMasterSecret); IOSFilecast filecast = new IOSFilecast(appkey,appMasterSecret);
// // TODO upload your device tokens, and use '\n' to split them if there are multiple tokens // TODO upload your device tokens, and use '\n' to split them if there are multiple tokens
// String fileId = client.uploadContents(appkey,appMasterSecret,"aa"+"\n"+"bb"); String fileId = client.uploadContents(appkey,appMasterSecret,"aa"+"\n"+"bb");
// filecast.setFileId( fileId); filecast.setFileId( fileId);
// //filecast.setAlert("IOS 文件播测试"); //filecast.setAlert("IOS 文件播测试");
// //alert的值设置为字典 //alert的值设置为字典
// filecast.setAlert("今日天气" , "" , "今日可能下雨🌂"); filecast.setAlert("今日天气" , "" , "今日可能下雨🌂");
// filecast.setBadge( 0); filecast.setBadge( 0);
// filecast.setSound( "default"); filecast.setSound( "default");
// // TODO set 'production_mode' to 'true' if your app is under production mode // TODO set 'production_mode' to 'true' if your app is under production mode
// filecast.setTestMode(); filecast.setTestMode();
// client.send(filecast); client.send(filecast);
//} }*/
} }
...@@ -108,8 +108,8 @@ public class PushClient { ...@@ -108,8 +108,8 @@ public class PushClient {
msg.setPredefinedKeyValue("timestamp", timestamp); msg.setPredefinedKeyValue("timestamp", timestamp);
String url = host + postPath; String url = host + postPath;
String postBody = msg.getPostBody(); String postBody = msg.getPostBody();
log.info("调用url======="+url); //log.info("调用url======="+url);
log.info("调用body======="+postBody); //log.info("调用body======="+postBody);
String sign = DigestUtils.md5Hex(("POST" + url + postBody + msg.getAppMasterSecret()).getBytes("utf8")); String sign = DigestUtils.md5Hex(("POST" + url + postBody + msg.getAppMasterSecret()).getBytes("utf8"));
url = url + "?sign=" + sign; url = url + "?sign=" + sign;
JSONObject respJson = null; JSONObject respJson = null;
......
package com.glsx.modules.notify.service;
import com.glsx.modules.notify.model.BaseRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class CarHomePushService extends PushService{
/**
* DEV表示开发环境,PRODUCT表示生产环境
*/
@Value("${youmeng.carhome.testMode}")
private String testMode;
/************************ android配置 ************************/
/**
* 友盟平台android的AppKey
*/
@Value("${youmeng.carhome.android.appkey}")
private String appKey_android_youmeng;
/**
* 友盟平台android的appMasterSecret
*/
@Value("${youmeng.carhome.android.appMasterSecret}")
private String appMasterSecret_android_youmeng;
/**
* 可以是写死的别名项目名随意
*/
@Value("${youmeng.carhome.android.aliasType}")
private String aliasType_android_youmeng;
/**
* 点击通知后跳转,android为activity值,ios为type值
*/
@Value("${youmeng.carhome.android.activity}")
private String activity_android_youmeng;
/************************ ios配置 ************************/
/**
* aliyun平台的AppKey
*/
@Value("${aliyun.carhome.ios.appKey}")
private String appKey_ios_aliyun;
/**
* 点击通知后跳转,android为activity值,ios为type值
*/
@Value("${aliyun.carhome.ios.type}")
private String type_ios_aliyun;
@Override
protected void setiOSAliyunValue(BaseRequest pushRequest) {
//appkey
pushRequest.setAppKey(appKey_ios_aliyun);
//环境
pushRequest.setTestMode(testMode);
//通知跳转
pushRequest.setType(type_ios_aliyun);
}
@Override
protected void setiOSYouMengValue(BaseRequest pushRequest) {
}
@Override
protected void setAndroidYouMengValue(BaseRequest pushRequest) {
//appkey
pushRequest.setAppKey(appKey_android_youmeng);
//appMasterSecret
pushRequest.setAppMasterSecret(appMasterSecret_android_youmeng);
//环境
pushRequest.setTestMode(testMode);
//AliasType
pushRequest.setAliasType(aliasType_android_youmeng);
//通知跳转
pushRequest.setActivity(activity_android_youmeng);
}
@Override
protected void setAndroidAliyunValue(BaseRequest pushRequest) {
}
}
...@@ -2,27 +2,49 @@ package com.glsx.modules.notify.service; ...@@ -2,27 +2,49 @@ package com.glsx.modules.notify.service;
import com.glsx.modules.notify.factory.PushFactory; import com.glsx.modules.notify.factory.PushFactory;
import com.glsx.modules.notify.factory.PushStrategy; import com.glsx.modules.notify.factory.PushStrategy;
import com.glsx.modules.notify.factory.PushType;
import com.glsx.modules.notify.model.BaseRequest; import com.glsx.modules.notify.model.BaseRequest;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service public abstract class PushService {
@Slf4j
public class PushService {
@Autowired @Autowired
private PushFactory pushFactory; private PushFactory pushFactory;
public R pushNotify(BaseRequest pushRequest){ public R pushNotify(BaseRequest pushRequest) {
//如果是阿里云
if (pushRequest.getPlatformType() == PushType.ALIYUN.getCode()) {
if (pushRequest.getDeviceType().equals("ANDROID"))
setAndroidAliyunValue(pushRequest);
if (pushRequest.getDeviceType().equals("iOS"))
setiOSAliyunValue(pushRequest);
}
//如果是友盟
if (pushRequest.getPlatformType() == PushType.YOUMENG.getCode()) {
if (pushRequest.getDeviceType().equals("ANDROID"))
setAndroidYouMengValue(pushRequest);
if (pushRequest.getDeviceType().equals("iOS"))
setiOSYouMengValue(pushRequest);
}
//获取对应策略,1:任意触发条件满足 2:全部触发条件满足 //获取对应策略,1:任意触发条件满足 2:全部触发条件满足
PushStrategy pushStrategy = null; PushStrategy pushStrategy = null;
try { try {
pushStrategy = pushFactory.getStrategy(pushRequest.getType()); pushStrategy = pushFactory.getStrategy(pushRequest.getPlatformType());
} catch (Exception e) { } catch (Exception e) {
R.error("创建策略失败:" + e.getMessage()); R.error("创建策略失败:" + e.getMessage());
} }
return pushStrategy.pushNotify(pushRequest); return pushStrategy.pushNotify(pushRequest);
} }
protected abstract void setiOSAliyunValue(BaseRequest pushRequest);
protected abstract void setiOSYouMengValue(BaseRequest pushRequest);
protected abstract void setAndroidYouMengValue(BaseRequest pushRequest);
protected abstract void setAndroidAliyunValue(BaseRequest pushRequest);
} }
...@@ -4,8 +4,10 @@ import com.glsx.modules.notify.factory.PushType; ...@@ -4,8 +4,10 @@ import com.glsx.modules.notify.factory.PushType;
import com.glsx.modules.notify.model.BaseRequest; import com.glsx.modules.notify.model.BaseRequest;
import com.glsx.modules.notify.model.param.NotifyReqParam; import com.glsx.modules.notify.model.param.NotifyReqParam;
import com.glsx.modules.notify.push.BroadCastService; import com.glsx.modules.notify.push.BroadCastService;
import com.glsx.modules.notify.service.CarHomePushService;
import com.glsx.modules.notify.service.PushService; import com.glsx.modules.notify.service.PushService;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -13,47 +15,33 @@ import org.springframework.beans.BeanUtils; ...@@ -13,47 +15,33 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest @SpringBootTest
@Slf4j @Slf4j
public class DeviceControllerTest { public class DeviceControllerTest {
@Autowired @Autowired
private BroadCastService demo; private CarHomePushService pushService;
@Autowired
PushService pushService;
@Test @Test
public void testPush_android_notify() { public void testPush_android_notify() {
try { try {
//demo.sendAndroidUnicast();
//demo.sendIOSUnicast();
/* TODO these methods are all available, just fill in some fields and do the test
* demo.sendAndroidCustomizedcastFile();
* demo.sendAndroidBroadcast();
* demo.sendAndroidGroupcast();
* demo.sendAndroidCustomizedcast();
* demo.sendAndroidFilecast();
*
* demo.sendIOSBroadcast();
* demo.sendIOSUnicast();
* demo.sendIOSGroupcast();
* demo.sendIOSCustomizedcast();
* demo.sendIOSFilecast();
*/
NotifyReqParam pushRequest = new NotifyReqParam(); NotifyReqParam pushRequest = new NotifyReqParam();
pushRequest.setType(PushType.YOUMENG.getCode()); //推送平台参数
pushRequest.setPlatformType(PushType.YOUMENG.getCode());
pushRequest.setDeviceType("ANDROID");
//推送别名参数
pushRequest.setAlias("Auv2Nn2JkqhFypmb1gm8u3gVCv1Y5T7xcsWo1YueLrck");
//通知参数
pushRequest.setTitle("消息推送测试标题"); pushRequest.setTitle("消息推送测试标题");
pushRequest.setBody("内容test"); pushRequest.setBody("内容test");
pushRequest.setDeviceType("ANDROID");
pushRequest.setTargetValue("com.glsx.aicar.push");
BaseRequest baseRequest = new BaseRequest(); BaseRequest baseRequest = new BaseRequest();
BeanUtils.copyProperties(pushRequest,baseRequest); BeanUtils.copyProperties(pushRequest,baseRequest);
R r = pushService.pushNotify(baseRequest); R r = pushService.pushNotify(baseRequest);
log.info("fzpush====="+r); log.info("fzpush===android==="+r);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
...@@ -62,14 +50,21 @@ public class DeviceControllerTest { ...@@ -62,14 +50,21 @@ public class DeviceControllerTest {
@Test @Test
public void testPush_ios_notify() { public void testPush_ios_notify() {
try { try {
BaseRequest pushRequest = new BaseRequest(); NotifyReqParam pushRequest = new NotifyReqParam();
pushRequest.setType(PushType.ALIYUN.getCode()); //推送平台参数
pushRequest.setTitle("消息推送测试标题"); pushRequest.setPlatformType(PushType.ALIYUN.getCode());
pushRequest.setBody("内容test");
pushRequest.setDeviceType("iOS"); pushRequest.setDeviceType("iOS");
pushRequest.setTargetValue("com.glsx.aicar.push"); //推送别名参数
R r = pushService.pushNotify(pushRequest); pushRequest.setAlias("com.glsx.aicar.push");
log.info("fzpush====="+r);
//通知参数
pushRequest.setTitle("这是消息推送测试标题");
pushRequest.setBody("这是内容test");
BaseRequest baseRequest = new BaseRequest();
BeanUtils.copyProperties(pushRequest,baseRequest);
R r = pushService.pushNotify(baseRequest);
log.info("fzpush===ios==="+r);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!