From d6495cf4e014bf9f5a458228567d2c8bd3cf33a0 Mon Sep 17 00:00:00 2001 From: dzq Date: Tue, 9 Dec 2025 16:10:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=BE=AE=E4=BF=A1=E7=99=BB=E5=BD=95):=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=80=9A=E8=BF=87openid=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加BindWxMpUserByOpenidCommand命令对象和对应的绑定接口 在WxUserApplicationService中实现通过openid直接绑定的逻辑 --- .../api/controller/WxLoginController.java | 22 ++++++++++++++++ .../command/BindWxMpUserByOpenidCommand.java | 14 +++++++++++ .../wx/user/WxUserApplicationService.java | 25 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 agileboot-domain/src/main/java/com/agileboot/domain/ab98/user/command/BindWxMpUserByOpenidCommand.java diff --git a/agileboot-api/src/main/java/com/agileboot/api/controller/WxLoginController.java b/agileboot-api/src/main/java/com/agileboot/api/controller/WxLoginController.java index 5021455..aec375b 100644 --- a/agileboot-api/src/main/java/com/agileboot/api/controller/WxLoginController.java +++ b/agileboot-api/src/main/java/com/agileboot/api/controller/WxLoginController.java @@ -9,6 +9,7 @@ import com.agileboot.domain.ab98.api.SsoLoginUserinfo; import com.agileboot.domain.ab98.user.Ab98UserApplicationService; import com.agileboot.domain.ab98.user.command.BindQyUserCommand; 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.qywx.user.QyUserApplicationService; 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())); } } + + @PostMapping("/bindWxMpUserByOpenid") + @ApiOperation(value = "绑定微信小程序用户到汇邦云", notes = "通过openid、企业ID、姓名、身份证绑定微信小程序用户到汇邦云") + public ResponseDTO 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())); + } + } } diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/ab98/user/command/BindWxMpUserByOpenidCommand.java b/agileboot-domain/src/main/java/com/agileboot/domain/ab98/user/command/BindWxMpUserByOpenidCommand.java new file mode 100644 index 0000000..0c87377 --- /dev/null +++ b/agileboot-domain/src/main/java/com/agileboot/domain/ab98/user/command/BindWxMpUserByOpenidCommand.java @@ -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; +} diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/wx/user/WxUserApplicationService.java b/agileboot-domain/src/main/java/com/agileboot/domain/wx/user/WxUserApplicationService.java index 89e486e..fd08147 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/wx/user/WxUserApplicationService.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/wx/user/WxUserApplicationService.java @@ -6,6 +6,7 @@ import com.agileboot.domain.ab98.api.Ab98UserDto; import com.agileboot.domain.ab98.user.Ab98UserApplicationService; import com.agileboot.domain.ab98.user.command.AddAb98UserCommand; 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.db.Ab98UserEntity; import com.agileboot.domain.ab98.user.db.Ab98UserService; @@ -285,6 +286,7 @@ public class WxUserApplicationService { */ @Transactional(rollbackFor = Exception.class) public boolean bindWxMpUserWithOpenid(BindWxMpUserCommand command, String openid) { + // ... existing implementation if (command == null || StringUtils.isBlank(openid) || StringUtils.isBlank(command.getName()) || StringUtils.isBlank(command.getIdNum())) { @@ -374,6 +376,29 @@ public class WxUserApplicationService { 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更新用户昵称和头像 *