修复了一些问题
This commit is contained in:
@@ -2,7 +2,6 @@ package com.bamanker.dailylove.config;
|
|||||||
|
|
||||||
import cn.hutool.core.util.ClassUtil;
|
import cn.hutool.core.util.ClassUtil;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ package com.bamanker.dailylove.controller;
|
|||||||
import cn.hutool.core.date.ChineseDate;
|
import cn.hutool.core.date.ChineseDate;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.bamanker.dailylove.config.DailyLoveConfigure;
|
import com.bamanker.dailylove.config.DailyLoveConfigure;
|
||||||
import com.bamanker.dailylove.domain.*;
|
import com.bamanker.dailylove.domain.DataItem;
|
||||||
|
import com.bamanker.dailylove.domain.ResultVo;
|
||||||
|
import com.bamanker.dailylove.domain.TianXinReqParam;
|
||||||
|
import com.bamanker.dailylove.domain.Weather;
|
||||||
import com.bamanker.dailylove.exception.PushException;
|
import com.bamanker.dailylove.exception.PushException;
|
||||||
import com.bamanker.dailylove.service.DataRemoteService;
|
import com.bamanker.dailylove.service.DataRemoteService;
|
||||||
import com.bamanker.dailylove.service.WechatRequestService;
|
import com.bamanker.dailylove.service.WechatRequestService;
|
||||||
@@ -143,9 +146,7 @@ public class PushDailyController {
|
|||||||
// 获取微信访问令牌并发送消息
|
// 获取微信访问令牌并发送消息
|
||||||
return wechatRequestService.getAccessToken("client_credential", DailyLoveConfigure.App_ID, DailyLoveConfigure.App_Secret)
|
return wechatRequestService.getAccessToken("client_credential", DailyLoveConfigure.App_ID, DailyLoveConfigure.App_Secret)
|
||||||
.onErrorMap(throwable -> new PushException("获取微信访问令牌失败: " + throwable.getMessage(), throwable))
|
.onErrorMap(throwable -> new PushException("获取微信访问令牌失败: " + throwable.getMessage(), throwable))
|
||||||
.map(tokenResp -> {
|
.map(tokenResp -> mapper.readTree(tokenResp).get("access_token").asString())
|
||||||
return mapper.readTree(tokenResp).get("access_token").asString();
|
|
||||||
})
|
|
||||||
.flatMap(accessToken -> wechatRequestService.sendMsg(accessToken, resultVo)
|
.flatMap(accessToken -> wechatRequestService.sendMsg(accessToken, resultVo)
|
||||||
.doOnNext(this::printPushLog)
|
.doOnNext(this::printPushLog)
|
||||||
.onErrorMap(throwable -> new PushException("发送微信消息失败: " + throwable.getMessage(), throwable)));
|
.onErrorMap(throwable -> new PushException("发送微信消息失败: " + throwable.getMessage(), throwable)));
|
||||||
@@ -218,14 +219,14 @@ public class PushDailyController {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// 解析天气数据
|
// 解析天气数据
|
||||||
String city = mapper.readTree(weatherResp).get("result").get("area").asText();
|
String city = mapper.readTree(weatherResp).get("result").get("area").asString();
|
||||||
var weatherData = mapper.readTree(weatherResp).get("result").get("list").get(0);
|
var weatherData = mapper.readTree(weatherResp).get("result").get("list").get(0);
|
||||||
Weather weather = mapper.treeToValue(weatherData, Weather.class);
|
Weather weather = mapper.treeToValue(weatherData, Weather.class);
|
||||||
|
|
||||||
// 解析其他数据
|
// 解析其他数据
|
||||||
String tips = mapper.readTree(tipsResp).get("result").get("content").asText();
|
String tips = mapper.readTree(tipsResp).get("result").get("content").asString();
|
||||||
String morningContent = mapper.readTree(morningResp).get("result").get("content").asText();
|
String morningContent = mapper.readTree(morningResp).get("result").get("content").asString();
|
||||||
String rainbowContent = mapper.readTree(rainbowResp).get("result").get("content").asText();
|
String rainbowContent = mapper.readTree(rainbowResp).get("result").get("content").asString();
|
||||||
|
|
||||||
// 创建结果对象
|
// 创建结果对象
|
||||||
ResultVo resultVo = ResultVo.initializeResultVo(DailyLoveConfigure.Open_ID,
|
ResultVo resultVo = ResultVo.initializeResultVo(DailyLoveConfigure.Open_ID,
|
||||||
@@ -254,9 +255,7 @@ public class PushDailyController {
|
|||||||
// 获取微信访问令牌并发送消息
|
// 获取微信访问令牌并发送消息
|
||||||
return wechatRequestService.getAccessToken("client_credential", DailyLoveConfigure.App_ID, DailyLoveConfigure.App_Secret)
|
return wechatRequestService.getAccessToken("client_credential", DailyLoveConfigure.App_ID, DailyLoveConfigure.App_Secret)
|
||||||
.onErrorMap(throwable -> new PushException("获取微信访问令牌失败: " + throwable.getMessage(), throwable))
|
.onErrorMap(throwable -> new PushException("获取微信访问令牌失败: " + throwable.getMessage(), throwable))
|
||||||
.map(tokenResp -> {
|
.map(tokenResp -> mapper.readTree(tokenResp).get("access_token").asString())
|
||||||
return mapper.readTree(tokenResp).get("access_token").asString();
|
|
||||||
})
|
|
||||||
.flatMap(accessToken -> wechatRequestService.sendMsg(accessToken, resultVo)
|
.flatMap(accessToken -> wechatRequestService.sendMsg(accessToken, resultVo)
|
||||||
.doOnNext(this::printPushLog)
|
.doOnNext(this::printPushLog)
|
||||||
.onErrorMap(throwable -> new PushException("发送微信消息失败: " + throwable.getMessage(), throwable)));
|
.onErrorMap(throwable -> new PushException("发送微信消息失败: " + throwable.getMessage(), throwable)));
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.bamanker.dailylove.domain;
|
package com.bamanker.dailylove.domain;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @descriptions 错误响应类
|
* @descriptions 错误响应类
|
||||||
|
|||||||
Reference in New Issue
Block a user