Commit ec4e69c7 by fz

1.优化代码

1 parent 39585aea
package com.glsx.modules.notify.service; package com.glsx.modules.notify.service;
import com.glsx.modules.notify.factory.PushFactory;
import com.glsx.modules.notify.factory.PushStrategy;
import com.glsx.modules.notify.model.BaseRequest; import com.glsx.modules.notify.model.BaseRequest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
@Slf4j @Slf4j
public class CarHomePushService extends PushService{ public class CarHomePushService extends PushService{
@Autowired
PushFactory pushFactory;
/** /**
* DEV表示开发环境,PRODUCT表示生产环境 * DEV表示开发环境,PRODUCT表示生产环境
*/ */
...@@ -57,6 +62,11 @@ public class CarHomePushService extends PushService{ ...@@ -57,6 +62,11 @@ public class CarHomePushService extends PushService{
private String type_ios_aliyun; private String type_ios_aliyun;
@Override @Override
protected PushStrategy getStrategy(Integer code) throws Exception{
return pushFactory.getStrategy(code);
}
@Override
protected void setiOSAliyunValue(BaseRequest pushRequest) { protected void setiOSAliyunValue(BaseRequest pushRequest) {
//appkey //appkey
pushRequest.setAppKey(appKey_ios_aliyun); pushRequest.setAppKey(appKey_ios_aliyun);
...@@ -79,6 +89,7 @@ public class CarHomePushService extends PushService{ ...@@ -79,6 +89,7 @@ public class CarHomePushService extends PushService{
pushRequest.setAppMasterSecret(appMasterSecret_android_youmeng); pushRequest.setAppMasterSecret(appMasterSecret_android_youmeng);
//环境 //环境
pushRequest.setTestMode(testMode); pushRequest.setTestMode(testMode);
log.info("setAliasType====="+aliasType_android_youmeng);
//AliasType //AliasType
pushRequest.setAliasType(aliasType_android_youmeng); pushRequest.setAliasType(aliasType_android_youmeng);
//通知跳转 //通知跳转
......
package com.glsx.modules.notify.service; package com.glsx.modules.notify.service;
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.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 org.springframework.beans.factory.annotation.Autowired;
public abstract class PushService {
@Autowired
private PushFactory pushFactory;
public abstract class PushService {
public R pushNotify(BaseRequest pushRequest) { public R pushNotify(BaseRequest pushRequest) {
//如果是阿里云 //如果是阿里云
if (pushRequest.getPlatformType() == PushType.ALIYUN.getCode()) { if (pushRequest.getPlatformType() == PushType.ALIYUN.getCode()) {
...@@ -32,7 +28,7 @@ public abstract class PushService { ...@@ -32,7 +28,7 @@ public abstract class PushService {
//获取对应策略,1:任意触发条件满足 2:全部触发条件满足 //获取对应策略,1:任意触发条件满足 2:全部触发条件满足
PushStrategy pushStrategy = null; PushStrategy pushStrategy = null;
try { try {
pushStrategy = pushFactory.getStrategy(pushRequest.getPlatformType()); pushStrategy = getStrategy(pushRequest.getPlatformType());
} catch (Exception e) { } catch (Exception e) {
R.error("创建策略失败:" + e.getMessage()); R.error("创建策略失败:" + e.getMessage());
} }
...@@ -40,6 +36,8 @@ public abstract class PushService { ...@@ -40,6 +36,8 @@ public abstract class PushService {
return pushStrategy.pushNotify(pushRequest); return pushStrategy.pushNotify(pushRequest);
} }
protected abstract PushStrategy getStrategy(Integer code) throws Exception;
protected abstract void setiOSAliyunValue(BaseRequest pushRequest); protected abstract void setiOSAliyunValue(BaseRequest pushRequest);
protected abstract void setiOSYouMengValue(BaseRequest pushRequest); protected abstract void setiOSYouMengValue(BaseRequest pushRequest);
......
...@@ -30,16 +30,23 @@ public class DeviceControllerTest { ...@@ -30,16 +30,23 @@ public class DeviceControllerTest {
try { try {
NotifyReqParam pushRequest = new NotifyReqParam(); NotifyReqParam pushRequest = new NotifyReqParam();
//推送平台参数 //推送平台参数
pushRequest.setPlatformType(PushType.YOUMENG.getCode()); //pushRequest.setPlatformType(PushType.YOUMENG.getCode());
pushRequest.setDeviceType("ANDROID"); pushRequest.setDeviceType("ANDROID");
//推送别名参数 //推送别名参数
pushRequest.setAlias("Auv2Nn2JkqhFypmb1gm8u3gVCv1Y5T7xcsWo1YueLrck"); pushRequest.setAlias("91712432");
//通知参数 //通知参数
pushRequest.setTitle("消息推送测试标题"); pushRequest.setTitle("消息推送测试标题");
pushRequest.setBody("内容test"); pushRequest.setBody("内容test");
BaseRequest baseRequest = new BaseRequest(); BaseRequest baseRequest = new BaseRequest();
BeanUtils.copyProperties(pushRequest,baseRequest); BeanUtils.copyProperties(pushRequest,baseRequest);
if (baseRequest.getDeviceType().equals("ANDROID")){
baseRequest.setPlatformType(PushType.YOUMENG.getCode());
}
if (baseRequest.getDeviceType().equals("iOS")){
baseRequest.setPlatformType(PushType.ALIYUN.getCode());
}
R r = pushService.pushNotify(baseRequest); R r = pushService.pushNotify(baseRequest);
log.info("fzpush===android==="+r); log.info("fzpush===android==="+r);
} catch (Exception ex) { } catch (Exception ex) {
...@@ -52,7 +59,7 @@ public class DeviceControllerTest { ...@@ -52,7 +59,7 @@ public class DeviceControllerTest {
try { try {
NotifyReqParam pushRequest = new NotifyReqParam(); NotifyReqParam pushRequest = new NotifyReqParam();
//推送平台参数 //推送平台参数
pushRequest.setPlatformType(PushType.ALIYUN.getCode()); //pushRequest.setPlatformType(PushType.ALIYUN.getCode());
pushRequest.setDeviceType("iOS"); pushRequest.setDeviceType("iOS");
//推送别名参数 //推送别名参数
pushRequest.setAlias("com.glsx.aicar.push"); pushRequest.setAlias("com.glsx.aicar.push");
...@@ -63,6 +70,13 @@ public class DeviceControllerTest { ...@@ -63,6 +70,13 @@ public class DeviceControllerTest {
BaseRequest baseRequest = new BaseRequest(); BaseRequest baseRequest = new BaseRequest();
BeanUtils.copyProperties(pushRequest,baseRequest); BeanUtils.copyProperties(pushRequest,baseRequest);
if (baseRequest.getDeviceType().equals("ANDROID")){
baseRequest.setPlatformType(PushType.YOUMENG.getCode());
}
if (baseRequest.getDeviceType().equals("iOS")){
baseRequest.setPlatformType(PushType.ALIYUN.getCode());
}
R r = pushService.pushNotify(baseRequest); R r = pushService.pushNotify(baseRequest);
log.info("fzpush===ios==="+r); log.info("fzpush===ios==="+r);
} catch (Exception ex) { } catch (Exception ex) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!