阿里云推送优化
This commit is contained in:
parent
9f2f861d28
commit
f1f0080537
|
|
@ -29,6 +29,11 @@ public class TblAliyunDeviceInfo {
|
|||
*/
|
||||
private Integer userId;
|
||||
|
||||
/**
|
||||
* 手机类型
|
||||
*/
|
||||
private String phoneType;
|
||||
|
||||
/**
|
||||
* 绑定时间
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -12,11 +12,9 @@ import com.ifish7.mq.business.user.entity.TblPushList;
|
|||
import com.ifish7.mq.business.user.service.ITblAliyunDeviceInfoService;
|
||||
import com.ifish7.mq.business.user.service.ITblPushListService;
|
||||
import lombok.extern.log4j.Log4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -37,8 +35,12 @@ public class AliyunPushApi {
|
|||
private static final String TARGET_TYPE = "DEVICE";
|
||||
//推送类型
|
||||
private static final String PUSH_TYPE = "NOTICE";
|
||||
//推送类型 ALL
|
||||
private static final String PHONE_TYPE = "ALL";
|
||||
|
||||
@Value("${android_app_key}")
|
||||
private String androidAppKey;
|
||||
|
||||
@Value("${ios_app_key}")
|
||||
private String iosAppKey;
|
||||
|
||||
@Autowired
|
||||
private PushRequest pushRequest;
|
||||
|
|
@ -56,9 +58,14 @@ public class AliyunPushApi {
|
|||
|
||||
//根据Target来设定,多个值使用逗号分隔
|
||||
//此处应该查询出用户所对应的deviceId ★★★★★
|
||||
String deviceIds = getUserDevices(String.valueOf(pushList.getUserId()));
|
||||
//如果次用户未绑定设备 不推送
|
||||
if (StringUtils.isNotBlank(deviceIds)) {
|
||||
// String deviceIds = getUserDevices(String.valueOf(pushList.getUserId()));
|
||||
List<TblAliyunDeviceInfo> pushUserDevices = aliyunDeviceInfoService.list(new QueryWrapper<TblAliyunDeviceInfo>().lambda().eq(TblAliyunDeviceInfo::getUserId, pushList.getUserId()));
|
||||
pushUserDevices.forEach(aliyunDeviceInfo -> {
|
||||
if ("iOS".equals(aliyunDeviceInfo.getPhoneType())) {
|
||||
pushRequest.setAppKey(Long.parseLong(iosAppKey));
|
||||
} else {
|
||||
pushRequest.setAppKey(Long.parseLong(androidAppKey));
|
||||
}
|
||||
//推送目标:
|
||||
//DEVICE:根据设备推送
|
||||
//ACCOUNT:根据账号推送
|
||||
|
|
@ -68,11 +75,11 @@ public class AliyunPushApi {
|
|||
pushRequest.setTarget(TARGET_TYPE);
|
||||
//响应数据
|
||||
pushRequest.setAcceptFormat(FormatType.JSON);
|
||||
pushRequest.setTargetValue(deviceIds);
|
||||
pushRequest.setTargetValue(aliyunDeviceInfo.getAliyunDeviceId());
|
||||
//推送类型
|
||||
pushRequest.setPushType(PUSH_TYPE);
|
||||
//推送设备类型
|
||||
pushRequest.setDeviceType(pushList.getPhoneType().toUpperCase().equals("IOS") ? "iOS" : pushList.getPhoneType().toUpperCase());
|
||||
pushRequest.setDeviceType(aliyunDeviceInfo.getPhoneType());
|
||||
// 消息的标题
|
||||
pushRequest.setTitle(pushList.getPushTitle());
|
||||
// 消息的内容
|
||||
|
|
@ -95,19 +102,6 @@ public class AliyunPushApi {
|
|||
} catch (ClientException e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
} else {
|
||||
log.info(String.format("user : '%s' not bind device ",pushList.getUserId()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String getUserDevices(String userId){
|
||||
//查询出userId所对应的所有的deviceId
|
||||
List<TblAliyunDeviceInfo> pushUserDevices = aliyunDeviceInfoService.list(new QueryWrapper<TblAliyunDeviceInfo>().lambda().eq(TblAliyunDeviceInfo::getUserId, userId));
|
||||
StringBuilder deviceIds = new StringBuilder();
|
||||
for (TblAliyunDeviceInfo aliyunDeviceInfo : pushUserDevices) {
|
||||
deviceIds.append(aliyunDeviceInfo.getAliyunDeviceId()).append(",");
|
||||
}
|
||||
return deviceIds.toString();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#broker_url=tcp://test.ifish7.com:61616
|
||||
broker_url=tcp://www.ifish7.com:61616
|
||||
broker_url=tcp://localhost:61616
|
||||
username=admin
|
||||
#password=admin
|
||||
password=adminifish7
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
accessKeyId= LTAIfZaosFH5IWlD
|
||||
accessKeySecret = dvlE8eFii31BcGb8HzkGz3eSaJ6Y94
|
||||
appKey = 26023230
|
||||
android_app_key = 26023230
|
||||
ios_app_key = 26023230
|
||||
#\u76EE\u524D\u8BE5\u503C\u56FA\u5B9A\uFF0C\u4E0D\u7528\u52A8
|
||||
regionId = cn-hangzhou
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
<bean id="app" class="com.ifish7.mq.utils.AppBeans" />
|
||||
|
||||
<bean id="push" class="com.aliyuncs.push.model.v20160801.PushRequest" scope="prototype">
|
||||
<property name="appKey" value="${appKey}" />
|
||||
<property name="sysProtocol" value="${protocol}" />
|
||||
<property name="sysMethod" value="${method}" />
|
||||
<property name="storeOffline" value="${storeOffline}" />
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class AliyunPushApiTest {
|
|||
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAIfZaosFH5IWlD", "dvlE8eFii31BcGb8HzkGz3eSaJ6Y94");
|
||||
DefaultAcsClient client = new DefaultAcsClient(profile);
|
||||
PushRequest pushRequest = new PushRequest();
|
||||
pushRequest.setAppKey(26023230l);
|
||||
pushRequest.setAppKey(26007228l);
|
||||
pushRequest.setSysProtocol(ProtocolType.HTTPS);
|
||||
pushRequest.setSysMethod(MethodType.POST);
|
||||
pushRequest.setStoreOffline(true);
|
||||
|
|
@ -45,11 +45,11 @@ public class AliyunPushApiTest {
|
|||
pushRequest.setAcceptFormat(FormatType.JSON);
|
||||
//根据Target来设定,多个值使用逗号分隔
|
||||
//此处应该查询出用户所对应的deviceId ★★★★★
|
||||
pushRequest.setTargetValue("bfde2078565a434aa6636419347fcd33,39a5f06b94324eef87e5665653b42367");
|
||||
pushRequest.setTargetValue("97e7cbda2a5d40b0af79b5f9aa49ddd3");
|
||||
//推送类型
|
||||
pushRequest.setPushType("NOTICE");
|
||||
//推送设备类型
|
||||
pushRequest.setDeviceType("ALL");
|
||||
pushRequest.setDeviceType("iOS");
|
||||
// 消息的标题
|
||||
pushRequest.setTitle("温度报警");
|
||||
// 消息的内容
|
||||
|
|
|
|||
Loading…
Reference in New Issue