feat(微信登录): 新增通过openid绑定微信小程序用户功能
添加BindWxMpUserByOpenidCommand命令对象和对应的绑定接口 在WxUserApplicationService中实现通过openid直接绑定的逻辑
This commit is contained in:
parent
bd2cd96163
commit
d6495cf4e0
|
|
@ -9,6 +9,7 @@ import com.agileboot.domain.ab98.api.SsoLoginUserinfo;
|
||||||
import com.agileboot.domain.ab98.user.Ab98UserApplicationService;
|
import com.agileboot.domain.ab98.user.Ab98UserApplicationService;
|
||||||
import com.agileboot.domain.ab98.user.command.BindQyUserCommand;
|
import com.agileboot.domain.ab98.user.command.BindQyUserCommand;
|
||||||
import com.agileboot.domain.ab98.user.command.BindWxMpUserCommand;
|
import com.agileboot.domain.ab98.user.command.BindWxMpUserCommand;
|
||||||
|
import com.agileboot.domain.ab98.user.command.BindWxMpUserByOpenidCommand;
|
||||||
import com.agileboot.domain.ab98.user.db.Ab98UserEntity;
|
import com.agileboot.domain.ab98.user.db.Ab98UserEntity;
|
||||||
import com.agileboot.domain.qywx.user.QyUserApplicationService;
|
import com.agileboot.domain.qywx.user.QyUserApplicationService;
|
||||||
import com.agileboot.domain.wx.user.WxUserApplicationService;
|
import com.agileboot.domain.wx.user.WxUserApplicationService;
|
||||||
|
|
@ -190,4 +191,25 @@ public class WxLoginController {
|
||||||
return ResponseDTO.fail(new ApiException(ErrorCode.Internal.INTERNAL_ERROR, "绑定失败: " + e.getMessage()));
|
return ResponseDTO.fail(new ApiException(ErrorCode.Internal.INTERNAL_ERROR, "绑定失败: " + e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/bindWxMpUserByOpenid")
|
||||||
|
@ApiOperation(value = "绑定微信小程序用户到汇邦云", notes = "通过openid、企业ID、姓名、身份证绑定微信小程序用户到汇邦云")
|
||||||
|
public ResponseDTO<String> bindWxMpUserByOpenid(@RequestBody BindWxMpUserByOpenidCommand command) {
|
||||||
|
if (command == null || StringUtils.isBlank(command.getOpenid()) || StringUtils.isBlank(command.getName()) || StringUtils.isBlank(command.getIdNum())) {
|
||||||
|
log.error("绑定微信小程序用户到汇邦云参数错误: {}", JSONUtil.toJsonStr(command));
|
||||||
|
return ResponseDTO.fail(new ApiException(ErrorCode.Client.COMMON_REQUEST_PARAMETERS_INVALID, "参数错误"));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
boolean success = wxUserApplicationService.bindWxMpUserByOpenid(command);
|
||||||
|
if (success) {
|
||||||
|
return ResponseDTO.ok("绑定成功");
|
||||||
|
} else {
|
||||||
|
return ResponseDTO.fail(new ApiException(ErrorCode.Internal.INTERNAL_ERROR, "绑定失败"));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("绑定微信小程序用户到汇邦云失败: ", e);
|
||||||
|
return ResponseDTO.fail(new ApiException(ErrorCode.Internal.INTERNAL_ERROR, "绑定失败: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.agileboot.domain.ab98.user.command;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class BindWxMpUserByOpenidCommand {
|
||||||
|
private String openid;
|
||||||
|
|
||||||
|
private String corpid;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String idNum;
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,7 @@ import com.agileboot.domain.ab98.api.Ab98UserDto;
|
||||||
import com.agileboot.domain.ab98.user.Ab98UserApplicationService;
|
import com.agileboot.domain.ab98.user.Ab98UserApplicationService;
|
||||||
import com.agileboot.domain.ab98.user.command.AddAb98UserCommand;
|
import com.agileboot.domain.ab98.user.command.AddAb98UserCommand;
|
||||||
import com.agileboot.domain.ab98.user.command.BindWxMpUserCommand;
|
import com.agileboot.domain.ab98.user.command.BindWxMpUserCommand;
|
||||||
|
import com.agileboot.domain.ab98.user.command.BindWxMpUserByOpenidCommand;
|
||||||
import com.agileboot.domain.ab98.user.command.UpdateAb98UserCommand;
|
import com.agileboot.domain.ab98.user.command.UpdateAb98UserCommand;
|
||||||
import com.agileboot.domain.ab98.user.db.Ab98UserEntity;
|
import com.agileboot.domain.ab98.user.db.Ab98UserEntity;
|
||||||
import com.agileboot.domain.ab98.user.db.Ab98UserService;
|
import com.agileboot.domain.ab98.user.db.Ab98UserService;
|
||||||
|
|
@ -285,6 +286,7 @@ public class WxUserApplicationService {
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean bindWxMpUserWithOpenid(BindWxMpUserCommand command, String openid) {
|
public boolean bindWxMpUserWithOpenid(BindWxMpUserCommand command, String openid) {
|
||||||
|
// ... existing implementation
|
||||||
if (command == null || StringUtils.isBlank(openid)
|
if (command == null || StringUtils.isBlank(openid)
|
||||||
|| StringUtils.isBlank(command.getName())
|
|| StringUtils.isBlank(command.getName())
|
||||||
|| StringUtils.isBlank(command.getIdNum())) {
|
|| StringUtils.isBlank(command.getIdNum())) {
|
||||||
|
|
@ -374,6 +376,29 @@ public class WxUserApplicationService {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定微信小程序用户到汇邦云(直接传入 openid)
|
||||||
|
*
|
||||||
|
* @param command 绑定命令(包含openid、企业ID、姓名、身份证)
|
||||||
|
* @return 绑定是否成功
|
||||||
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean bindWxMpUserByOpenid(BindWxMpUserByOpenidCommand command) {
|
||||||
|
if (command == null || StringUtils.isBlank(command.getOpenid())
|
||||||
|
|| StringUtils.isBlank(command.getName())
|
||||||
|
|| StringUtils.isBlank(command.getIdNum())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a BindWxMpUserCommand to reuse the existing implementation
|
||||||
|
BindWxMpUserCommand bindCommand = new BindWxMpUserCommand();
|
||||||
|
bindCommand.setName(command.getName());
|
||||||
|
bindCommand.setIdNum(command.getIdNum());
|
||||||
|
bindCommand.setCorpid(command.getCorpid());
|
||||||
|
|
||||||
|
return bindWxMpUserWithOpenid(bindCommand, command.getOpenid());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据openid更新用户昵称和头像
|
* 根据openid更新用户昵称和头像
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue