api-passenger通过feign可变参数控制的方式,调用service-verificationcode,获取验证码

main
topsun 2 years ago
parent 3d8c978e1a
commit 417a48020d

@ -28,10 +28,21 @@
<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-openfeign</artifactId>
</dependency>
<dependency>
<groupId>com.internal</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>
</project>

@ -3,15 +3,17 @@ package com.taxi.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;
/**
* Spring Cloud @EnableDiscoveryClient
*/
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class ApiPassengerApplication {
public static void main(String[] args) {
public static void main(String[] args) {
SpringApplication.run(ApiPassengerApplication.class);
}
}

@ -1,14 +0,0 @@
package com.taxi.apipassenger.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
class TestController {
@GetMapping("/test")
public String test(){
return "test";
}
}

@ -0,0 +1,15 @@
package com.taxi.apipassenger.remote;
import com.internal.dto.ResponseResult;
import com.internal.response.NumberResponse;
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;
@FeignClient("service-verificationcode")
public interface ServiceVerificatoncodeClient {
@RequestMapping(method = RequestMethod.GET,value = "/numberCode/{size}")
ResponseResult<NumberResponse> getNumberCode(@PathVariable("size") int size);
}

@ -1,24 +1,33 @@
package com.taxi.apipassenger.service;
import com.internal.dto.ResponseResult;
import com.internal.response.NumberResponse;
import com.taxi.apipassenger.remote.ServiceVerificatoncodeClient;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class VerificationCodeService {
public String generatorCode(String passenegerPhone){
@Autowired
private ServiceVerificatoncodeClient serviceVerificatoncodeClient;
public String generatorCode(String passenegerPhone) {
//调用验证码服务,获取验证码
System.out.println("调用验证码服务,获取验证码");
String code = "11111";
ResponseResult<NumberResponse> responseResult = serviceVerificatoncodeClient.getNumberCode(6);
int code = responseResult.getData().getNumberCode();
System.out.println("访问service-verificationcode服务获取验证码" + code );
//存入redis
System.out.println("存入redis");
//返回值
JSONObject result =new JSONObject();
result.put("code",1);
result.put("message","success");
JSONObject result = new JSONObject();
result.put("code", code);
result.put("message", "success");
return result.toString();
}
}

Loading…
Cancel
Save