From a4df21a0fd131fdd850a0aac8eb21489e0141680 Mon Sep 17 00:00:00 2001 From: wanggeng888 <450292408@qq.com> Date: Sun, 2 May 2021 16:21:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BE=AE=E4=BF=A1=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 1 + register-wechat/pom.xml | 28 ++++++++++ .../account/RegisterWechatController.java | 54 ++++++++++++++++++ .../OfficialAccountRegisterPhoneVO.java | 53 ++++++++++++++++++ .../IOfficialAccountRegisterService.java | 26 +++++++++ .../OfficialAccountRegisterServiceImpl.java | 56 +++++++++++++++++++ 6 files changed, 218 insertions(+) create mode 100644 register-wechat/pom.xml create mode 100644 register-wechat/src/main/java/ink/wgink/register/wechat/controller/app/api/official/account/RegisterWechatController.java create mode 100644 register-wechat/src/main/java/ink/wgink/register/wechat/service/miniapp/OfficialAccountRegisterPhoneVO.java create mode 100644 register-wechat/src/main/java/ink/wgink/register/wechat/service/official/account/IOfficialAccountRegisterService.java create mode 100644 register-wechat/src/main/java/ink/wgink/register/wechat/service/official/account/impl/OfficialAccountRegisterServiceImpl.java diff --git a/pom.xml b/pom.xml index 8dba1c97..e9a5f186 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,7 @@ module-wechat register-base module-sms + register-wechat pom diff --git a/register-wechat/pom.xml b/register-wechat/pom.xml new file mode 100644 index 00000000..e772dbff --- /dev/null +++ b/register-wechat/pom.xml @@ -0,0 +1,28 @@ + + + + wg-basic + ink.wgink + 1.0-SNAPSHOT + + 4.0.0 + + register-wechat + 微信注册模块 + + + + ink.wgink + service-user + 1.0-SNAPSHOT + + + ink.wgink + module-wechat + 1.0-SNAPSHOT + + + + \ No newline at end of file diff --git a/register-wechat/src/main/java/ink/wgink/register/wechat/controller/app/api/official/account/RegisterWechatController.java b/register-wechat/src/main/java/ink/wgink/register/wechat/controller/app/api/official/account/RegisterWechatController.java new file mode 100644 index 00000000..fca100ff --- /dev/null +++ b/register-wechat/src/main/java/ink/wgink/register/wechat/controller/app/api/official/account/RegisterWechatController.java @@ -0,0 +1,54 @@ +package ink.wgink.register.wechat.controller.app.api.official.account; + +import ink.wgink.annotation.CheckRequestBodyAnnotation; +import ink.wgink.common.base.DefaultBaseController; +import ink.wgink.exceptions.DependencyException; +import ink.wgink.exceptions.ParamsException; +import ink.wgink.interfaces.consts.ISystemConstant; +import ink.wgink.interfaces.sms.ISmsBaseService; +import ink.wgink.pojo.result.ErrorResult; +import ink.wgink.pojo.result.SuccessResult; +import ink.wgink.register.wechat.service.miniapp.OfficialAccountRegisterPhoneVO; +import ink.wgink.register.wechat.service.official.account.IOfficialAccountRegisterService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: RegisterController + * @Description: 注册 + * @Author: wanggeng + * @Date: 2021/4/29 6:12 下午 + * @Version: 1.0 + */ +@Api(tags = ISystemConstant.API_TAGS_WECHAT_PREFIX + "注册") +@RestController +@RequestMapping(ISystemConstant.WECHAT_PREFIX + "/register") +public class RegisterWechatController extends DefaultBaseController { + + @Autowired + private IOfficialAccountRegisterService officialAccountRegisterService; + + @ApiOperation(value = "手机注册", notes = "手机注册,手机 + 短信验证码接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("phone") + @CheckRequestBodyAnnotation + public synchronized SuccessResult phone(@RequestBody OfficialAccountRegisterPhoneVO officialAccountRegisterPhoneVO) throws Exception { + Map params = requestParams(); + officialAccountRegisterService.phoneRegister(officialAccountRegisterPhoneVO, params); + return new SuccessResult(); + } + +} diff --git a/register-wechat/src/main/java/ink/wgink/register/wechat/service/miniapp/OfficialAccountRegisterPhoneVO.java b/register-wechat/src/main/java/ink/wgink/register/wechat/service/miniapp/OfficialAccountRegisterPhoneVO.java new file mode 100644 index 00000000..716dba1a --- /dev/null +++ b/register-wechat/src/main/java/ink/wgink/register/wechat/service/miniapp/OfficialAccountRegisterPhoneVO.java @@ -0,0 +1,53 @@ +package ink.wgink.register.wechat.service.miniapp; + +import ink.wgink.annotation.CheckEmptyAnnotation; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: RegisterPhoneVO + * @Description: 手机注册 + * @Author: wanggeng + * @Date: 2021/5/1 11:47 上午 + * @Version: 1.0 + */ +@ApiModel +public class OfficialAccountRegisterPhoneVO { + + @ApiModelProperty(name = "phone", value = "手机号") + @CheckEmptyAnnotation(name = "手机号", verifyType = "phone") + private String phone; + @ApiModelProperty(name = "userCode", value = "用户码") + @CheckEmptyAnnotation(name = "用户码") + private String userCode; + + public String getPhone() { + return phone == null ? "" : phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getUserCode() { + return userCode == null ? "" : userCode; + } + + public void setUserCode(String userCode) { + this.userCode = userCode; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"phone\":\"") + .append(phone).append('\"'); + sb.append(",\"verifyCode\":\"") + .append(userCode).append('\"'); + sb.append('}'); + return sb.toString(); + } +} diff --git a/register-wechat/src/main/java/ink/wgink/register/wechat/service/official/account/IOfficialAccountRegisterService.java b/register-wechat/src/main/java/ink/wgink/register/wechat/service/official/account/IOfficialAccountRegisterService.java new file mode 100644 index 00000000..29263ee4 --- /dev/null +++ b/register-wechat/src/main/java/ink/wgink/register/wechat/service/official/account/IOfficialAccountRegisterService.java @@ -0,0 +1,26 @@ +package ink.wgink.register.wechat.service.official.account; + +import ink.wgink.register.wechat.service.miniapp.OfficialAccountRegisterPhoneVO; + +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: IOfficialAccountRegisterService + * @Description: 公众号注册 + * @Author: wanggeng + * @Date: 2021/5/2 3:56 下午 + * @Version: 1.0 + */ +public interface IOfficialAccountRegisterService { + + /** + * 手机注册 + 用户码注册 + * + * @param officialAccountRegisterPhoneVO + * @param params + */ + void phoneRegister(OfficialAccountRegisterPhoneVO officialAccountRegisterPhoneVO, Map params); +} diff --git a/register-wechat/src/main/java/ink/wgink/register/wechat/service/official/account/impl/OfficialAccountRegisterServiceImpl.java b/register-wechat/src/main/java/ink/wgink/register/wechat/service/official/account/impl/OfficialAccountRegisterServiceImpl.java new file mode 100644 index 00000000..bf356379 --- /dev/null +++ b/register-wechat/src/main/java/ink/wgink/register/wechat/service/official/account/impl/OfficialAccountRegisterServiceImpl.java @@ -0,0 +1,56 @@ +package ink.wgink.register.wechat.service.official.account.impl; + +import ink.wgink.common.base.DefaultBaseService; +import ink.wgink.exceptions.SearchException; +import ink.wgink.exceptions.UpdateException; +import ink.wgink.interfaces.consts.ISystemConstant; +import ink.wgink.module.wechat.pojo.dtos.official.account.OfficialAccountUserDTO; +import ink.wgink.module.wechat.pojo.pos.official.account.OfficialAccountUserPO; +import ink.wgink.module.wechat.service.official.account.IOfficialAccountUserService; +import ink.wgink.register.wechat.service.miniapp.OfficialAccountRegisterPhoneVO; +import ink.wgink.register.wechat.service.official.account.IOfficialAccountRegisterService; +import ink.wgink.service.user.pojo.vos.UpdateUsernameVO; +import ink.wgink.service.user.service.IUserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: OfficialAccountRegisterServiceImpl + * @Description: 公众号注册 + * @Author: wanggeng + * @Date: 2021/5/2 3:56 下午 + * @Version: 1.0 + */ +@Service +public class OfficialAccountRegisterServiceImpl extends DefaultBaseService implements IOfficialAccountRegisterService { + + @Autowired + private IUserService userService; + @Autowired + private IOfficialAccountUserService officialAccountUserService; + + @Override + public void phoneRegister(OfficialAccountRegisterPhoneVO officialAccountRegisterPhoneVO, Map params) { + OfficialAccountUserPO officialAccountUserPO = officialAccountUserService.getPOByUserCode(officialAccountRegisterPhoneVO.getUserCode()); + if (officialAccountUserPO == null) { + throw new SearchException("验证码错误"); + } + if (officialAccountUserPO.getIsInitAccount() == 0) { + throw new UpdateException("已经绑定用户"); + } + // 更新用户名 + UpdateUsernameVO updateUsernameVO = new UpdateUsernameVO(); + updateUsernameVO.setUsername(officialAccountRegisterPhoneVO.getPhone()); + updateUsernameVO.setUpdateReason("公众号验证码绑定手机"); + userService.updateUsername(officialAccountUserPO.getUserId(), updateUsernameVO); + // 修改初始账号标识 + officialAccountUserService.updateIsInitAccount(officialAccountUserPO.getOpenId(), 0); + } + + +}