小程序端手机号与openid解绑
This commit is contained in:
parent
e2f456c4dd
commit
d43b715ad8
@ -4,6 +4,7 @@ import com.xinelu.common.core.controller.BaseController;
|
||||
import com.xinelu.common.core.domain.AjaxResult;
|
||||
import com.xinelu.common.core.page.TableDataInfo;
|
||||
import com.xinelu.mobile.dto.appletpersoncenter.HealthRecordDTO;
|
||||
import com.xinelu.mobile.dto.appletpersoncenter.UnbindRequestDTO;
|
||||
import com.xinelu.mobile.dto.verifysmscode.VerifySmsCodeDTO;
|
||||
import com.xinelu.mobile.service.appletpersoncenter.AppletPersonCenterService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@ -88,6 +89,13 @@ public class AppletPersonCenterController extends BaseController {
|
||||
return appletPersonCenterService.appletLoginV1(loginCode);
|
||||
}
|
||||
|
||||
@ApiOperation("小程序端手机号与openid解绑")
|
||||
@PostMapping("/unbindOpenId")
|
||||
public AjaxResult unbindOpenId(@RequestBody UnbindRequestDTO unbindRequestDTO) {
|
||||
return appletPersonCenterService.unbindOpenId(unbindRequestDTO.getPhoneNum(), unbindRequestDTO.getOpenId());
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("小程序登录发送短信验证码")
|
||||
@GetMapping("/sendSms")
|
||||
public AjaxResult sendSms(String phoneNum) {
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
package com.xinelu.mobile.dto.appletpersoncenter;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @program: PostDischargePatientManage
|
||||
* @description: 小程序解绑请求参数
|
||||
* @author: yxl
|
||||
* @create: 2024-07-09 15:12
|
||||
**/
|
||||
@Data
|
||||
public class UnbindRequestDTO {
|
||||
|
||||
@ApiModelProperty(value = "手机号")
|
||||
private String phoneNum;
|
||||
|
||||
@ApiModelProperty(value = "微信小程序openid")
|
||||
private String openId;
|
||||
}
|
||||
@ -70,4 +70,12 @@ public interface AppletPersonCenterService {
|
||||
* @return 验证短信验证码信息
|
||||
*/
|
||||
AjaxResult verifySmsCode(VerifySmsCodeDTO verifySmsCodeDTO);
|
||||
|
||||
/**
|
||||
* 小程序端手机号与openid解绑
|
||||
* @param phoneNum 手机号
|
||||
* @param openId openid
|
||||
* @return 解绑信息
|
||||
*/
|
||||
AjaxResult unbindOpenId(String phoneNum, String openId);
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
@ -247,6 +248,7 @@ public class AppletPersonCenterServiceImpl implements AppletPersonCenterService
|
||||
* @return 验证短信验证码信息
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AjaxResult verifySmsCode(VerifySmsCodeDTO verifySmsCodeDTO) {
|
||||
try {
|
||||
String openId = verifySmsCodeDTO.getOpenId();
|
||||
@ -254,33 +256,66 @@ public class AppletPersonCenterServiceImpl implements AppletPersonCenterService
|
||||
String cacheKey = Constants.SMS_CODE + verifySmsCodeDTO.getPhoneNum();
|
||||
ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
|
||||
String storedCode = valueOperations.get(cacheKey);
|
||||
|
||||
// 缓存的验证码不存在
|
||||
if (storedCode == null) {
|
||||
log.error("验证码已过期,手机号:{}", verifySmsCodeDTO.getPhoneNum());
|
||||
return AjaxResult.error("验证码已过期,请重新获取!");
|
||||
}
|
||||
|
||||
// 缓存的验证码与输入的验证码不匹配
|
||||
if (!storedCode.equals(smsCode)) {
|
||||
log.error("验证码验证失败,手机号:{},输入的验证码:{},获取的验证码:{}", verifySmsCodeDTO.getPhoneNum(), smsCode, storedCode);
|
||||
return AjaxResult.error("验证码错误,请重新输入!");
|
||||
}
|
||||
|
||||
// 根据手机号和姓名查询用户信息
|
||||
log.info("验证码验证成功,手机号:{},输入的验证码:{},获取的验证码:{}", verifySmsCodeDTO.getPhoneNum(), smsCode, storedCode);
|
||||
List<ResidentInfo> residentInfos = residentInfoMapper.getResidentInfoByPhoneAndName(verifySmsCodeDTO.getPhoneNum(), verifySmsCodeDTO.getPatientName());
|
||||
|
||||
// 用户信息不存在
|
||||
if (residentInfos == null || residentInfos.isEmpty()) {
|
||||
return AjaxResult.error("您的用户信息尚未录入系统,无法执行注册操作!");
|
||||
} else if (residentInfos.size() > 1) {
|
||||
// 存在姓名和手机号重复的情况
|
||||
return AjaxResult.error("您的信息存在重复记录,请联系管理员进行操作!");
|
||||
}
|
||||
// 更新用户的openid
|
||||
ResidentInfo residentInfo = residentInfos.get(0);
|
||||
residentInfo.setOpenId(openId);
|
||||
residentInfoMapper.updateResidentInfo(residentInfo);
|
||||
log.info("用户注册成功,姓名:{},手机号:{},openid:{}", verifySmsCodeDTO.getPatientName(), verifySmsCodeDTO.getPhoneNum(), openId);
|
||||
return AjaxResult.success("注册成功!", residentInfo);
|
||||
} catch (Exception e) {
|
||||
log.error("验证验证码时发生异常,手机号:{},异常信息:{}", verifySmsCodeDTO.getPhoneNum(), e.getMessage(), e);
|
||||
return AjaxResult.error("短信验证码验证失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序端手机号与openid解绑
|
||||
*
|
||||
* @param phoneNum 手机号
|
||||
* @param openId openid
|
||||
* @return 解绑信息
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AjaxResult unbindOpenId(String phoneNum, String openId) {
|
||||
try {
|
||||
// 根据phoneNum和openid查询用户信息
|
||||
ResidentInfo residentInfo = residentInfoMapper.getResidentInfoByPhoneAndOpenId(phoneNum, openId);
|
||||
|
||||
// 未查询到用户信息
|
||||
if (ObjectUtils.isEmpty(residentInfo)) {
|
||||
log.info("未查询到用户信息,手机号:{},openId:{}", phoneNum, openId);
|
||||
return AjaxResult.error("未查询到用户信息,无法解绑!");
|
||||
}
|
||||
|
||||
// 清空openid字段,更新用户信息
|
||||
residentInfo.setOpenId(null);
|
||||
residentInfoMapper.updateResidentInfo(residentInfo);
|
||||
log.info("解绑成功,手机号:{},openId:{}", phoneNum, openId);
|
||||
return AjaxResult.success("解绑成功!");
|
||||
} catch (Exception e) {
|
||||
log.error("解绑openId时发生异常,手机号:{},openId:{},异常信息:{}", phoneNum, openId, e.getMessage(), e);
|
||||
return AjaxResult.error("解绑失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user