add: 实现功能1

master
msb_89821 2 years ago
parent 01db3ae4d7
commit c6efd829da

@ -25,6 +25,11 @@
<groupId>com.alibaba.cloud</groupId> <groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>

@ -5,16 +5,14 @@ import com.alibaba.fastjson.JSON;
import com.mashibing.dto.PassengerRequestDto; import com.mashibing.dto.PassengerRequestDto;
import com.mashibing.dto.ResponseResult; import com.mashibing.dto.ResponseResult;
import com.mashibing.util.JwtUtils; import com.mashibing.util.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import mashibing.online.text.consonant.PassengerConsonant; import mashibing.online.text.consonant.PassengerConsonant;
import mashibing.online.text.dto.UserInfo; import mashibing.online.text.dto.UserInfo;
import mashibing.online.text.feign.SendSMSCodeService; import mashibing.online.text.feign.SendSMSCodeService;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -24,8 +22,9 @@ import java.util.concurrent.TimeUnit;
* @Description * @Description
* @date 2022/10/5 * @date 2022/10/5
*/ */
@Slf4j
@RestController @RestController
@RequestMapping("/passenger")
public class PassengerController { public class PassengerController {
@Resource @Resource
@ -45,7 +44,7 @@ public class PassengerController {
// 调服务获取验证码 // 调服务获取验证码
String smsCode = sendSMSCodeService.getSmsCode(6,passengerRequestDto.getPhoneNumber()); String smsCode = sendSMSCodeService.getSmsCode(6,passengerRequestDto.getPhoneNumber());
System.out.println(""+ JSON.toJSONString(smsCode)); log.info(""+ JSON.toJSONString(smsCode));
// 存入redis 有限时间 // 存入redis 有限时间
stringRedisTemplate.opsForValue().set(PassengerConsonant.phoneNumberCodePreKey+passengerRequestDto.getPhoneNumber(), stringRedisTemplate.opsForValue().set(PassengerConsonant.phoneNumberCodePreKey+passengerRequestDto.getPhoneNumber(),
smsCode,2, TimeUnit.MINUTES); smsCode,2, TimeUnit.MINUTES);
@ -74,7 +73,7 @@ public class PassengerController {
throw new RuntimeException("短信验证码错误!"); throw new RuntimeException("短信验证码错误!");
} }
// 用户注册 // 用户注册
System.out.println("phone 短信验证码正确"); log.info("phone {} 短信验证码正确!",phone);
// 返回token // 返回token
String token = JwtUtils.genaroteToken(phone, PassengerConsonant.PassengerIdendity); String token = JwtUtils.genaroteToken(phone, PassengerConsonant.PassengerIdendity);

@ -8,4 +8,8 @@ spring:
discovery: discovery:
server-addr: 127.0.0.1:8848 server-addr: 127.0.0.1:8848
application: application:
name: api-passinger name: api-passinger
redis:
host: 127.0.0.1
database: 0
port: 6379

@ -60,7 +60,7 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
<version> 2.2.1.RELEASE</version> <version>2.2.1.RELEASE</version>
</dependency> </dependency>
</dependencies> </dependencies>
@ -69,6 +69,7 @@
<module>api-passinger</module> <module>api-passinger</module>
<module>send-server</module> <module>send-server</module>
<module>untitled4</module> <module>untitled4</module>
<module>service-passenger-user</module>
</modules> </modules>
<dependencyManagement> <dependencyManagement>
@ -83,7 +84,7 @@
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId> <artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR2</version> <version>2020.0.1</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>

@ -23,10 +23,7 @@ import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.apache.tomcat.util.security.MD5Encoder; import org.apache.tomcat.util.security.MD5Encoder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import sun.security.provider.MD5; import sun.security.provider.MD5;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -44,7 +41,8 @@ import java.util.UUID;
* @date 2022/10/7 * @date 2022/10/7
*/ */
@Slf4j @Slf4j
@RestController("/send") @RestController
@RequestMapping("/send")
public class SendSmsCodeController { public class SendSmsCodeController {
public static final String CHARSET_UTF8 = "UTF-8"; public static final String CHARSET_UTF8 = "UTF-8";
@ -83,6 +81,10 @@ public class SendSmsCodeController {
UUID.randomUUID().toString()); UUID.randomUUID().toString());
String rutlet=post(smsAccount.getUrl() + PATH_SEND_SMS, params); String rutlet=post(smsAccount.getUrl() + PATH_SEND_SMS, params);
log.info("==="+rutlet); log.info("==="+rutlet);
if(StringUtils.isBlank(rutlet)){
log.error("获取验证码异常!");
return String.valueOf(radom);
}
JSONObject jsonObject=JSON.parseObject(rutlet); JSONObject jsonObject=JSON.parseObject(rutlet);
Integer status=jsonObject.getInteger("status"); Integer status=jsonObject.getInteger("status");
if (!Integer.valueOf(0).equals(status)){ if (!Integer.valueOf(0).equals(status)){

@ -0,0 +1,39 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>oneline-text-plublic</artifactId>
<groupId>com.mashibing</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.example</groupId>
<artifactId>service-passenger-user</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>service-passenger-user</name>
<description>service-passenger-user</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,15 @@
package com.example.servicepassengeruser;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
public class ServicePassengerUserApplication {
public static void main(String[] args) {
SpringApplication.run(ServicePassengerUserApplication.class, args);
}
}

@ -0,0 +1,10 @@
package com.example.servicepassengeruser;
class ServicePassengerUserApplicationTests {
}
Loading…
Cancel
Save