登陆,极光推送修改
This commit is contained in:
parent
28bd9d64f7
commit
22712b91c4
|
|
@ -5,10 +5,75 @@
|
|||
*/
|
||||
package com.ifish.API;
|
||||
|
||||
import cn.jpush.api.JPushClient;
|
||||
import cn.jpush.api.push.PushResult;
|
||||
import cn.jpush.api.push.model.Platform;
|
||||
import cn.jpush.api.push.model.PushPayload;
|
||||
import cn.jpush.api.push.model.audience.Audience;
|
||||
import cn.jpush.api.push.model.notification.Notification;
|
||||
import java.util.Map;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
@Component
|
||||
public class JiGuangPush {
|
||||
|
||||
|
||||
private static JPushClient jPushClient = null;
|
||||
//正式
|
||||
// private static final String masterSecret = "60162c8cf195ce9f4dc76629";
|
||||
// private static final String appKey = "d970d5e193cb2a0bbe41653c";
|
||||
//测试
|
||||
private final static String masterSecret = "4f759a0609dcd9d2edb06125";
|
||||
private final static String appKey = "6e5e9d757570859b3f274bb8";
|
||||
|
||||
static {
|
||||
jPushClient = new JPushClient(masterSecret, appKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向安卓手机推送一条信息
|
||||
*
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
public boolean pushMessageByAndroid(String title, String message, String userId, Map map) {
|
||||
try {
|
||||
PushPayload payload = PushPayload.newBuilder()
|
||||
.setPlatform(Platform.android())
|
||||
.setAudience(Audience.alias(userId))
|
||||
.setNotification(Notification.android(title, message, map))
|
||||
.build();
|
||||
|
||||
PushResult result = jPushClient.sendPush(payload);
|
||||
if (result.msg_id > 0 && result.isResultOK()) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean pushMessageByIOS(String title, String message, String userId, Map map) {
|
||||
try {
|
||||
PushPayload payload = PushPayload.newBuilder()
|
||||
.setPlatform(Platform.ios())
|
||||
.setAudience(Audience.alias(userId))
|
||||
.setNotification(Notification.ios(message, map))
|
||||
.build();
|
||||
|
||||
PushResult result = jPushClient.sendPush(payload);
|
||||
if (result.msg_id > 0 && result.isResultOK()) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String b = e.getMessage();
|
||||
String a = "";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class Device {
|
|||
* @param macAddress
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/bindDevice.do", method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/bindDevice.do", method = RequestMethod.GET)
|
||||
public Object bindDevice(Integer userId, String macAddress) {
|
||||
try {
|
||||
return deviceHelperI.bindDevice(userId, macAddress);
|
||||
|
|
|
|||
|
|
@ -6,10 +6,7 @@
|
|||
package com.ifish.controller;
|
||||
|
||||
import com.ifish.bean.Tbl_User;
|
||||
import com.ifish.enums.ResultEnum;
|
||||
import com.ifish.helper.UserHelperI;
|
||||
import com.ifish.util.IfishUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -87,8 +84,8 @@ public class Login {
|
|||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/touristLogin.do", method = RequestMethod.POST)
|
||||
public Object touristLogin() {
|
||||
return userHelperI.touristRegister();
|
||||
public Object touristLogin(String loginType) {
|
||||
return userHelperI.touristRegister(loginType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@
|
|||
*/
|
||||
package com.ifish.helper;
|
||||
|
||||
import com.ifish.API.JiGuangPush;
|
||||
import com.ifish.bean.Tbl_Activa_Code;
|
||||
import com.ifish.bean.Tbl_Device;
|
||||
import com.ifish.bean.Tbl_Device_Statistics;
|
||||
import com.ifish.bean.Tbl_Device_User;
|
||||
import com.ifish.bean.Tbl_Push_List;
|
||||
import com.ifish.bean.Tbl_User;
|
||||
import com.ifish.enums.PushTypeEnum;
|
||||
import com.ifish.enums.ResultEnum;
|
||||
|
|
@ -28,16 +30,16 @@ import org.springframework.stereotype.Component;
|
|||
*/
|
||||
@Component
|
||||
public class DeviceHelper implements DeviceHelperI {
|
||||
|
||||
|
||||
@Autowired
|
||||
private RedisHelperI redisHelperI;
|
||||
|
||||
|
||||
@Autowired
|
||||
private RedisKeyHelperI redisKeyHelperI;
|
||||
|
||||
|
||||
@Autowired
|
||||
private Tbl_Device_Mapper tbl_Device_Mapper;
|
||||
|
||||
|
||||
@Autowired
|
||||
private UserHelperI userHelperI;
|
||||
|
||||
|
|
@ -204,7 +206,7 @@ public class DeviceHelper implements DeviceHelperI {
|
|||
*/
|
||||
@Override
|
||||
public Object bindDevice(Integer userId, String mackAddress) {
|
||||
|
||||
|
||||
try {
|
||||
Tbl_User tmpUser = userHelperI.getUserById(userId);
|
||||
//用户存在
|
||||
|
|
@ -226,7 +228,7 @@ public class DeviceHelper implements DeviceHelperI {
|
|||
if (tmpDdeviceUser != null) {
|
||||
//原先不是主控制,则删除其他用户关联关系
|
||||
if (!tmpDdeviceUser.getIsMaster().equals("1")) {
|
||||
|
||||
|
||||
for (Tbl_Device_User du : deviceUserList) {
|
||||
Integer userid = du.getUserId();
|
||||
Integer deviceId = du.getDeviceId();
|
||||
|
|
@ -249,7 +251,7 @@ public class DeviceHelper implements DeviceHelperI {
|
|||
jPushNotifcation(baseMap, pushMap);
|
||||
}
|
||||
tbl_Device_Mapper.deleteDeviceUserById(du.getId());
|
||||
|
||||
redisKeyHelperI.deleteRedisByTbl_Device_User(tmpDdeviceUser);
|
||||
}
|
||||
}
|
||||
//变更为主控
|
||||
|
|
@ -258,7 +260,7 @@ public class DeviceHelper implements DeviceHelperI {
|
|||
tmpDdeviceUser.setUpdateTime(date);
|
||||
tmpDdeviceUser.setCreateTime(date);
|
||||
tbl_Device_Mapper.updateTblDeviceUser(tmpDdeviceUser);
|
||||
|
||||
redisKeyHelperI.deleteRedisByTbl_Device_User(tmpDdeviceUser);
|
||||
deviceUser.setShowName(tmpDdeviceUser.getShowName());
|
||||
deviceUser.setIsMaster(tmpDdeviceUser.getIsMaster());
|
||||
} //未绑定过
|
||||
|
|
@ -286,6 +288,7 @@ public class DeviceHelper implements DeviceHelperI {
|
|||
jPushNotifcation(baseMap, pushMap);
|
||||
}
|
||||
tbl_Device_Mapper.deleteDeviceUserById(du.getId());
|
||||
redisKeyHelperI.deleteRedisByTbl_Device_User(du);
|
||||
}
|
||||
//需要新增
|
||||
bln = true;
|
||||
|
|
@ -309,6 +312,7 @@ public class DeviceHelper implements DeviceHelperI {
|
|||
//修改设备统计信息
|
||||
ds.setFirstActivate(new Date());
|
||||
tbl_Device_Mapper.updateDeviceStatistics(ds);
|
||||
redisKeyHelperI.deleteRedisByTbl_Device_Statistics(ds);
|
||||
}
|
||||
}
|
||||
} //设备不存在
|
||||
|
|
@ -434,7 +438,7 @@ public class DeviceHelper implements DeviceHelperI {
|
|||
camera.setActiveTime(date);
|
||||
camera.setUpdateTime(date);
|
||||
int i = tbl_Device_Mapper.updateTbl_Device(camera);
|
||||
|
||||
|
||||
activa_Code.setIsUsed("1");
|
||||
tbl_Device_Mapper.updateTblActivaCodeIsUse(activeCode);
|
||||
return IfishUtil.returnJson(ResultEnum.success.getKey(), "");
|
||||
|
|
@ -460,10 +464,10 @@ public class DeviceHelper implements DeviceHelperI {
|
|||
*/
|
||||
@Override
|
||||
public Object updateDeviceUser(Tbl_Device_User device) {
|
||||
|
||||
|
||||
try {
|
||||
Tbl_Device_User olDevice_User = getDeviceUserByUserId_DeviceId(device.getUserId(), device.getDeviceId());
|
||||
|
||||
|
||||
if (device != null) {
|
||||
if (olDevice_User != null) {
|
||||
device.setId(olDevice_User.getId());
|
||||
|
|
@ -496,7 +500,7 @@ public class DeviceHelper implements DeviceHelperI {
|
|||
Tbl_Device_User olDevice_User = getDeviceUserByUserId_CameraId(device_User.getUserId(), cameraId.toString());
|
||||
if (olDevice_User != null) {
|
||||
if (olDevice_User != null) {
|
||||
|
||||
|
||||
device_User.setId(olDevice_User.getId());
|
||||
int i = tbl_Device_Mapper.updateTblDeviceUser(device_User);
|
||||
if (i > 0) {
|
||||
|
|
@ -567,6 +571,12 @@ public class DeviceHelper implements DeviceHelperI {
|
|||
}
|
||||
return IfishUtil.returnJson(ResultEnum.fail101.getKey(), "");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private JiGuangPush jiGuangPush;
|
||||
|
||||
@Autowired
|
||||
private PushMessageHelperI pushMessageHelperI;
|
||||
|
||||
/**
|
||||
* 极光推送
|
||||
|
|
@ -575,7 +585,52 @@ public class DeviceHelper implements DeviceHelperI {
|
|||
*/
|
||||
public boolean jPushNotifcation(Map<String, String> baseMap, Map<String, String> pushMap) {
|
||||
try {
|
||||
|
||||
//登录类型
|
||||
String loginType = baseMap.get("loginType");
|
||||
if (loginType != null) {
|
||||
//推送消息类型
|
||||
String msgType = pushMap.get("msg_type");
|
||||
String userId = baseMap.get("user_id");
|
||||
String title = baseMap.get("title");
|
||||
String content = baseMap.get("content");
|
||||
boolean result = false;
|
||||
if (loginType.equals("ios")) {
|
||||
result = jiGuangPush.pushMessageByIOS(title, content, userId, pushMap);
|
||||
} else if (loginType.equals("android")) {
|
||||
result = jiGuangPush.pushMessageByAndroid(title, content, userId, pushMap);
|
||||
}
|
||||
//推送记录
|
||||
Tbl_Push_List pushList = new Tbl_Push_List();
|
||||
if (msgType.equals(PushTypeEnum.remove_device.getKey())) {
|
||||
pushList.setUserId(Integer.valueOf(userId));
|
||||
pushList.setDeviceId(Integer.valueOf(pushMap.get("device_id")));
|
||||
pushList.setPhoneType(loginType);
|
||||
pushList.setShowName(pushMap.get("showName"));
|
||||
pushList.setPushType(msgType);
|
||||
pushList.setPushTitle(title);
|
||||
pushList.setPushContext(content);
|
||||
pushList.setJpushStatus(result ? "1" : "0");
|
||||
pushList.setCreateTime(new Date());
|
||||
pushMessageHelperI.save(pushList);
|
||||
return true;
|
||||
} //发送看护报告推送
|
||||
else if (msgType.equals(PushTypeEnum.send_report.getKey())) {
|
||||
String reportId = baseMap.get("reportId");
|
||||
if (reportId != null) {
|
||||
pushList.setReportId(Integer.valueOf(reportId));
|
||||
}
|
||||
pushList.setUserId(Integer.valueOf(userId));
|
||||
pushList.setPhoneType(loginType);
|
||||
pushList.setPushType(msgType);
|
||||
pushList.setPushTitle(title);
|
||||
pushList.setPushContext(content);
|
||||
pushList.setPushLink(pushMap.get("push_link"));
|
||||
pushList.setJpushStatus(result ? "1" : "0");
|
||||
pushList.setCreateTime(new Date());
|
||||
pushMessageHelperI.save(pushList);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,4 +109,18 @@ public class PushMessageHelper implements PushMessageHelperI {
|
|||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tbl_Push_List save(Tbl_Push_List pushList) {
|
||||
try {
|
||||
int i = tbl_Push_List_Mapper.saveTbl_Push_List(pushList);
|
||||
if (i > 0) {
|
||||
return pushList;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
*/
|
||||
package com.ifish.helper;
|
||||
|
||||
import com.ifish.bean.Tbl_Push_List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Administrator
|
||||
|
|
@ -30,4 +32,6 @@ public interface PushMessageHelperI {
|
|||
* @return
|
||||
*/
|
||||
Object deletePushList(Integer userId, Integer pushId);
|
||||
|
||||
Tbl_Push_List save(Tbl_Push_List pushList);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,10 @@ public class UserHelper implements UserHelperI {
|
|||
public Object login(Tbl_User user) {
|
||||
try {
|
||||
Tbl_User tmpUser = null;
|
||||
//登陆手机类型为空,返回参数错误
|
||||
if (StringUtils.isBlank(user.getLoginType())) {
|
||||
return IfishUtil.returnJson(ResultEnum.error401.getKey(), "");
|
||||
}
|
||||
//如果用户手机不为空,进行手机登陆
|
||||
if (StringUtils.isNotBlank(user.getPhoneNumber())) {
|
||||
tmpUser = tbl_User_Mapper.getUserByPhoneNumber(user.getPhoneNumber());
|
||||
|
|
@ -93,7 +97,7 @@ public class UserHelper implements UserHelperI {
|
|||
if (tmpUser != null) {
|
||||
return touristLogin(tmpUser);
|
||||
} else {
|
||||
return touristRegister();
|
||||
return touristRegister(user.getLoginType());
|
||||
}
|
||||
}
|
||||
//密码不正确
|
||||
|
|
@ -319,9 +323,13 @@ public class UserHelper implements UserHelperI {
|
|||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Object touristRegister() {
|
||||
public Object touristRegister(String loginType) {
|
||||
Tbl_User user = new Tbl_User();
|
||||
if (StringUtils.isBlank(loginType)) {
|
||||
return IfishUtil.returnJson(ResultEnum.error401.getKey(), "");
|
||||
}
|
||||
user.setUserType("0");
|
||||
user.setLoginType(loginType);
|
||||
int i = tbl_User_Mapper.insertUserByTourist(user);
|
||||
Map result = new HashMap();
|
||||
if (i > 0 && user.getUserId() > 0) {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public interface UserHelperI {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
public Object touristRegister();
|
||||
public Object touristRegister(String loginType);
|
||||
|
||||
/**
|
||||
* 封装设备返回信息
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ package com.ifish.mapper;
|
|||
import com.ifish.bean.Tbl_Push_List;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.SelectProvider;
|
||||
|
|
@ -60,4 +61,13 @@ public interface Tbl_Push_List_Mapper {
|
|||
@Select("SELECT COUNT(1) FROM TBL_PUSH_LIST WHERE user_id = #{userid} AND push_type = #{pushtype} LIMIT ${first},${pagesize}")
|
||||
Integer getPushListCount(@Param("userid") Integer userId, @Param("pushtype") String pushType, @Param("pagesize") Integer pageSize, @Param("first") Integer firstResult);
|
||||
|
||||
/**
|
||||
* 插入一条推送信息
|
||||
*
|
||||
* @param tbl_Push_List
|
||||
* @return
|
||||
*/
|
||||
@Insert("INSERT INTO TBL_PUSH_LIST(user_id,device_id,show_name,phone_type,push_type,push_title,push_context,create_time,push_link,jpush_status,google_status,report_id,mcu_count,modular_count,router_count,server_count,server_try_count) VALUES (#{push.userId},#{push.deviceId},#{push.showName},#{push.phoneType},"
|
||||
+ "#{push.pushType},#{push.pushTitle},#{push.pushContext},NOW(),#{push.pushLink},#{push.jpushStatus},#{push.googleStatus},#{push.reportId},#{push.mcuCount},#{push.modularCount},#{push.routerCount},#{push.serverCount},#{push.serverTryCount})")
|
||||
Integer saveTbl_Push_List(@Param("push") Tbl_Push_List tbl_Push_List);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue