WeChatServiceImpl.java 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.inspur.customer.service.wechat;
  2. import com.inspur.customer.client.wechat.IWeChatService;
  3. import com.inspur.customer.context.HttpUrlConstant;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.apache.dubbo.config.annotation.DubboService;
  6. import org.springframework.beans.factory.annotation.Value;
  7. import org.springframework.http.HttpEntity;
  8. import org.springframework.http.HttpHeaders;
  9. import org.springframework.http.HttpMethod;
  10. import org.springframework.http.ResponseEntity;
  11. import org.springframework.web.client.RestTemplate;
  12. import javax.annotation.Resource;
  13. /**
  14. * 发送微信
  15. *
  16. * @author wangbo
  17. * @version 1.0
  18. * @date 2022/3/9
  19. */
  20. @Slf4j
  21. @DubboService(interfaceClass = IWeChatService.class)
  22. public class WeChatServiceImpl implements IWeChatService {
  23. @Resource
  24. private RestTemplate restTemplate;
  25. @Value("${msr.idms.top}")
  26. private String MSR_IDMS_TOP;
  27. @Override
  28. public String queryTicket(String appKey, String userId, String authorization) {
  29. String url = String.format(HttpUrlConstant.QUERY_TICKET.replace("MSR_IDMS_TOP", MSR_IDMS_TOP), userId, appKey);
  30. HttpHeaders header = new HttpHeaders();
  31. // header.add("Authorization", authorization);
  32. ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<String>(header), String.class);
  33. log.info("获取二维码url: {}", url);
  34. return response.getBody();
  35. }
  36. @Override
  37. public String askUser(String userId) {
  38. return restTemplate.getForObject(String.format(HttpUrlConstant.ASK_USER.replace("MSR_IDMS_TOP", MSR_IDMS_TOP), userId), String.class);
  39. }
  40. }