feign远程调用,获取验证码

master
kezhen0805 2 years ago
parent 3f3c322ad5
commit f2bfef1987

@ -26,6 +26,17 @@
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId> <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.mashibing</groupId>
<artifactId>internal-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
</dependencies> </dependencies>
<properties> <properties>

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

@ -1,6 +1,10 @@
package com.mashibing.apipassenger.controller; package com.mashibing.apipassenger.controller;
import com.mashibing.apipassenger.service.VerificationCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/** /**
@ -11,8 +15,18 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
public class TestController { public class TestController {
@Autowired
VerificationCodeService verificationCodeService;
@GetMapping("/test") @GetMapping("/test")
public String test(){ public String test(){
return "tingting"; return "tingting";
} }
@GetMapping("/verification-code")
public String getNumberCode(){
String s = verificationCodeService.generatorCode("1234");
System.out.println("s = " + s);
return null;
}
} }

@ -0,0 +1,22 @@
package com.mashibing.apipassenger.remote;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.response.NumberCodeResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.lang.reflect.Method;
/**
* @author kezhen
* @date 2023/7/12
* @description
*/
@FeignClient("service-verificationcode")
public interface ServiceVefificationcodeClient {
@RequestMapping(method = RequestMethod.GET,value = "/numberCode/{size}")
ResponseResult<NumberCodeResponse> getNumberCode(@PathVariable("size") int size);
}

@ -0,0 +1,30 @@
package com.mashibing.apipassenger.service;
import com.mashibing.apipassenger.remote.ServiceVefificationcodeClient;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.response.NumberCodeResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author kezhen
* @date 2023/7/12
* @description
*/
@Service
public class VerificationCodeService {
@Autowired
ServiceVefificationcodeClient serviceVefificationcodeClient;
public String generatorCode(String passengerPhone) {
// 调用验证码服务,获取验证码
ResponseResult<NumberCodeResponse> numberCodeResponse = serviceVefificationcodeClient.getNumberCode(6);
int numberCode = numberCodeResponse.getData().getNumberCode();
System.out.println("numberCode = " + numberCode);
// 存入redis
return Integer.toString(numberCode);
}
}

@ -33,11 +33,7 @@
<classifier>jdk15</classifier> <classifier>jdk15</classifier>
</dependency> </dependency>
<dependency>
<groupId>com.mashibing</groupId>
<artifactId>internal-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>

@ -23,6 +23,12 @@
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.mashibing</groupId>
<artifactId>internal-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
<properties> <properties>

Loading…
Cancel
Save