1
0
forked from lxh/go-wxhelper
go-wxhelper/utils/news.go

48 lines
935 B
Go
Raw Permalink Normal View History

2024-05-15 11:15:15 +08:00
package utils
import (
"github.com/go-resty/resty/v2"
"go-wechat/config"
2024-07-05 09:32:39 +08:00
"go-wechat/model/dto"
2024-05-15 11:15:15 +08:00
"log"
)
// News
// @description: 新闻
type News interface {
MorningPost() []string // 早报
}
type news struct{}
// NewsUtil
// @description: 新闻工具
// @param account
// @param password
// @return LeiGod
func NewsUtil() News {
return &news{}
}
// MorningPost
// @description: 早报
// @receiver news
// @return records
func (news) MorningPost() (records []string) {
2024-07-05 09:32:39 +08:00
var newsResp dto.MorningPost
2024-05-15 11:15:15 +08:00
res := resty.New()
resp, err := res.R().
SetHeader("Content-Type", "application/json;chartset=utf-8").
SetQueryParam("token", config.Conf.System.AlApiToken).
2024-05-15 11:15:15 +08:00
SetResult(&newsResp).
Post("https://v2.alapi.cn/api/zaobao")
if err != nil {
log.Panicf("每日早报获取失败: %s", err.Error())
}
log.Printf("每日早报获取结果: %s", unicodeToText(resp.String()))
records = newsResp.Data.News
return
}