2024-05-15 11:15:15 +08:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-resty/resty/v2"
|
2024-07-04 14:10:46 +08:00
|
|
|
"go-wechat/model/model"
|
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) {
|
|
|
|
var newsResp model.MorningPost
|
|
|
|
|
|
|
|
res := resty.New()
|
|
|
|
resp, err := res.R().
|
|
|
|
SetHeader("Content-Type", "application/json;chartset=utf-8").
|
|
|
|
SetQueryParam("token", "cFoMZNNBxT4jQovS").
|
|
|
|
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
|
|
|
|
}
|