Commit 7f73444c by fz

1.添加对接友盟平台推送,传平台策略字段区分

1 parent 47aaa352
...@@ -220,7 +220,7 @@ public class HttpUtil { ...@@ -220,7 +220,7 @@ public class HttpUtil {
int statusCode = statusLine.getStatusCode(); int statusCode = statusLine.getStatusCode();
if (statusCode != 200) { if (statusCode != 200) {
HTTPException exception = new HTTPException(statusCode); HTTPException exception = new HTTPException(statusCode);
logger.error("请求地址" + url + "出错,http 状态码为:" + statusCode, exception); logger.error("请求地址" + url + "出错,http 状态码为:" + statusCode+",错误信息:"+exception.getMessage(), exception);
throw exception; throw exception;
} }
String retData = EntityUtils.toString(entity, JSON_UTF8.getCharset()); String retData = EntityUtils.toString(entity, JSON_UTF8.getCharset());
......
...@@ -66,8 +66,7 @@ public class AliYunStrategy extends BaseStrategy implements PushStrategy { ...@@ -66,8 +66,7 @@ public class AliYunStrategy extends BaseStrategy implements PushStrategy {
return R.error("push请求失败"); return R.error("push请求失败");
Map<String, Object> map = new HashMap(); Map<String, Object> map = new HashMap();
map.put("RequestId", pushResponse.getRequestId()); map.put("msg_id", pushResponse.getMessageId());
map.put("MessageId", pushResponse.getMessageId());
return R.ok().data(map); return R.ok().data(map);
} }
......
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.plat.core.web.R; import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
//全部满足触发条件策略 //全部满足触发条件策略
@Slf4j @Slf4j
@Component @Component
public class YouMengStrategy implements PushStrategy { public class YouMengStrategy implements PushStrategy {
@Autowired
private BroadCastService broadCastService;
@Override @Override
public R pushNotify(BaseRequest request) { public R pushNotify(BaseRequest request) {
String deviceType = request.getDeviceType();
if (StringUtils.isEmpty(deviceType)) {
return R.error("终端类型DeviceType不能为空");
}
log.info("====="+deviceType);
//iOS:iOS设备
//ANDROID:Android设备
if (deviceType.equals("ANDROID")) {
return pushAndroidNotify(request);
}
if (deviceType.equals("iOS")) {
return pushIOSNotify(request);
}
return R.error("终端类型DeviceType不匹配");
}
private R pushIOSNotify(BaseRequest request) {
return null; return null;
} }
private R pushAndroidNotify(BaseRequest request) {
try {
return broadCastService.sendAndroidCustomizedcast(request);
} catch (Exception e) {
e.printStackTrace();
return R.error(e.getMessage());
}
}
//public void sendAndroidCustomizedcast() throws Exception { //public void sendAndroidCustomizedcast() throws Exception {
// AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(appkey,appMasterSecret); // AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(appkey,appMasterSecret);
// // TODO Set your alias here, and use comma to split them if there are multiple alias. // // TODO Set your alias here, and use comma to split them if there are multiple alias.
......
...@@ -6,7 +6,7 @@ import lombok.Data; ...@@ -6,7 +6,7 @@ import lombok.Data;
@Data @Data
public class BaseRequest { public class BaseRequest {
/** /**
* 1.阿里云(其他暂未实现) * 1.阿里云,2.友盟
*/ */
private Integer type; private Integer type;
......
...@@ -3,12 +3,15 @@ package com.glsx.modules.notify.push; ...@@ -3,12 +3,15 @@ package com.glsx.modules.notify.push;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.glsx.common.utils.HttpUtil; import com.glsx.common.utils.HttpUtil;
import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@Component @Component
@Slf4j @Slf4j
...@@ -100,7 +103,7 @@ public class PushClient { ...@@ -100,7 +103,7 @@ public class PushClient {
// //
// return fileId; // return fileId;
//} //}
public boolean send(UmengNotification msg) throws Exception { public R send(UmengNotification msg) throws Exception {
String timestamp = Integer.toString((int) (System.currentTimeMillis() / 1000)); String timestamp = Integer.toString((int) (System.currentTimeMillis() / 1000));
msg.setPredefinedKeyValue("timestamp", timestamp); msg.setPredefinedKeyValue("timestamp", timestamp);
String url = host + postPath; String url = host + postPath;
...@@ -123,8 +126,11 @@ public class PushClient { ...@@ -123,8 +126,11 @@ public class PushClient {
String errorCode = data.getString("error_code"); String errorCode = data.getString("error_code");
String errorMsg = data.getString("error_msg"); String errorMsg = data.getString("error_msg");
log.error("友盟fail===errorCode:" + errorCode + "===errorMsg:" + errorMsg); log.error("友盟fail===errorCode:" + errorCode + "===errorMsg:" + errorMsg);
return false; return R.error(errorCode,errorMsg);
} }
return true;
Map<String, Object> map = new HashMap();
map.put("msg_id", data.get("msg_id"));
return R.ok().data(map);
} }
} }
...@@ -44,7 +44,7 @@ public class DeviceControllerTest { ...@@ -44,7 +44,7 @@ public class DeviceControllerTest {
*/ */
NotifyReqParam pushRequest = new NotifyReqParam(); NotifyReqParam pushRequest = new NotifyReqParam();
pushRequest.setType(PushType.ALIYUN.getCode()); pushRequest.setType(PushType.YOUMENG.getCode());
pushRequest.setTitle("消息推送测试标题"); pushRequest.setTitle("消息推送测试标题");
pushRequest.setBody("内容test"); pushRequest.setBody("内容test");
pushRequest.setDeviceType("ANDROID"); pushRequest.setDeviceType("ANDROID");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!