package com.alatus.mall.thirdparty.controller;
import com.alatus.common.utils.R;
import com.alatus.mall.thirdparty.component.SmSComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/sms")
public class SmsSendController {
@Autowired
private SmSComponent smSComponent;
// 提供给别的服务用来调用的
@GetMapping("/sendCode")
public R sendCode(@RequestParam("phone") String phone,@RequestParam("code") String code){
smSComponent.sendSms(phone, code);
return R.ok();
}
}
package com.alatus.mall.thirdparty.controller;
import com.alatus.common.utils.R;
import com.alatus.mall.thirdparty.component.SmSComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/sms")
public class SmsSendController {
@Autowired
private SmSComponent smSComponent;
// 提供给别的服务用来调用的
@GetMapping("/sendCode")
public R sendCode(@RequestParam("phone") String phone,@RequestParam("code") String code){
smSComponent.sendSms(phone, code);
return R.ok();
}
}
package com.alatus.mall.auth.app;
import com.alatus.common.utils.R;
import com.alatus.mall.auth.feign.ThirdPartFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.UUID;
@Controller
public class LoginController {
@Autowired
private ThirdPartFeignService thirdPartFeignService;
@GetMapping("/sms/sendCode")
public R sendCode(@RequestParam("phone") String phone){
String code = UUID.randomUUID().toString().substring(0, 5);
R sendCode = thirdPartFeignService.sendCode(phone, code);
if(sendCode.getCode()==0){
return R.ok();
}
else{
return R.error();
}
}
}
package com.alatus.mall.auth.app;
import com.alatus.common.utils.R;
import com.alatus.mall.auth.feign.ThirdPartFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.UUID;
@Controller
public class LoginController {
@Autowired
private ThirdPartFeignService thirdPartFeignService;
@GetMapping("/sms/sendCode")
public R sendCode(@RequestParam("phone") String phone){
String code = UUID.randomUUID().toString().substring(0, 5);
R sendCode = thirdPartFeignService.sendCode(phone, code);
if(sendCode.getCode()==0){
return R.ok();
}
else{
return R.error();
}
}
}
package com.alatus.mall.auth.feign;
import com.alatus.common.utils.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@FeignClient("Mall-third-party")
public interface ThirdPartFeignService {
@GetMapping("/sms/sendCode")
R sendCode(@RequestParam("phone") String phone, @RequestParam("code") String code);
}
package com.alatus.mall.auth.feign;
import com.alatus.common.utils.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@FeignClient("Mall-third-party")
public interface ThirdPartFeignService {
@GetMapping("/sms/sendCode")
R sendCode(@RequestParam("phone") String phone, @RequestParam("code") String code);
}
package com.alatus.mall.auth;
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 MallAuthServerApplication {
public static void main(String[] args) {
SpringApplication.run(MallAuthServerApplication.class, args);
}
}
package com.alatus.mall.auth;
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 MallAuthServerApplication {
public static void main(String[] args) {
SpringApplication.run(MallAuthServerApplication.class, args);
}
}