新增微信注册模块

This commit is contained in:
wanggeng888 2021-05-02 16:21:24 +08:00
parent 6e645514af
commit a4df21a0fd
6 changed files with 218 additions and 0 deletions

View File

@ -33,6 +33,7 @@
<module>module-wechat</module>
<module>register-base</module>
<module>module-sms</module>
<module>register-wechat</module>
</modules>
<packaging>pom</packaging>

28
register-wechat/pom.xml Normal file
View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>wg-basic</artifactId>
<groupId>ink.wgink</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>register-wechat</artifactId>
<description>微信注册模块</description>
<dependencies>
<dependency>
<groupId>ink.wgink</groupId>
<artifactId>service-user</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ink.wgink</groupId>
<artifactId>module-wechat</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -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<String, Object> params = requestParams();
officialAccountRegisterService.phoneRegister(officialAccountRegisterPhoneVO, params);
return new SuccessResult();
}
}

View File

@ -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();
}
}

View File

@ -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<String, Object> params);
}

View File

@ -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<String, Object> 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);
}
}