diff --git a/user-service/src/main/java/com/hp/user/service/config/SwaggerConfig1.java b/user-service/src/main/java/com/hp/user/service/config/SwaggerConfig1.java deleted file mode 100644 index 54a4baa..0000000 --- a/user-service/src/main/java/com/hp/user/service/config/SwaggerConfig1.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.hp.user.service.config; - -import org.springframework.context.annotation.Bean; - -import org.springframework.context.annotation.Configuration; -import springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; - - -@Configuration -@EnableSwagger2 -public class SwaggerConfig1{ - /** - * 创建API应用 - * apiInfo() 增加API相关信息 - * 通过select()函数返回一个ApiSelectorBuilder实例,用来控制哪些接口暴露给Swagger来展现, - * 本例采用指定扫描的包路径来定义指定要建立API的目录。 - * - * @return - */ - @Bean - public Docket createRestApi() { - return new Docket(DocumentationType.SWAGGER_2) - .apiInfo(apiInfo()) - .select() - .apis(RequestHandlerSelectors.basePackage("com.hp.user.service.controller")) - .paths(PathSelectors.any()) - .build(); - } - - /** - * 创建该API的基本信息(这些基本信息会展现在文档页面中) - * 访问地址:http://项目实际地址/swagger-ui.html - * @return - */ - private ApiInfo apiInfo() { - return new ApiInfoBuilder() - .title("Spring Boot中使用Swagger2构建RESTful APIs") - .version("1.0") - .build(); - } -} diff --git a/user-service/src/main/java/com/hp/user/service/controller/AuthenticationController.java b/user-service/src/main/java/com/hp/user/service/controller/AuthenticationController.java index a02b054..39e792d 100644 --- a/user-service/src/main/java/com/hp/user/service/controller/AuthenticationController.java +++ b/user-service/src/main/java/com/hp/user/service/controller/AuthenticationController.java @@ -5,7 +5,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import com.hp.user.client.entity.AccountVO; import com.hp.user.client.service.AccountService; +import com.hp.user.service.entity.Account; import io.swagger.annotations.Api; @@ -41,8 +43,27 @@ public class AuthenticationController { * 需要用户信息 */ @RequestMapping("/register") - public void register() { - + public void register(AccountVO account) { + accountService.register(account); + } + + /** + * 微信注册 + * 需要用户信息 + */ + @RequestMapping("/wxRegister") + public void wxRegister() { + + } + + /** + * 绑定微信号 + * @param userId + * @param wxNumber + */ + @RequestMapping("/bingWx") + public void bindWx(String userId,String wxNumber) { + accountService.bindWx(userId, wxNumber); } diff --git a/user-service/src/main/java/com/hp/user/service/entity/Account.java b/user-service/src/main/java/com/hp/user/service/entity/Account.java index 2dbcf7b..f1f3c9f 100644 --- a/user-service/src/main/java/com/hp/user/service/entity/Account.java +++ b/user-service/src/main/java/com/hp/user/service/entity/Account.java @@ -25,7 +25,7 @@ public class Account implements Serializable { * 用户Id */ @TableId(value = "user_id") - private String userId; + private Long userId; /** * 用户名 */ @@ -57,7 +57,7 @@ public class Account implements Serializable { public Account(){} - public Account(String userId, String userName, String wxNumber, String phone, Date sysCreateTime, String sysCreator, Date sysUpdateTime, String sysUpdater) { + public Account(Long userId, String userName, String wxNumber, String phone, Date sysCreateTime, String sysCreator, Date sysUpdateTime, String sysUpdater) { this.userId = userId; this.userName = userName; this.wxNumber = wxNumber; @@ -68,11 +68,11 @@ public class Account implements Serializable { this.sysUpdater = sysUpdater; } - public String getUserId() { + public Long getUserId() { return userId; } - public void setUserId(String userId) { + public void setUserId(Long userId) { this.userId = userId; } diff --git a/user-service/src/main/java/com/hp/user/service/impl/AccountServiceImpl.java b/user-service/src/main/java/com/hp/user/service/impl/AccountServiceImpl.java index 8e0174b..57a94e0 100644 --- a/user-service/src/main/java/com/hp/user/service/impl/AccountServiceImpl.java +++ b/user-service/src/main/java/com/hp/user/service/impl/AccountServiceImpl.java @@ -1,9 +1,20 @@ package com.hp.user.service.impl; +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; +import com.hp.user.client.entity.AccountVO; import com.hp.user.client.service.AccountService; import com.hp.user.client.service.MessageService; +import com.hp.user.service.constants.UserConstants; +import com.hp.user.service.dao.AccountMapper; +import com.hp.user.service.entity.Account; +import com.hp.user.service.redis.RedisOperation; + +import redis.clients.jedis.Jedis; import org.apache.commons.codec.binary.StringUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,19 +31,77 @@ public class AccountServiceImpl implements AccountService { @Autowired private MessageService messageService; + + @Autowired + private AccountMapper accountMapper; @Override public void login(String phone, String verificationCode) { try { + //需要判断phone是否存在 + checkPhone(phone); String code = messageService.getVerificationCode(phone); if(StringUtils.equals(verificationCode, code)) { //登陆成功 }else { - //登陆失败,返回验证码 + //登陆失败 + //返回错误信息 + } + }catch(Exception e) { + + } + } + + @Override + public Boolean checkPhone(String phone) { + //不存在为true + Boolean flage = true; + try { + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("phone", phone); + queryWrapper.eq("sys_deleted", 0); + Integer count = accountMapper.selectCount(queryWrapper); + if(count>0) { + //表示手机以及存在,需要返回错误 + System.out.println("手机号已经存在"); + flage = false; + } + + }catch(Exception e) { + + } + return flage; + + } + + @Override + public void register(AccountVO accountVo) { + try { + if(checkPhone(accountVo.getPhone())) { + Account account = new Account(); + BeanUtils.copyProperties(accountVo, account); + account.setUserId(IdWorker.getId()); + accountMapper.insert(account); } }catch(Exception e) { } + + } + + @Override + public void bindWx(String userIdStr, String wxNumber) { + try { + Long userId = Long.parseLong(userIdStr); + Account account = new Account(); + account.setUserId(userId); + account.setWxNumber(wxNumber); + accountMapper.updateById(account); + }catch(Exception e) { + + } + } } diff --git a/user-service/src/main/java/com/hp/user/service/impl/MessageServiceImpl.java b/user-service/src/main/java/com/hp/user/service/impl/MessageServiceImpl.java index 1823ec4..67ab76b 100644 --- a/user-service/src/main/java/com/hp/user/service/impl/MessageServiceImpl.java +++ b/user-service/src/main/java/com/hp/user/service/impl/MessageServiceImpl.java @@ -56,8 +56,11 @@ public class MessageServiceImpl implements MessageService { @Override public String getVerificationCode(String phone) { - // TODO Auto-generated method stub - return null; + Jedis jedis = redisOperation.getRedis(); + String key = UserConstants.VERIFICATION_CODE+phone; + String code = jedis.get(key); + jedis.del(key); + return code; } } diff --git a/user-service/src/main/java/com/hp/user/service/redis/RedisOperation.java b/user-service/src/main/java/com/hp/user/service/redis/RedisOperation.java index 851932e..3ec0189 100644 --- a/user-service/src/main/java/com/hp/user/service/redis/RedisOperation.java +++ b/user-service/src/main/java/com/hp/user/service/redis/RedisOperation.java @@ -139,7 +139,7 @@ public class RedisOperation implements ApplicationRunner{ @Override public void run(ApplicationArguments args) throws Exception { - System.out.print("redis"); +// System.out.print("redis"); // JedisPool pool = null; // common-pool配置 if (pool == null) {