提交 a231c18f 编写于 作者: Administrator's avatar Administrator

Merge branch 'dev-detection-0704' into 'release'

Dev detection 0704

See merge request !117
流水线 #49691 已失败 于阶段
......@@ -11,7 +11,7 @@
<groupId>com.pica.cloud.account</groupId>
<artifactId>pica-cloud-account-client</artifactId>
<version>1.1.3</version>
<version>1.1.4-SNAPSHOT</version>
<name>pica-cloud-account-client</name>
<packaging>jar</packaging>
......@@ -28,7 +28,7 @@
<dependency>
<groupId>com.pica.cloud.account</groupId>
<artifactId>pica-cloud-account-common</artifactId>
<version>1.1.3</version>
<version>1.1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
......
package com.pica.cloud.account.account.client;
import com.pica.cloud.account.account.common.req.LoginAppletReq;
import com.pica.cloud.foundation.entity.PicaResponse;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;
......@@ -14,4 +15,7 @@ public interface LoginClient {
@PostMapping("/account/login/QRCode")
PicaResponse<String> loginQRCode(@RequestHeader(value = "token") String token,@RequestHeader(value = "user_token_tourist") String user_token_tourist);
@PostMapping("/account/login/applet")
PicaResponse<String> loginApplet(@RequestBody LoginAppletReq req);
}
......@@ -11,7 +11,7 @@
<groupId>com.pica.cloud.account</groupId>
<artifactId>pica-cloud-account-common</artifactId>
<version>1.1.3</version>
<version>1.1.4-SNAPSHOT</version>
<name>pica-cloud-account-common</name>
<packaging>jar</packaging>
......
package com.pica.cloud.account.account.common.req;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* @author xinxu.wang
* @create 2022/7/4
*/
@ApiModel
public class LoginAppletReq {
@ApiModelProperty("手机号")
private String mobilePhone;
@ApiModelProperty("微信unionid")
private String unionid;
@ApiModelProperty("微信openid")
private String openid;
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
public String getMobilePhone() {
return mobilePhone;
}
public void setMobilePhone(String mobilePhone) {
this.mobilePhone = mobilePhone;
}
public String getUnionid() {
return unionid;
}
public void setUnionid(String unionid) {
this.unionid = unionid;
}
}
......@@ -167,7 +167,7 @@
<dependency>
<groupId>com.pica.cloud.account</groupId>
<artifactId>pica-cloud-account-common</artifactId>
<version>1.1.3</version>
<version>1.1.4-SNAPSHOT</version>
</dependency>
<dependency>
......@@ -284,6 +284,12 @@
<artifactId>pica-cloud-message-client</artifactId>
<version>1.0.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.pica.cloud.wechat</groupId>
<artifactId>pica-cloud-applet-client</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<dependencyManagement>
......
......@@ -25,8 +25,12 @@ import com.pica.cloud.foundation.service.starter.interceptor.EnabledLoginValidat
import com.pica.cloud.foundation.utils.constants.CommonConstants;
import com.pica.cloud.foundation.utils.entity.PicaUser;
import com.pica.cloud.foundation.utils.utils.CommonUtil;
import com.pica.cloud.foundation.utils.utils.StringUtil;
import com.pica.cloud.foundation.utils.utils.ValidateUtils;
import com.pica.cloud.foundation.utils.utils.json.Object2Map;
import com.pica.cloud.wechat.applet.client.AppletServiceClient;
import com.pica.cloud.wechat.applet.common.model.AppletModel;
import com.pica.cloud.wechat.applet.common.req.AppletReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
......@@ -67,6 +71,9 @@ public class AccountController extends AccountBaseController {
@Autowired
private DoctorService doctorService;
@Autowired
private AppletServiceClient appletServiceClient;
@GetMapping("/test")
public String test() {
return "{\"status\":\"UP\"}";
......@@ -98,6 +105,38 @@ public class AccountController extends AccountBaseController {
return PicaResponse.toResponse(StringUtils.EMPTY);
}
@ApiOperation("获取登录验证码")
@GetMapping("/authCode/applet")
public PicaResponse<String> getAuthCodeApplet(@ApiParam(value = "手机号", required = true) @RequestParam("mobilePhone") String mobilePhone,
@ApiParam(value = "验证码类型 0默认 1注册 2修改密码 4微信登录绑定手机 5修改手机 6重置密码 7患者招募提交问卷(效验") @RequestParam(value = "flag", defaultValue = "0") String flag,
@ApiParam(value = "小程序code", required = true) @RequestParam("code") String code,
@ApiParam(value = "小程序类型", required = true) @RequestParam("type") Integer type) {
AppletModel appletModel = appletServiceClient.code2Session(code,type).getData();
if (StringUtil.isNull(appletModel) || StringUtil.isNull(appletModel.getUnionId())) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(),"小程序code解密失败");
}
this.checkMobilePhone(mobilePhone);
String authCode = CommonUtil.createValidateCode(); //随机生成验证码
String message = "您的验证码是" + authCode + ",在10分钟内有效。如非本人操作,请忽略本短信!";
long senderId = 0L;
if (Integer.parseInt(flag) != 7) {
//判断账号是否已经存在
Account account = accountService.getByMobilePhone(mobilePhone);
if (StringUtil.isNull(account)) {
throw new PicaException(PicaResultCode.RESULE_DATA_NONE.code(),"请先至云鹊医App注册认证后使用");
}
senderId = account == null ? 0L : account.getId();
}
//验证码保存到redis,失效时间10分钟
redisClient.set(this.getAuthCodeKey(mobilePhone, flag), authCode, 600);
//发送短信
super.sendMobileMessage(mobilePhone, message, senderId);
return PicaResponse.toResponse(StringUtils.EMPTY);
}
@ApiOperation("教培项目校验短信验证码")
@GetMapping("/check/authCode")
public PicaResponse checkAuthCode(@ApiParam(value = "手机号", required = true) @RequestParam("mobilePhone") String mobilePhone,
......
......@@ -2,6 +2,8 @@ package com.pica.cloud.account.account.server.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.common.req.LoginAppletReq;
import com.pica.cloud.account.account.server.entity.AesBean.AesAuthCodeAppletReq;
import com.pica.cloud.account.account.server.entity.AesBean.AesAuthCodeReq;
import com.pica.cloud.account.account.server.entity.*;
import com.pica.cloud.account.account.server.enums.AccountExceptionEnum;
......@@ -13,13 +15,11 @@ import com.pica.cloud.account.account.server.log.AccountLogUtils;
import com.pica.cloud.account.account.server.req.AccountReq;
import com.pica.cloud.account.account.server.req.BaseRequest;
import com.pica.cloud.account.account.server.req.OneClickLoginReq;
import com.pica.cloud.account.account.server.service.CaptchaService;
import com.pica.cloud.account.account.server.service.DoctorService;
import com.pica.cloud.account.account.server.service.LoginService;
import com.pica.cloud.account.account.server.service.TokenService;
import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.account.account.server.util.CryptoUtil;
import com.pica.cloud.account.account.server.util.RSAUtil;
import com.pica.cloud.account.account.server.service.*;
import com.pica.cloud.account.account.server.util.*;
import com.pica.cloud.foundation.completeness.client.utils.IntactUtils;
import com.pica.cloud.foundation.encryption.common.constants.EncryptConstants;
import com.pica.cloud.foundation.encryption.util.EncryptUtils;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.entity.PicaResultCode;
......@@ -29,6 +29,9 @@ import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.service.starter.interceptor.EnabledLoginValidate;
import com.pica.cloud.foundation.utils.annotation.LoginPermission;
import com.pica.cloud.foundation.utils.utils.StringUtil;
import com.pica.cloud.wechat.applet.client.AppletServiceClient;
import com.pica.cloud.wechat.applet.common.model.AppletModel;
import com.pica.cloud.wechat.applet.common.req.AppletReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
......@@ -39,6 +42,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;
@Api(description = "登录资源")
......@@ -72,6 +76,16 @@ public class LoginController extends AccountBaseController {
@Resource
private AccountController accountController;
@Autowired
private AccountService accountService;
@Autowired
private IntactUtil intactUtil;
@Autowired
private TokenUtils tokenUtils;
@Autowired
private AppletServiceClient appletServiceClient;
/**
* 密码登录接口(app、H5、web)
*
......@@ -517,4 +531,109 @@ public class LoginController extends AccountBaseController {
SaasLoginResult login = loginService.saasLoginByAuthCode(request);
return PicaResponse.toResponse(login);
}
@ApiOperation("云鹊医助手小程序授权登录")
@PostMapping("/login/applet")
public PicaResponse<String> loginApplet(@RequestBody LoginAppletReq req) {
accountController.checkMobilePhone(req.getMobilePhone());
logger.info("login applet :{}", JSONObject.toJSONString(req));
String batchNo = IntactUtils.getUUID();
intactUtil.sendIntact(batchNo, "login/applet", com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_1, "req:" + JSON.toJSONString(req));
Account account = accountService.getByMobilePhone(req.getMobilePhone()); //获取账号信息
if (account == null) {
intactUtil.sendIntact(batchNo, "login/applet", com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3, "未注册,请验证码登录");
return PicaResponse.toResponse(null, PicaResultCode.RESULE_DATA_NONE.code(), "未注册,请验证码登录");
}
//更新最后登录时间
Account update = new Account();
update.setId(account.getId());
update.setLastLoginTime(new Date());
update.setModifyId(account.getId());
update.setModifyTime(new Date());
accountService.updateAccountById(update);
//登录成功,清除旧token,生成新token
Account account1 = new Account();
account1.setId(account.getId());
account1.setAcctId(account.getAcctId());
account1.setCreatTime(new Date());
account1.setMobilePhone(req.getMobilePhone());
account1.setRegisterSource(4);
String newToken = tokenUtils.generateToken(account1);
int expiredSeconds = 24 * 60 * 60 * 30;
cacheClient.set("token-doctor-unionid-"+req.getUnionid(),newToken,expiredSeconds);
cacheClient.set("token-unionid-"+newToken,req.getUnionid(),expiredSeconds);
cacheClient.set("token-openid-"+newToken,req.getOpenid(),expiredSeconds);
intactUtil.sendIntact(batchNo, "login/applet", com.pica.cloud.foundation.completeness.contract.constants.CommonConstants.INTACT_CONTENT_LOG_STATUS_3, "req:" + JSON.toJSONString(req));
return PicaResponse.toResponse(newToken);
}
@ApiOperation("云鹊医助手小程序授权登录")
@PostMapping("/login/applet/authCode")
public PicaResponse<LoginResult> loginAppletAuthCode(@RequestBody AesAuthCodeAppletReq authCodeReq) {
AppletModel appletModel = appletServiceClient.code2Session(authCodeReq.getCode(),authCodeReq.getType()).getData();
if (StringUtil.isNull(appletModel) || StringUtil.isNull(appletModel.getUnionId())) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(),"小程序code解密失败");
}
BaseRequest request = new BaseRequest();
request.setMobile(authCodeReq.getMobile());
request.setAuthCode(authCodeReq.getAuthCode());
logger.info("login-register:{}",JSONObject.toJSONString(request));
request.setProductType(1);
request.setSourceType(4);
request.setLoginIp(super.getIpAddr());
request.setUserTokenTourist(super.getUserTokenTourist());
LoginResult login = loginService.loginAndRegister(request);
if (StringUtil.isNotNull(login)) {
int expiredSeconds = 24 * 60 * 60 * 30;
cacheClient.set("token-doctor-unionid-"+appletModel.getUnionId(),login.getToken(),expiredSeconds);
cacheClient.set("token-unionid-"+login.getToken(),appletModel.getUnionId(),expiredSeconds);
cacheClient.set("token-openid-"+login.getToken(),appletModel.getOpenId(),expiredSeconds);
/** 绑定医生和unionid关系 */
appletServiceClient.insertAppletDoctor(appletModel.getUnionId(), EncryptUtils.encryptContent(login.getUserId().toString(), EncryptConstants.ENCRYPT_TYPE_DOCTOR_ID));
}
return PicaResponse.toResponse(login);
}
/**
* 退出登录接口,返回一个随机token
*
* @return
*/
@ApiOperation(value = "云鹊医助手小程序退出登录接口")
@GetMapping("/logout/applet")
public PicaResponse loginOutApplet() {
String token = super.getToken();
if (StringUtils.isNotEmpty(token)) {
try {
Long doctorId = super.getDoctorIdByToken();
Doctor doctorInfo = doctorService.getDoctorInfo(doctorId.intValue());
if (StringUtil.isNotNull(doctorInfo)) {
Integer acctId = doctorInfo.getAcctId();
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(acctId, 1, 4,
AccountTypeEnum.LOGIN_OUT.getCode(), super.getIpAddr(), AccountTypeEnum.LOGIN_STATUS_SUCCESS.getCode(), AccountTypeEnum.LOG_TYPE_LOGIN.getCode(),
"",0,super.getUserTokenTourist());
picaLogUtils.info(entity);
}
} catch (Exception e) {
}
String unionid = redisClient.get("token-unionid-" +token);
redisClient.del("token-unionid-" +token);
redisClient.del("token-openid-" +token);
redisClient.del("token-doctor-unionid-" +unionid);
return PicaResponse.toResponse();
} else {
throw new AccountException(AccountExceptionEnum.PICA_LOGIN_AGAIN);
}
}
}
// Copyright 2016-2101 Pica.
package com.pica.cloud.account.account.server.entity.AesBean;
/**
* @ClassName AesAuthCodeAppletReq
* @Description TODO
* @Author xinxu.wang
* @Date 2022/7/5 18:33
* @ModifyDate 2022/7/5 18:33
* @Version 1.0
*/
public class AesAuthCodeAppletReq {
private Integer bizType;
private String device_token;
private String mobile;
private Integer flag;
private String token;
private String authCode;
private String password;
private String code;
private Integer type;
/**
* 加密后的密文
*/
private String key;
/**
* 加密后的数据
*/
private String content;
// 是否需要校验该设备登录的手机号
private Boolean checkFlag = false;
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Boolean getCheckFlag() {
return checkFlag;
}
public void setCheckFlag(Boolean checkFlag) {
this.checkFlag = checkFlag;
}
public Integer getBizType() {
return bizType;
}
public void setBizType(Integer bizType) {
this.bizType = bizType;
}
public String getDevice_token() {
return device_token;
}
public void setDevice_token(String device_token) {
this.device_token = device_token;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public Integer getFlag() {
return flag;
}
public void setFlag(Integer flag) {
this.flag = flag;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getAuthCode() {
return authCode;
}
public void setAuthCode(String authCode) {
this.authCode = authCode;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册