首页>代码>SpringBoot整合微信模板消息实现每日给女友发送早安问候语和天气预报>/wechat-push/src/main/java/com/cxs/client/impl/OutInterfaceClientImpl.java
package com.cxs.client.impl;
import com.alibaba.fastjson.JSON;
import com.cxs.client.OutInterfaceClient;
import com.cxs.client.req.SendMsgReq;
import com.cxs.client.resp.AccessTokenResp;
import com.cxs.client.resp.BaiduWeatherResp;
import com.cxs.client.resp.CaiHongPiResp;
import com.cxs.config.CommonConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
/**
* @Project: wechat-push
* @Author: cxs2014501@163.com
* @Create: 2023/9/7 10:40
* @Description:
**/
@Slf4j
@Service
public class OutInterfaceClientImpl implements OutInterfaceClient {
@Autowired
private RestTemplate restTemplate;
@Autowired
private CommonConfig commonConfig;
@Override
public BaiduWeatherResp getWeatherInfo() {
String baiduWeatherUrl = commonConfig.getBaiduWeatherUrl();
String url = baiduWeatherUrl
.replace("[1]", commonConfig.getBaiduDistrictId())
.replace("[2]", commonConfig.getBaiduAk());
return restTemplate.getForObject(url, BaiduWeatherResp.class);
}
@Override
public CaiHongPiResp getCaiHongPiInfo() {
String tianxingCaihongpiUrl = commonConfig.getTianxingCaihongpiUrl();
String url = tianxingCaihongpiUrl.replace("[1]", commonConfig.getTianxingKey());
return restTemplate.getForObject(url, CaiHongPiResp.class);
}
@Override
public AccessTokenResp getWeChatAccessToken() {
String tokenUrl = commonConfig.getTokenUrl();
String url = tokenUrl
.replace("[1]", commonConfig.getAppId())
.replace("[2]", commonConfig.getSecret());
return restTemplate.getForObject(url, AccessTokenResp.class);
}
}
最近下载更多
qiheideguang LV18
1月22日
goccgoccgocc LV4
2024年5月23日
小黄同学 LV8
2024年5月21日
2775645521 LV7
2024年4月23日
denliv_hui LV14
2024年3月31日
zhujunnan LV12
2024年3月8日
1289755 LV3
2023年11月25日
栈道小生 LV10
2023年11月16日
txf123 LV6
2023年11月14日
zhaixunfei LV8
2023年11月9日

最近浏览