首页>代码>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);
    }
}
最近下载更多
2775645521  LV5 4月23日
denliv_hui  LV13 3月31日
zhujunnan  LV12 3月8日
1289755  LV3 2023年11月25日
栈道小生  LV10 2023年11月16日
txf123  LV4 2023年11月14日
zhaixunfei  LV8 2023年11月9日
wuhbujjs  LV7 2023年11月9日
帅涵123456  LV2 2023年11月5日
Seaskye  LV14 2023年11月4日
最近浏览更多
kenhomeliu  LV29 4月30日
win nas 4月28日
暂无贡献等级
2775645521  LV5 4月23日
东北虎啸  LV3 4月17日
feizai0101 4月14日
暂无贡献等级
泓鼎168  LV19 4月11日
不顾asdf  LV7 4月9日
暂无贡献等级
xiaozhi丶  LV14 4月7日
strongning  LV3 4月5日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友