新增接口 微信验证,手机号码绑定
This commit is contained in:
parent
01eca3dcf9
commit
beca25818d
|
|
@ -93,12 +93,21 @@ public class UsersAction {
|
||||||
* @param code
|
* @param code
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestMapping(value="/wechatLogin",method=RequestMethod.POST)
|
@RequestMapping(value="/wechatLogin",method=RequestMethod.GET)
|
||||||
public JsonResult<?> wechatLogin(String code) {
|
public JsonResult<?> wechatLogin(String code) {
|
||||||
|
|
||||||
return userService.wechatLogin(code);
|
return userService.wechatLogin(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信登录验证
|
||||||
|
* @param unionId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping(value="/wechatValidate",method=RequestMethod.GET)
|
||||||
|
public JsonResult<?> wechatValidate(String unionId) {
|
||||||
|
return userService.wechatValidate(unionId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更多用户数据
|
* 更多用户数据
|
||||||
* @param userId
|
* @param userId
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,12 @@ public class UserInfoDto {
|
||||||
* 用户ID
|
* 用户ID
|
||||||
*/
|
*/
|
||||||
private Integer userId;
|
private Integer userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信unionID
|
||||||
|
*/
|
||||||
|
private String unionId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手机号码
|
* 手机号码
|
||||||
*/
|
*/
|
||||||
|
|
@ -149,4 +155,12 @@ public class UserInfoDto {
|
||||||
public void setSessionID2(String sessionID2) {
|
public void setSessionID2(String sessionID2) {
|
||||||
this.sessionID2 = sessionID2;
|
this.sessionID2 = sessionID2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUnionId() {
|
||||||
|
return unionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUnionId(String unionId) {
|
||||||
|
this.unionId = unionId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,21 @@ public interface UserService {
|
||||||
*/
|
*/
|
||||||
public JsonResult<?> wechatLogin(String code);
|
public JsonResult<?> wechatLogin(String code);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信登录验证
|
||||||
|
* @param unionId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JsonResult<?> wechatValidate(String unionId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号绑定
|
||||||
|
* @param unionId
|
||||||
|
* @param phone
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JsonResult<?> bindPhone(String unionId, String phone);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更多用户数据信息
|
* 更多用户数据信息
|
||||||
* @param userId
|
* @param userId
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import java.util.Random;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.ifish.entity.event.QueueEventBody;
|
import com.ifish.entity.event.QueueEventBody;
|
||||||
import com.ifish.entity.event.QueueEventEntity;
|
import com.ifish.entity.event.QueueEventEntity;
|
||||||
|
import com.ifish.util.StringUtil;
|
||||||
import com.ifish.util.WeChatUtils;
|
import com.ifish.util.WeChatUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
|
|
@ -329,13 +330,14 @@ public class UserServiceImpl implements UserService {
|
||||||
public JsonResult<?> wechatLogin(String code) {
|
public JsonResult<?> wechatLogin(String code) {
|
||||||
JSONObject wechatUserInfo = WeChatUtils.getWechatUserInfo(code);
|
JSONObject wechatUserInfo = WeChatUtils.getWechatUserInfo(code);
|
||||||
//微信授权失败
|
//微信授权失败
|
||||||
if (wechatUserInfo == null || wechatUserInfo.size() == 0) {
|
if (wechatUserInfo == null || wechatUserInfo.size() == 2) {
|
||||||
throw new IfishException(ResultEnum.error403);
|
throw new IfishException(ResultEnum.error403);
|
||||||
}
|
}
|
||||||
//用户信息
|
//用户信息
|
||||||
User user = userDao.findUniqueByProperty(Restrictions.eq("wechatUnionid",wechatUserInfo.getString("unionid")));
|
User user = userDao.findUniqueByProperty(Restrictions.eq("wechatUnionid",wechatUserInfo.getString("unionid")));
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
user = new User();
|
user = new User();
|
||||||
|
user.setWechatUnionid(wechatUserInfo.getString("unionid"));
|
||||||
user.setPhoneType("wechat");
|
user.setPhoneType("wechat");
|
||||||
user.setLoginType("wechat");
|
user.setLoginType("wechat");
|
||||||
user.setIsRegisterGwell(BooleanEnum.NO.getKey());
|
user.setIsRegisterGwell(BooleanEnum.NO.getKey());
|
||||||
|
|
@ -379,7 +381,7 @@ public class UserServiceImpl implements UserService {
|
||||||
pushList.setPushType(PushTypeEnum.qu_reply.getKey());
|
pushList.setPushType(PushTypeEnum.qu_reply.getKey());
|
||||||
pushList.setPushTitle("系统通知");
|
pushList.setPushTitle("系统通知");
|
||||||
pushList.setPushContext(msg.toString());
|
pushList.setPushContext(msg.toString());
|
||||||
sendPushQueueMessage(pushList);
|
// sendPushQueueMessage(pushList);
|
||||||
//更新用户注册信息
|
//更新用户注册信息
|
||||||
user.setIsRegisterNetease(BooleanEnum.YES.getKey());
|
user.setIsRegisterNetease(BooleanEnum.YES.getKey());
|
||||||
userDao.update(user);
|
userDao.update(user);
|
||||||
|
|
@ -394,9 +396,185 @@ public class UserServiceImpl implements UserService {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("userInfo", userInfoDto);
|
json.put("userInfo", userInfoDto);
|
||||||
json.put("userAsset", userAssetDto);
|
json.put("userAsset", userAssetDto);
|
||||||
|
//设备信息
|
||||||
|
DeviceInfoDto deviceInfo = getDeviceInfo(user.getUserId());
|
||||||
|
/**
|
||||||
|
* 登录返回信息
|
||||||
|
*/
|
||||||
|
//用户信息
|
||||||
|
json.put("user", getUserInfo(user,gwellParam));
|
||||||
|
//用户资产
|
||||||
|
json.put("userAsset", getUserAssetInfo(userId));
|
||||||
|
//金币任务
|
||||||
|
json.put("goldTasks", getGoldTaskList(userId));
|
||||||
|
|
||||||
|
//资讯信息
|
||||||
|
json.put("information", cacheService.getInformation());
|
||||||
|
//设备信息
|
||||||
|
json.put("device", deviceInfo.getDeviceList());
|
||||||
|
//摄像头信息
|
||||||
|
json.put("camera", getCameraInfo(userId));
|
||||||
|
//设备关联摄像头信息
|
||||||
|
json.put("deviceCamera", getDeviceCamera(deviceInfo.getDeviceIds()));
|
||||||
|
//商家信息(自己是商家)
|
||||||
|
json.put("shopsInfo", getShopsInfo(userId,user.getUserImg()));
|
||||||
|
//看护商家信息
|
||||||
|
json.put("shopsInfo2", getShopsInfo(user.getShopsUserId(),null));
|
||||||
return new JsonResult<JSONObject>(ResultEnum.success.getKey(), json);
|
return new JsonResult<JSONObject>(ResultEnum.success.getKey(), json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonResult<?> wechatValidate(String unionId) {
|
||||||
|
if (unionId == null || unionId.length() == 0) {
|
||||||
|
throw new IfishException(ResultEnum.error401);
|
||||||
|
}
|
||||||
|
//用户信息
|
||||||
|
User user = userDao.findUniqueByProperty(Restrictions.eq("wechatUnionid",unionId));
|
||||||
|
if (user == null) {
|
||||||
|
throw new IfishException(ResultEnum.fail101);
|
||||||
|
}
|
||||||
|
//技威参数
|
||||||
|
GwellParamDto gwellParam = getGwellInfo(user.getIsRegisterGwell(), user.getWechatUnionid());
|
||||||
|
if(gwellParam!=null){
|
||||||
|
user.setIsRegisterGwell(gwellParam.getIsRegisterGwell());
|
||||||
|
user.setP2PVerifyCode1(gwellParam.getP2PVerifyCode1());
|
||||||
|
user.setP2PVerifyCode2(gwellParam.getP2PVerifyCode2());
|
||||||
|
user.setGwellUserID(gwellParam.getUserID());
|
||||||
|
}
|
||||||
|
Integer userId = user.getUserId();
|
||||||
|
StringBuffer msg = new StringBuffer();
|
||||||
|
msg.append("感谢您使用爱鱼奇,连接智能设备请查看下方说明书,内含操作视频:http://u.eqxiu.com/s/KmmVl87l\n");
|
||||||
|
msg.append("摄像头售后:18667812003\n睿芯插排售后:15757401229\n绚多插排售后:18857689069\n松诺插排售后:13392205468");
|
||||||
|
//如果当前设备用户未注册
|
||||||
|
if (user.getIsRegisterNetease().equals(BooleanEnum.NO.getKey())) {
|
||||||
|
PushList pushList = new PushList();
|
||||||
|
pushList.setUserId(userId);
|
||||||
|
pushList.setDeviceId(0);
|
||||||
|
pushList.setPhoneType("ALL");
|
||||||
|
pushList.setShowName("");
|
||||||
|
pushList.setPushType(PushTypeEnum.qu_reply.getKey());
|
||||||
|
pushList.setPushTitle("系统通知");
|
||||||
|
pushList.setPushContext(msg.toString());
|
||||||
|
// sendPushQueueMessage(pushList);
|
||||||
|
//更新用户注册信息
|
||||||
|
user.setIsRegisterNetease(BooleanEnum.YES.getKey());
|
||||||
|
userDao.update(user);
|
||||||
|
}
|
||||||
|
//更新登陆参数
|
||||||
|
userDao.executeLoginUpdate(userId,user.getLoginType());
|
||||||
|
//用户基本信息
|
||||||
|
UserInfoDto userInfoDto = getUserInfoDto(user, gwellParam);
|
||||||
|
//用户资产信息
|
||||||
|
UserAssetDto userAssetDto = getUserAssetInfo(userId);
|
||||||
|
//返回json信息
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("userInfo", userInfoDto);
|
||||||
|
json.put("userAsset", userAssetDto);
|
||||||
|
//设备信息
|
||||||
|
DeviceInfoDto deviceInfo = getDeviceInfo(user.getUserId());
|
||||||
|
/**
|
||||||
|
* 登录返回信息
|
||||||
|
*/
|
||||||
|
//用户信息
|
||||||
|
json.put("user", getUserInfo(user,gwellParam));
|
||||||
|
//用户资产
|
||||||
|
json.put("userAsset", getUserAssetInfo(userId));
|
||||||
|
//金币任务
|
||||||
|
json.put("goldTasks", getGoldTaskList(userId));
|
||||||
|
|
||||||
|
//资讯信息
|
||||||
|
json.put("information", cacheService.getInformation());
|
||||||
|
//设备信息
|
||||||
|
json.put("device", deviceInfo.getDeviceList());
|
||||||
|
//摄像头信息
|
||||||
|
json.put("camera", getCameraInfo(userId));
|
||||||
|
//设备关联摄像头信息
|
||||||
|
json.put("deviceCamera", getDeviceCamera(deviceInfo.getDeviceIds()));
|
||||||
|
//商家信息(自己是商家)
|
||||||
|
json.put("shopsInfo", getShopsInfo(userId,user.getUserImg()));
|
||||||
|
//看护商家信息
|
||||||
|
json.put("shopsInfo2", getShopsInfo(user.getShopsUserId(),null));
|
||||||
|
return new JsonResult<JSONObject>(ResultEnum.success.getKey(), json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonResult<?> bindPhone(String unionId, String phone) {
|
||||||
|
if (unionId == null || phone == null) {
|
||||||
|
throw new IfishException(ResultEnum.error401);
|
||||||
|
}
|
||||||
|
//用户信息
|
||||||
|
User userWechat = userDao.findUniqueByProperty(Restrictions.eq("wechatUnionid",unionId));
|
||||||
|
if (userWechat == null) {
|
||||||
|
throw new IfishException(ResultEnum.fail101);
|
||||||
|
}
|
||||||
|
User userPhone = userDao.findUniqueByProperty(Restrictions.eq("phoneNumber",unionId));
|
||||||
|
if (userPhone == null) {
|
||||||
|
throw new IfishException(ResultEnum.fail101);
|
||||||
|
}
|
||||||
|
List<DeviceUser> deviceUserListWechat = deviceUserDao.findByProperty(Restrictions.eq("priId.userId", userWechat.getUserId()));
|
||||||
|
List<DeviceUser> deviceUserListPhone = deviceUserDao.findByProperty(Restrictions.eq("priId.userId", userPhone.getUserId()));
|
||||||
|
for(DeviceUser deviceUser:deviceUserListWechat){
|
||||||
|
for (DeviceUser devicePhone : deviceUserListPhone) {
|
||||||
|
//如果 手机账号中存在设备
|
||||||
|
if (devicePhone.getPriId().getDeviceId().intValue() == deviceUser.getPriId().getDeviceId().intValue()) {
|
||||||
|
//当前账号是主控制账号
|
||||||
|
if (devicePhone.getIsMaster().equals("1")) {
|
||||||
|
//删除 微信账号下的设备
|
||||||
|
deviceUserDao.delete(deviceUser);
|
||||||
|
} else {
|
||||||
|
//修改 手机号账号下的设备为主控设备
|
||||||
|
devicePhone.setIsMaster("1");
|
||||||
|
deviceUserDao.update(devicePhone);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 微信账号下绑定的userid改为手机号的userid
|
||||||
|
DeviceUserId priId = deviceUser.getPriId();
|
||||||
|
priId.setUserId(userPhone.getUserId());
|
||||||
|
deviceUserDao.update(deviceUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//如果 手机号码账号下不存在设备 则修改微信账号下的设备关联为手机号的userid
|
||||||
|
if (deviceUserListPhone.size() == 0) {
|
||||||
|
DeviceUserId priId = deviceUser.getPriId();
|
||||||
|
priId.setUserId(userPhone.getUserId());
|
||||||
|
deviceUserDao.update(deviceUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//修改手机账号的微信unionid
|
||||||
|
userPhone.setWechatUnionid(userWechat.getWechatUnionid());
|
||||||
|
userDao.update(userPhone);
|
||||||
|
|
||||||
|
//用户资产信息
|
||||||
|
UserAssetDto userAssetDtoWechat = getUserAssetInfo(userWechat.getUserId());
|
||||||
|
UserAssetDto userAssetDtoPhone = getUserAssetInfo(userPhone.getUserId());
|
||||||
|
//设置经验值
|
||||||
|
userAssetDtoPhone.setGoldValue(new BigDecimal(userAssetDtoWechat.getGoldValue().intValue() + userAssetDtoPhone.getGoldValue().intValue()));
|
||||||
|
if (userAssetDtoPhone.getGoldValue().intValue() <= 0 && userAssetDtoPhone.getGoldValue().intValue() < 7) {
|
||||||
|
userAssetDtoPhone.setGradeNum(0);
|
||||||
|
userAssetDtoPhone.setGradeName("小虾米");
|
||||||
|
} else if (userAssetDtoPhone.getGoldValue().intValue() <= 7 && userAssetDtoPhone.getGoldValue().intValue() < 70) {
|
||||||
|
userAssetDtoPhone.setGradeNum(0);
|
||||||
|
userAssetDtoPhone.setGradeName("小飞鱼");
|
||||||
|
} else if (userAssetDtoPhone.getGoldValue().intValue() <= 70 && userAssetDtoPhone.getGoldValue().intValue() < 170) {
|
||||||
|
userAssetDtoPhone.setGradeNum(1);
|
||||||
|
userAssetDtoPhone.setGradeName("横行蟹");
|
||||||
|
} else if (userAssetDtoPhone.getGoldValue().intValue() <= 170 && userAssetDtoPhone.getGoldValue().intValue() < 370) {
|
||||||
|
userAssetDtoPhone.setGradeNum(2);
|
||||||
|
userAssetDtoPhone.setGradeName("海夜叉");
|
||||||
|
} else if (userAssetDtoPhone.getGoldValue().intValue() <= 370 && userAssetDtoPhone.getGoldValue().intValue() < 670) {
|
||||||
|
userAssetDtoPhone.setGradeNum(3);
|
||||||
|
userAssetDtoPhone.setGradeName("龟丞相");
|
||||||
|
} else if (userAssetDtoPhone.getGoldValue().intValue() <= 670 && userAssetDtoPhone.getGoldValue().intValue() < 1070) {
|
||||||
|
userAssetDtoPhone.setGradeNum(5);
|
||||||
|
userAssetDtoPhone.setGradeName("小白龙");
|
||||||
|
} else if (userAssetDtoPhone.getGoldValue().intValue() <= 1070 && userAssetDtoPhone.getGoldValue().intValue() < 1570) {
|
||||||
|
userAssetDtoPhone.setGradeNum(7);
|
||||||
|
userAssetDtoPhone.setGradeName("海龙王");
|
||||||
|
}
|
||||||
|
return wechatValidate(unionId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更多用户数据信息
|
* 更多用户数据信息
|
||||||
*/
|
*/
|
||||||
|
|
@ -1079,6 +1257,7 @@ public class UserServiceImpl implements UserService {
|
||||||
dto.setNeteaseToken(user.getNeteaseToken());
|
dto.setNeteaseToken(user.getNeteaseToken());
|
||||||
dto.setUserType(user.getUserType());
|
dto.setUserType(user.getUserType());
|
||||||
dto.setShopsUserId(user.getShopsUserId());
|
dto.setShopsUserId(user.getShopsUserId());
|
||||||
|
dto.setUnionId(user.getWechatUnionid());
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue