阿里云推送
This commit is contained in:
parent
22aa395392
commit
cec82bbf33
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.ifish7.mq.business.user.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author yan.y
|
||||||
|
* @since 2019-05-28
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class TblAliyunDeviceInfo {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备ID
|
||||||
|
*/
|
||||||
|
private String aliyunDeviceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户ID
|
||||||
|
*/
|
||||||
|
private Integer userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime bindTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最后更新时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime lastUpdateTime;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
package com.ifish7.mq.business.user.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import java.time.LocalTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
*
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author yan.y
|
|
||||||
* @since 2019-04-13
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
@TableName("tbl_push_user_device")
|
|
||||||
public class TblPushUserDevice {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主键
|
|
||||||
*/
|
|
||||||
private Integer pushId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户ID
|
|
||||||
*/
|
|
||||||
private Integer pushUserId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设备ID
|
|
||||||
*/
|
|
||||||
private String pushDeviceId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设备绑定时间
|
|
||||||
*/
|
|
||||||
private LocalTime pushBindTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设备绑定类型
|
|
||||||
*/
|
|
||||||
private String pushBindType;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.ifish7.mq.business.user.mapper;
|
||||||
|
|
||||||
|
import com.ifish7.mq.business.user.entity.TblAliyunDeviceInfo;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author yan.y
|
||||||
|
* @since 2019-05-28
|
||||||
|
*/
|
||||||
|
public interface TblAliyunDeviceInfoMapper extends BaseMapper<TblAliyunDeviceInfo> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
package com.ifish7.mq.business.user.mapper;
|
|
||||||
|
|
||||||
import com.ifish7.mq.business.user.entity.TblPushUserDevice;
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Mapper 接口
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author yan.y
|
|
||||||
* @since 2019-04-13
|
|
||||||
*/
|
|
||||||
public interface TblPushUserDeviceMapper extends BaseMapper<TblPushUserDevice> {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.ifish7.mq.business.user.service;
|
||||||
|
|
||||||
|
import com.ifish7.mq.business.user.entity.TblAliyunDeviceInfo;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author yan.y
|
||||||
|
* @since 2019-05-28
|
||||||
|
*/
|
||||||
|
public interface ITblAliyunDeviceInfoService extends IService<TblAliyunDeviceInfo> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
package com.ifish7.mq.business.user.service;
|
|
||||||
|
|
||||||
import com.ifish7.mq.business.user.entity.TblPushUserDevice;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 服务类
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author yan.y
|
|
||||||
* @since 2019-04-13
|
|
||||||
*/
|
|
||||||
public interface ITblPushUserDeviceService extends IService<TblPushUserDevice> {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.ifish7.mq.business.user.service.impl;
|
||||||
|
|
||||||
|
import com.ifish7.mq.business.user.entity.TblAliyunDeviceInfo;
|
||||||
|
import com.ifish7.mq.business.user.mapper.TblAliyunDeviceInfoMapper;
|
||||||
|
import com.ifish7.mq.business.user.service.ITblAliyunDeviceInfoService;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务实现类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author yan.y
|
||||||
|
* @since 2019-05-28
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class TblAliyunDeviceInfoServiceImpl extends ServiceImpl<TblAliyunDeviceInfoMapper, TblAliyunDeviceInfo> implements ITblAliyunDeviceInfoService {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -7,16 +7,16 @@ import com.aliyuncs.profile.DefaultProfile;
|
||||||
import com.aliyuncs.push.model.v20160801.PushRequest;
|
import com.aliyuncs.push.model.v20160801.PushRequest;
|
||||||
import com.aliyuncs.push.model.v20160801.PushResponse;
|
import com.aliyuncs.push.model.v20160801.PushResponse;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.ifish7.mq.business.user.entity.TblAliyunDeviceInfo;
|
||||||
import com.ifish7.mq.business.user.entity.TblPushList;
|
import com.ifish7.mq.business.user.entity.TblPushList;
|
||||||
import com.ifish7.mq.business.user.entity.TblPushUserDevice;
|
import com.ifish7.mq.business.user.service.ITblAliyunDeviceInfoService;
|
||||||
import com.ifish7.mq.business.user.entity.TblUser;
|
|
||||||
import com.ifish7.mq.business.user.service.ITblPushListService;
|
import com.ifish7.mq.business.user.service.ITblPushListService;
|
||||||
import com.ifish7.mq.business.user.service.ITblPushUserDeviceService;
|
|
||||||
import com.ifish7.mq.business.user.service.ITblUserService;
|
|
||||||
import lombok.extern.log4j.Log4j;
|
import lombok.extern.log4j.Log4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -46,11 +46,11 @@ public class AliyunPushApi {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ITblPushListService pushListService;
|
private ITblPushListService pushListService;
|
||||||
|
|
||||||
@Autowired
|
// @Autowired
|
||||||
private ITblUserService userService;
|
// private ITblUserService userService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ITblPushUserDeviceService pushUserDeviceService;
|
private ITblAliyunDeviceInfoService aliyunDeviceInfoService;
|
||||||
|
|
||||||
public void advancedPush(TblPushList pushList){
|
public void advancedPush(TblPushList pushList){
|
||||||
|
|
||||||
|
|
@ -72,7 +72,7 @@ public class AliyunPushApi {
|
||||||
//推送类型
|
//推送类型
|
||||||
pushRequest.setPushType(PUSH_TYPE);
|
pushRequest.setPushType(PUSH_TYPE);
|
||||||
//推送设备类型
|
//推送设备类型
|
||||||
pushRequest.setDeviceType(PHONE_TYPE);
|
pushRequest.setDeviceType(pushList.getPhoneType().toUpperCase().equals("IOS") ? "iOS" : pushList.getPhoneType().toUpperCase());
|
||||||
// 消息的标题
|
// 消息的标题
|
||||||
pushRequest.setTitle(pushList.getPushTitle());
|
pushRequest.setTitle(pushList.getPushTitle());
|
||||||
// 消息的内容
|
// 消息的内容
|
||||||
|
|
@ -83,13 +83,14 @@ public class AliyunPushApi {
|
||||||
//android通知设置
|
//android通知设置
|
||||||
pushRequest.setAndroidOpenType("APPLICATION");
|
pushRequest.setAndroidOpenType("APPLICATION");
|
||||||
pushRequest.setAndroidNotifyType("BOTH");
|
pushRequest.setAndroidNotifyType("BOTH");
|
||||||
pushRequest.setAndroidNotificationChannel("1");
|
// pushRequest.setAndroidNotificationChannel("1");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PushResponse response = client.getAcsResponse(pushRequest);
|
PushResponse response = client.getAcsResponse(pushRequest);
|
||||||
pushList.setReportId(Integer.parseInt(response.getMessageId()));
|
pushList.setReportId(Integer.parseInt(response.getMessageId()));
|
||||||
//未读
|
//未读
|
||||||
pushList.setIsRead(1);
|
pushList.setIsRead(1);
|
||||||
|
pushList.setDeviceId(pushList.getDeviceId() == 0 ? null : pushList.getDeviceId());
|
||||||
pushListService.save(pushList);
|
pushListService.save(pushList);
|
||||||
} catch (ClientException e) {
|
} catch (ClientException e) {
|
||||||
log.error(e.getMessage(),e);
|
log.error(e.getMessage(),e);
|
||||||
|
|
@ -102,10 +103,10 @@ public class AliyunPushApi {
|
||||||
|
|
||||||
private String getUserDevices(String userId){
|
private String getUserDevices(String userId){
|
||||||
//查询出userId所对应的所有的deviceId
|
//查询出userId所对应的所有的deviceId
|
||||||
List<TblPushUserDevice> pushUserDevices = pushUserDeviceService.list(new QueryWrapper<TblPushUserDevice>().lambda().eq(TblPushUserDevice::getPushUserId, userId));
|
List<TblAliyunDeviceInfo> pushUserDevices = aliyunDeviceInfoService.list(new QueryWrapper<TblAliyunDeviceInfo>().lambda().eq(TblAliyunDeviceInfo::getUserId, userId));
|
||||||
StringBuilder deviceIds = new StringBuilder();
|
StringBuilder deviceIds = new StringBuilder();
|
||||||
for (TblPushUserDevice pushUserDevice : pushUserDevices) {
|
for (TblAliyunDeviceInfo aliyunDeviceInfo : pushUserDevices) {
|
||||||
deviceIds.append(pushUserDevice.getPushDeviceId()).append(",");
|
deviceIds.append(aliyunDeviceInfo.getAliyunDeviceId()).append(",");
|
||||||
}
|
}
|
||||||
return deviceIds.toString();
|
return deviceIds.toString();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
jdbc.driver=com.mysql.jdbc.Driver
|
jdbc.driver=com.mysql.jdbc.Driver
|
||||||
#jdbc.url=jdbc\:mysql\://localhost\:3306/myfishdb?characterEncoding\=UTF-8
|
jdbc.url=jdbc\:mysql\://localhost\:3306/myfishdb?characterEncoding\=UTF-8
|
||||||
jdbc.url=jdbc\:mysql\://139.196.24.156\:3306/myfishdb?characterEncoding\=UTF-8
|
#jdbc.url=jdbc\:mysql\://139.196.24.156\:3306/myfishdb?characterEncoding\=UTF-8
|
||||||
#jdbc.username=root
|
#jdbc.username=root
|
||||||
#jdbc.password=123456
|
#jdbc.password=123456
|
||||||
#jdbc.username=ifish
|
jdbc.username=ifish
|
||||||
#jdbc.password=ifish7pwd
|
jdbc.password=ifish7pwd
|
||||||
jdbc.username=root
|
#jdbc.username=root
|
||||||
jdbc.password=ifish7mysql
|
#jdbc.password=ifish7mysql
|
||||||
#jdbc.testWhileIdle=true
|
#jdbc.testWhileIdle=true
|
||||||
jdbc.validationQuery=SELECT * FROM DUAL
|
jdbc.validationQuery=SELECT * FROM DUAL
|
||||||
initialSize=1
|
initialSize=1
|
||||||
|
|
|
||||||
|
|
@ -16,4 +16,6 @@ log4j.appender.File.Threshold = ALL
|
||||||
log4j.appender.File.layout = org.apache.log4j.PatternLayout
|
log4j.appender.File.layout = org.apache.log4j.PatternLayout
|
||||||
log4j.appender.File.layout.ConversionPattern =[ifishMQ][%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n
|
log4j.appender.File.layout.ConversionPattern =[ifishMQ][%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n
|
||||||
|
|
||||||
|
log4j.logger.org.springframework=INFO
|
||||||
log4j.logger.org.apache.activemq=INFO
|
log4j.logger.org.apache.activemq=INFO
|
||||||
|
log4j.logger.org.apache.http=INFO
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.ifish7.mq.business.device.mapper.TblDeviceHeaterMapper">
|
|
||||||
|
|
||||||
</mapper>
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.ifish7.mq.business.device.mapper.TblDeviceMapper">
|
|
||||||
|
|
||||||
</mapper>
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.ifish7.mq.business.device.mapper.TblFactoryHardwareMapper">
|
|
||||||
|
|
||||||
</mapper>
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.ifish7.mq.business.device.mapper.TblFactoryListMapper">
|
|
||||||
|
|
||||||
</mapper>
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.ifish7.mq.business.device.mapper.TblHardwareTypeMapper">
|
|
||||||
|
|
||||||
</mapper>
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.ifish7.mq.business.device.mapper.TblLoginRecordMapper">
|
|
||||||
|
|
||||||
</mapper>
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.ifish7.mq.business.user.mapper.TblDeviceUserMapper">
|
|
||||||
|
|
||||||
</mapper>
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.ifish7.mq.business.user.mapper.TblPushListMapper">
|
|
||||||
|
|
||||||
</mapper>
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.ifish7.mq.business.user.mapper.TblPushUserDeviceMapper">
|
|
||||||
|
|
||||||
</mapper>
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.ifish7.mq.business.user.mapper.TblUserMapper">
|
|
||||||
|
|
||||||
</mapper>
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
broker_url=tcp://test.ifish7.com:61616
|
#broker_url=tcp://test.ifish7.com:61616
|
||||||
|
broker_url=tcp://www.ifish7.com:61616
|
||||||
username=admin
|
username=admin
|
||||||
#password=admin
|
#password=admin
|
||||||
password=adminifish7
|
password=adminifish7
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,11 @@ public class AliyunPushApiTest {
|
||||||
pushRequest.setAcceptFormat(FormatType.JSON);
|
pushRequest.setAcceptFormat(FormatType.JSON);
|
||||||
//根据Target来设定,多个值使用逗号分隔
|
//根据Target来设定,多个值使用逗号分隔
|
||||||
//此处应该查询出用户所对应的deviceId ★★★★★
|
//此处应该查询出用户所对应的deviceId ★★★★★
|
||||||
pushRequest.setTargetValue("c17c0590e8254b6b977b8fd7706fa8c2");
|
pushRequest.setTargetValue("bfde2078565a434aa6636419347fcd33,39a5f06b94324eef87e5665653b42367");
|
||||||
//推送类型
|
//推送类型
|
||||||
pushRequest.setPushType("NOTICE");
|
pushRequest.setPushType("NOTICE");
|
||||||
//推送设备类型
|
//推送设备类型
|
||||||
pushRequest.setDeviceType("ANDROID");
|
pushRequest.setDeviceType("ALL");
|
||||||
// 消息的标题
|
// 消息的标题
|
||||||
pushRequest.setTitle("温度报警");
|
pushRequest.setTitle("温度报警");
|
||||||
// 消息的内容
|
// 消息的内容
|
||||||
|
|
@ -59,10 +59,10 @@ public class AliyunPushApiTest {
|
||||||
pushRequest.setAndroidNotifyType("BOTH");//通知的提醒方式 "VIBRATE" : 震动 "SOUND" : 声音 "BOTH" : 声音和震动 NONE : 静音
|
pushRequest.setAndroidNotifyType("BOTH");//通知的提醒方式 "VIBRATE" : 震动 "SOUND" : 声音 "BOTH" : 声音和震动 NONE : 静音
|
||||||
pushRequest.setAndroidOpenType("APPLICATION"); //点击通知后动作 "APPLICATION" : 打开应用 "ACTIVITY" : 打开AndroidActivity "URL" : 打开URL "NONE" : 无跳转
|
pushRequest.setAndroidOpenType("APPLICATION"); //点击通知后动作 "APPLICATION" : 打开应用 "ACTIVITY" : 打开AndroidActivity "URL" : 打开URL "NONE" : 无跳转
|
||||||
// 指定notificaitonchannel id
|
// 指定notificaitonchannel id
|
||||||
pushRequest.setAndroidNotificationChannel("1");
|
// pushRequest.setAndroidNotificationChannel("1");
|
||||||
try {
|
try {
|
||||||
PushResponse response = client.getAcsResponse(pushRequest);
|
PushResponse response = client.getAcsResponse(pushRequest);
|
||||||
log.info(response);
|
log.info(response.getMessageId());
|
||||||
} catch (ClientException e) {
|
} catch (ClientException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue