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;
......
...@@ -2,6 +2,7 @@ package com.glsx.modules.notify.push; ...@@ -2,6 +2,7 @@ package com.glsx.modules.notify.push;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.glsx.modules.notify.model.BaseRequest;
import com.glsx.modules.notify.push.android.AndroidBroadcast; 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.AndroidGroupcast;
...@@ -10,255 +11,266 @@ import com.glsx.modules.notify.push.ios.IOSBroadcast; ...@@ -10,255 +11,266 @@ import com.glsx.modules.notify.push.ios.IOSBroadcast;
import com.glsx.modules.notify.push.ios.IOSCustomizedcast; import com.glsx.modules.notify.push.ios.IOSCustomizedcast;
import com.glsx.modules.notify.push.ios.IOSGroupcast; import com.glsx.modules.notify.push.ios.IOSGroupcast;
import com.glsx.modules.notify.push.ios.IOSUnicast; import com.glsx.modules.notify.push.ios.IOSUnicast;
import com.glsx.plat.core.web.R;
import org.springframework.beans.factory.annotation.Autowired; 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
public class BroadCastService { public class BroadCastService {
@Value("${youmeng.appkey}") @Value("${youmeng.appkey}")
private String appkey; private String appkey;
@Value("${youmeng.appMasterSecret}") @Value("${youmeng.appMasterSecret}")
private String appMasterSecret; private String appMasterSecret;
@Autowired @Value("${youmeng.android.testMode}")
private PushClient client; private String testMode;
public void sendAndroidBroadcast() throws Exception { @Value("${youmeng.android.aliasType}")
AndroidBroadcast broadcast = new AndroidBroadcast(appkey,appMasterSecret); private String aliasType;
broadcast.setTicker( "Android broadcast ticker");
broadcast.setTitle( "中文的title");
broadcast.setText( "Android broadcast text");
broadcast.goAppAfterOpen();
broadcast.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.
broadcast.setProductionMode();
// Set customized fields
broadcast.setExtraField("test", "helloworld");
//厂商通道相关参数
broadcast.setChannelActivity("your channel activity");
broadcast.setChannelProperties("abc");
client.send(broadcast);
}
public void sendAndroidUnicast() throws Exception {
AndroidUnicast unicast = new AndroidUnicast(appkey,appMasterSecret);
// TODO Set your device token
unicast.setDeviceToken( "your device_token");
unicast.setTicker( "Android unicast ticker");
unicast.setTitle( "中文的title");
unicast.setText( "Android unicast text");
unicast.goAppAfterOpen();
unicast.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.
unicast.setProductionMode();
// Set customized fields
unicast.setExtraField("test", "helloworld");
unicast.setChannelActivity("your channel activity");
unicast.setChannelProperties("abc");
client.send(unicast);
}
public void sendAndroidGroupcast() throws Exception {
AndroidGroupcast groupcast = new AndroidGroupcast(appkey,appMasterSecret);
/* TODO
* Construct the filter condition:
* "where":
* {
* "and":
* [
* {"tag":"test"},
* {"tag":"Test"}
* ]
* }
*/
JSONObject filterJson = new JSONObject();
JSONObject whereJson = new JSONObject();
JSONArray tagArray = new JSONArray();
JSONObject testTag = new JSONObject();
JSONObject TestTag = new JSONObject();
testTag.put("tag", "test");
TestTag.put("tag", "Test");
tagArray.add(testTag);
tagArray.add(TestTag);
whereJson.put("and", tagArray);
filterJson.put("where", whereJson);
groupcast.setFilter(filterJson); @Autowired
groupcast.setTicker( "Android groupcast ticker"); private PushClient client;
groupcast.setTitle( "中文的title");
groupcast.setText( "Android groupcast text");
groupcast.goAppAfterOpen();
groupcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
groupcast.setChannelActivity("your channel activity");
// TODO Set 'production_mode' to 'false' if it's a test device.
// For how to register a test device, please see the developer doc.
groupcast.setProductionMode();
//厂商通道相关参数
groupcast.setChannelActivity("your channel activity");
groupcast.setChannelProperties("abc");
client.send(groupcast);
}
public void sendAndroidCustomizedcast() 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("你与后台商定的用来区分用户的不能相同的", "可以是写死的别名项目名随意" public void sendAndroidBroadcast() throws Exception {
customizedcast.setAlias("alias", "alias_type"); AndroidBroadcast broadcast = new AndroidBroadcast(appkey, appMasterSecret);
//通知栏提示文字 broadcast.setTicker("Android broadcast ticker");
customizedcast.setTicker( "Android customizedcast ticker"); broadcast.setTitle("中文的title");
//通知标题 broadcast.setText("Android broadcast text");
customizedcast.setTitle( "中文的title"); broadcast.goAppAfterOpen();
//通知文字描述 broadcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
customizedcast.setText( "Android customizedcast text"); // TODO Set 'production_mode' to 'false' if it's a test device.
customizedcast.goAppAfterOpen(); // For how to register a test device, please see the developer doc.
customizedcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION); broadcast.setProductionMode();
// TODO Set 'production_mode' to 'false' if it's a test device. // Set customized fields
// For how to register a test device, please see the developer doc. broadcast.setExtraField("test", "helloworld");
customizedcast.setProductionMode(); //厂商通道相关参数
//厂商通道相关参数 broadcast.setChannelActivity("your channel activity");
customizedcast.setChannelActivity("your channel activity"); broadcast.setChannelProperties("abc");
customizedcast.setChannelProperties("abc"); client.send(broadcast);
client.send(customizedcast); }
}
public void sendAndroidUnicast() throws Exception {
//public void sendAndroidCustomizedcastFile() throws Exception { AndroidUnicast unicast = new AndroidUnicast(appkey, appMasterSecret);
// AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(appkey,appMasterSecret); // TODO Set your device token
// // TODO Set your alias here, and use comma to split them if there are multiple alias. unicast.setDeviceToken("your device_token");
// // And if you have many alias, you can also upload a file containing these alias, then unicast.setTicker("Android unicast ticker");
// // use file_id to send customized notification. unicast.setTitle("中文的title");
// String fileId = client.uploadContents(appkey,appMasterSecret,"aa"+"\n"+"bb"+"\n"+"alias"); unicast.setText("Android unicast text");
// customizedcast.setFileId(fileId, "alias_type"); unicast.goAppAfterOpen();
// customizedcast.setTicker( "Android customizedcast ticker"); unicast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
// customizedcast.setTitle( "中文的title"); // TODO Set 'production_mode' to 'false' if it's a test device.
// customizedcast.setText( "Android customizedcast text"); // For how to register a test device, please see the developer doc.
// customizedcast.goAppAfterOpen(); unicast.setProductionMode();
// customizedcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION); // Set customized fields
// // TODO Set 'production_mode' to 'false' if it's a test device. unicast.setExtraField("test", "helloworld");
// // For how to register a test device, please see the developer doc. unicast.setChannelActivity("your channel activity");
// customizedcast.setProductionMode(); unicast.setChannelProperties("abc");
// //厂商通道相关参数 client.send(unicast);
// customizedcast.setChannelActivity("your channel activity"); }
// customizedcast.setChannelProperties("abc");
// client.send(customizedcast); public void sendAndroidGroupcast() throws Exception {
//} AndroidGroupcast groupcast = new AndroidGroupcast(appkey, appMasterSecret);
// /* TODO
//public void sendAndroidFilecast() throws Exception { * Construct the filter condition:
// AndroidFilecast filecast = new AndroidFilecast(appkey,appMasterSecret); * "where":
// // 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"); * "and":
// filecast.setFileId( fileId); * [
// filecast.setTicker( "Android filecast ticker"); * {"tag":"test"},
// filecast.setTitle( "中文的title"); * {"tag":"Test"}
// filecast.setText( "Android filecast text"); * ]
// filecast.goAppAfterOpen(); * }
// filecast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION); */
// //厂商通道相关参数 JSONObject filterJson = new JSONObject();
// filecast.setChannelActivity("your channel activity"); JSONObject whereJson = new JSONObject();
// filecast.setChannelProperties("abc"); JSONArray tagArray = new JSONArray();
// client.send(filecast); JSONObject testTag = new JSONObject();
//} JSONObject TestTag = new JSONObject();
testTag.put("tag", "test");
public void sendIOSBroadcast() throws Exception { TestTag.put("tag", "Test");
IOSBroadcast broadcast = new IOSBroadcast(appkey,appMasterSecret); tagArray.add(testTag);
tagArray.add(TestTag);
whereJson.put("and", tagArray);
filterJson.put("where", whereJson);
groupcast.setFilter(filterJson);
groupcast.setTicker("Android groupcast ticker");
groupcast.setTitle("中文的title");
groupcast.setText("Android groupcast text");
groupcast.goAppAfterOpen();
groupcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
groupcast.setChannelActivity("your channel activity");
// TODO Set 'production_mode' to 'false' if it's a test device.
// For how to register a test device, please see the developer doc.
groupcast.setProductionMode();
//厂商通道相关参数
groupcast.setChannelActivity("your channel activity");
groupcast.setChannelProperties("abc");
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 {
// 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.
// String fileId = client.uploadContents(appkey,appMasterSecret,"aa"+"\n"+"bb"+"\n"+"alias");
// customizedcast.setFileId(fileId, "alias_type");
// customizedcast.setTicker( "Android customizedcast ticker");
// customizedcast.setTitle( "中文的title");
// customizedcast.setText( "Android customizedcast text");
// 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.
// customizedcast.setProductionMode();
// //厂商通道相关参数
// customizedcast.setChannelActivity("your channel activity");
// customizedcast.setChannelProperties("abc");
// client.send(customizedcast);
//}
//
//public void sendAndroidFilecast() throws Exception {
// AndroidFilecast filecast = new AndroidFilecast(appkey,appMasterSecret);
// // 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");
// filecast.setFileId( fileId);
// filecast.setTicker( "Android filecast ticker");
// filecast.setTitle( "中文的title");
// filecast.setText( "Android filecast text");
// filecast.goAppAfterOpen();
// filecast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
// //厂商通道相关参数
// filecast.setChannelActivity("your channel activity");
// filecast.setChannelProperties("abc");
// client.send(filecast);
//}
public void sendIOSBroadcast() throws Exception {
IOSBroadcast broadcast = new IOSBroadcast(appkey, appMasterSecret);
//alert值设置为字符串
//broadcast.setAlert("IOS 广播测试");
//alert的值设置为字典
broadcast.setAlert("今日天气", "", "今日可能下雨🌂");
broadcast.setBadge(0);
broadcast.setSound("default");
// TODO set 'production_mode' to 'true' if your app is under production mode
broadcast.setTestMode();
// Set customized fields
broadcast.setCustomizedField("test", "helloworld");
client.send(broadcast);
}
public void sendIOSUnicast() throws Exception {
IOSUnicast unicast = new IOSUnicast(appkey, appMasterSecret);
// TODO Set your device token
unicast.setDeviceToken("your device_token");
//alert值设置为字符串 //alert值设置为字符串
//broadcast.setAlert("IOS 广播测试"); //unicast.setAlert("IOS 单播测试");
//alert的值设置为字典 //alert的值设置为字典
broadcast.setAlert("今日天气" , "" , "今日可能下雨🌂"); unicast.setAlert("今日天气", "", "今日可能下雨🌂");
broadcast.setBadge( 0); unicast.setBadge(0);
broadcast.setSound( "default"); unicast.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
broadcast.setTestMode(); unicast.setTestMode();
// Set customized fields // Set customized fields
broadcast.setCustomizedField("test", "helloworld"); unicast.setCustomizedField("test", "helloworld");
client.send(broadcast); client.send(unicast);
} }
public void sendIOSUnicast() throws Exception {
IOSUnicast unicast = new IOSUnicast(appkey,appMasterSecret); public void sendIOSGroupcast() throws Exception {
// TODO Set your device token IOSGroupcast groupcast = new IOSGroupcast(appkey, appMasterSecret);
unicast.setDeviceToken( "your device_token"); /* TODO
//alert值设置为字符串 * Construct the filter condition:
//unicast.setAlert("IOS 单播测试"); * "where":
//alert的值设置为字典 * {
unicast.setAlert("今日天气" , "" , "今日可能下雨🌂"); * "and":
unicast.setBadge( 0); * [
unicast.setSound( "default"); * {"tag":"iostest"}
// TODO set 'production_mode' to 'true' if your app is under production mode * ]
unicast.setTestMode(); * }
// Set customized fields */
unicast.setCustomizedField("test", "helloworld"); JSONObject filterJson = new JSONObject();
client.send(unicast); JSONObject whereJson = new JSONObject();
} JSONArray tagArray = new JSONArray();
JSONObject testTag = new JSONObject();
testTag.put("tag", "iostest");
tagArray.add(testTag);
whereJson.put("and", tagArray);
filterJson.put("where", whereJson);
System.out.println(filterJson.toString());
// Set filter condition into rootJson
groupcast.setFilter(filterJson);
//groupcast.setAlert("IOS 组播测试");
//alert的值设置为字典
groupcast.setAlert("今日天气", "subtitle", "今日可能下雨🌂");
groupcast.setBadge(0);
groupcast.setSound("default");
// TODO set 'production_mode' to 'true' if your app is under production mode
groupcast.setTestMode();
client.send(groupcast);
}
public void sendIOSCustomizedcast() throws Exception {
IOSCustomizedcast customizedcast = new IOSCustomizedcast(appkey, appMasterSecret);
// TODO Set your alias and alias_type 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.
customizedcast.setAlias("alias", "alias_type");
//customizedcast.setAlert("IOS 个性化测试");
//alert的值设置为字典
customizedcast.setAlert("今日天气", "", "今日可能下雨🌂");
customizedcast.setBadge(0);
customizedcast.setSound("default");
// TODO set 'production_mode' to 'true' if your app is under production mode
customizedcast.setTestMode();
client.send(customizedcast);
}
//public void sendIOSFilecast() throws Exception {
public void sendIOSGroupcast() throws Exception { // IOSFilecast filecast = new IOSFilecast(appkey,appMasterSecret);
IOSGroupcast groupcast = new IOSGroupcast(appkey,appMasterSecret); // // TODO upload your device tokens, and use '\n' to split them if there are multiple tokens
/* TODO // String fileId = client.uploadContents(appkey,appMasterSecret,"aa"+"\n"+"bb");
* Construct the filter condition: // filecast.setFileId( fileId);
* "where": // //filecast.setAlert("IOS 文件播测试");
* { // //alert的值设置为字典
* "and": // filecast.setAlert("今日天气" , "" , "今日可能下雨🌂");
* [ // filecast.setBadge( 0);
* {"tag":"iostest"} // filecast.setSound( "default");
* ] // // TODO set 'production_mode' to 'true' if your app is under production mode
* } // filecast.setTestMode();
*/ // client.send(filecast);
JSONObject filterJson = new JSONObject(); //}
JSONObject whereJson = new JSONObject();
JSONArray tagArray = new JSONArray();
JSONObject testTag = new JSONObject();
testTag.put("tag", "iostest");
tagArray.add(testTag);
whereJson.put("and", tagArray);
filterJson.put("where", whereJson);
System.out.println(filterJson.toString());
// Set filter condition into rootJson
groupcast.setFilter(filterJson);
//groupcast.setAlert("IOS 组播测试");
//alert的值设置为字典
groupcast.setAlert("今日天气" , "subtitle" , "今日可能下雨🌂");
groupcast.setBadge( 0);
groupcast.setSound( "default");
// TODO set 'production_mode' to 'true' if your app is under production mode
groupcast.setTestMode();
client.send(groupcast);
}
public void sendIOSCustomizedcast() throws Exception {
IOSCustomizedcast customizedcast = new IOSCustomizedcast(appkey,appMasterSecret);
// TODO Set your alias and alias_type 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.
customizedcast.setAlias("alias", "alias_type");
//customizedcast.setAlert("IOS 个性化测试");
//alert的值设置为字典
customizedcast.setAlert("今日天气" , "" , "今日可能下雨🌂");
customizedcast.setBadge( 0);
customizedcast.setSound( "default");
// TODO set 'production_mode' to 'true' if your app is under production mode
customizedcast.setTestMode();
client.send(customizedcast);
}
//public void sendIOSFilecast() throws Exception {
// IOSFilecast filecast = new IOSFilecast(appkey,appMasterSecret);
// // 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");
// filecast.setFileId( fileId);
// //filecast.setAlert("IOS 文件播测试");
// //alert的值设置为字典
// filecast.setAlert("今日天气" , "" , "今日可能下雨🌂");
// filecast.setBadge( 0);
// filecast.setSound( "default");
// // TODO set 'production_mode' to 'true' if your app is under production mode
// filecast.setTestMode();
// client.send(filecast);
//}
} }
...@@ -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!