hi大家好呀~感谢你们的收看~话不多说直接开始~
今天第一部分内容也比较简单,是远程调用
流程如下,请看图
web-customer接口
现在controller里写入代码,调service方法最终返回VO对象
在Service中实现代码(可以根据这个手敲)
service方法最终返回VO对象
@Override
public CustomerLoginVo getCustomerLoginInfo(String token) {
//2 根据token查询redis
//3 查询token在redis里面对应用户id
String customerId =
(String)redisTemplate.opsForValue()
.get(RedisConstant.USER_LOGIN_KEY_PREFIX + token);
if(StringUtils.isEmpty(customerId)) {
throw new GuiguException(ResultCodeEnum.DATA_ERROR);
}
// if(!StringUtils.hasText(customerId)) {
// throw new GuiguException(ResultCodeEnum.DATA_ERROR);
// }
//4 根据用户id进行远程调用 得到用户信息
Result<CustomerLoginVo> customerLoginVoResult =
customerInfoFeignClient.getCustomerLoginInfo(Long.parseLong(customerId));
Integer code = customerLoginVoResult.getCode();
if(code != 200) {
throw new GuiguException(ResultCodeEnum.DATA_ERROR);
}
CustomerLoginVo customerLoginVo = customerLoginVoResult.getData();
if(customerLoginVo == null) {
throw new GuiguException(ResultCodeEnum.DATA_ERROR);
}
//5 返回用户信息
return customerLoginVo;
}
要记得在如下接口实现好,并且@GetMapping路径要一致!!
@FeignClient(value = "service-customer")
public interface CustomerInfoFeignClient {
@GetMapping("/customer/info/login/{code}")
public Result<Long> login(@PathVariable String code);
@GetMapping("/customer/info/getCustomerLoginInfo/{customerId}")
Result<CustomerLoginVo> getCustomerLoginInfo(@PathVariable("customerId") Long customerId);
当你全弄完后~启动这三个
然后你会在微信小程序端发现一个神奇的报错,这个无视即可,因为还未开发,是为了获取你的位置信息的