通过open feign 方式调用service-verificationcode

master
liuyuanqiang 2 years ago
parent fac441d3e2
commit 585cb383bd

@ -21,6 +21,24 @@
<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>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>org.mashibing</groupId>
<artifactId>internal-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

@ -3,9 +3,11 @@ package com.mashibing.apipassenger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class ApiPassengerApplication {
//log
public static void main(String[] args) {

@ -0,0 +1,13 @@
package com.mashibing.apipassenger.remote;
import com.mashibing.common.dto.ResponseResult;
import com.mashibing.common.response.NumberCodeResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@FeignClient("service-verificationcode")
public interface ServiceVefificationcodeClient {
@GetMapping("/numberCode/{size}")
ResponseResult<NumberCodeResponse> getNumberCode(@PathVariable("size") int size);
}

@ -1,15 +1,22 @@
package com.mashibing.apipassenger.service;
import com.mashibing.apipassenger.remote.ServiceVefificationcodeClient;
import com.mashibing.common.dto.ResponseResult;
import com.mashibing.common.response.NumberCodeResponse;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class VerificationCodeService {
@Autowired
ServiceVefificationcodeClient serviceVefificationcodeClient;
public String generatorCode(String passengerPhone){
//调用验证码服务,获取验证码
System.out.println("调用验证码服务,获取验证码");
String code = "111111";
ResponseResult<NumberCodeResponse> responseResult = serviceVefificationcodeClient.getNumberCode(6);
int numberCode = responseResult.getData().getNumberCode();
System.out.println("接收到的numberCode:" + numberCode);
//存入redis
System.out.println("存入redis");

@ -34,24 +34,39 @@
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
<!-- nacos 依赖 -->
<!-- nacos 依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2021.1</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2021.1</version>
</dependency>
</dependency>-->
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2021.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2020.0.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>

@ -32,6 +32,11 @@
<artifactId>internal-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies>
<build>

@ -18,7 +18,7 @@ public class NumberCodeController {
//获取随机数
double mathRandom = (Math.random() * 9 + 1) * pow(10, size-1);
int resultInt = (int) mathRandom;
System.out.println(resultInt);
System.out.println("generate numberCode:" + resultInt);
NumberCodeResponse response = new NumberCodeResponse();
response.setNumberCode(resultInt);

Loading…
Cancel
Save