package llm import ( "encoding/json" "eta/eta_api/utils" "fmt" "io" "net/http" "strings" ) type BaseResp struct { Code int `json:"code"` Msg string `json:"msg"` } type WechatPlatformListResp struct { BaseResp Data []WechatPlatformResp `json:"data"` } type WechatPlatformResp struct { Fakeid string `json:"fakeid"` Nickname string `json:"nickname"` Alias string `json:"alias"` RoundHeadImg string `json:"round_head_img"` ServiceType int `json:"service_type"` Signature string `json:"signature"` Verified bool `json:"verified"` } // SearchByWechat // @Description: 公众号列表 // @author: Roc // @datetime 2025-03-04 18:09:01 // @param name string // @return resp WechatPlatformResp // @return err error func SearchByWechat(name string) (items []WechatPlatformResp, err error) { if utils.ETA_WX_CRAWLER_URL == "" { err = fmt.Errorf("ETA微信爬虫服务地址为空") return } getUrl := utils.ETA_WX_CRAWLER_URL + `/api/wechat_platform/search_by_wechat?name=` + name result, err := HttpGet(getUrl) if err != nil { err = fmt.Errorf("调用ETA微信爬虫服务接口失败 error:%s", err.Error()) return } var resp WechatPlatformListResp err = json.Unmarshal(result, &resp) if err != nil { return } items = resp.Data return } type WechatArticleResp struct { BaseResp Data WechatArticleDataResp `json:"data"` } type WechatArticleDataResp struct { HtmlContent string `json:"HtmlContent"` TextContent string `json:"TextContent"` RoundHeadImg string `json:"RoundHeadImg"` ProfileSignature string `json:"ProfileSignature"` Appuin string `json:"Appuin"` Nickname string `json:"Nickname"` UserName string `json:"UserName"` Title string `json:"Title"` Desc string `json:"Desc"` CoverUrl string `json:"CoverUrl"` CreateAt string `json:"CreateAt"` CountryName string `json:"CountryName"` ProvinceName string `json:"ProvinceName"` CityName string `json:"CityName"` } // SearchByWechatArticle // @Description: 获取报告详情 // @author: Roc // @datetime 2025-03-04 18:08:45 // @param link string // @return resp WechatArticleResp // @return err error func SearchByWechatArticle(link string) (wechatArticle WechatArticleDataResp, err error) { if utils.ETA_WX_CRAWLER_URL == "" { err = fmt.Errorf("ETA微信爬虫服务地址为空") return } getUrl := utils.ETA_WX_CRAWLER_URL + `/api/wechat_platform/article/info/search_by_wechat?link=` + link result, err := HttpGet(getUrl) if err != nil { err = fmt.Errorf("调用ETA微信爬虫服务接口失败 error:%s", err.Error()) return } var resp WechatArticleResp err = json.Unmarshal(result, &resp) if err != nil { return } wechatArticle = resp.Data return } type WechatArticleListResp struct { BaseResp Data WechatArticleMenuPage `json:"data"` } type WechatArticleMenuPage struct { List []ArticleMenu `json:"List"` Total int `json:"Total"` } type ArticleMenu struct { Aid string `json:"Aid"` Title string `json:"Title"` Link string `json:"Link"` Cover string `json:"Cover"` Digest string `json:"Digest"` UpdateTime int `json:"UpdateTime"` CreateTime int `json:"CreateTime"` AppMsgId int64 `json:"AppMsgId"` AuthorName string `json:"AuthorName"` Content string `json:"Content"` } func SearchByWechatArticleList(fakeId string, num int) (items WechatArticleMenuPage, err error) { if utils.ETA_WX_CRAWLER_URL == "" { err = fmt.Errorf("ETA微信爬虫服务地址为空") return } getUrl := fmt.Sprintf(`%s/api/wechat_platform/article/list/search_by_wechat?fakeid=%s&num=%d`, utils.ETA_WX_CRAWLER_URL, fakeId, num) result, err := HttpGet(getUrl) if err != nil { err = fmt.Errorf("调用ETA微信爬虫服务接口失败 error:%s", err.Error()) return } var resp WechatArticleListResp err = json.Unmarshal(result, &resp) if err != nil { return } items = resp.Data return } func HttpGet(url string) ([]byte, error) { client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err } req.Header.Set("authorization", utils.MD5(utils.ETA_FORUM_HUB_NAME_EN+utils.ETA_FORUM_HUB_MD5_KEY)) resp, err := client.Do(req) if err != nil { return nil, err } defer resp.Body.Close() result, err := io.ReadAll(resp.Body) if err != nil { return nil, err } utils.FileLog.Debug("HttpPost:" + string(result)) var baseResp BaseResp err = json.Unmarshal(result, &baseResp) if err != nil { return nil, err } if baseResp.Code != 200 { return nil, fmt.Errorf("code:%d,msg:%s", baseResp.Code, baseResp.Msg) } return result, err } func HttpPost(url, postData, lang string, params ...string) ([]byte, error) { body := io.NopCloser(strings.NewReader(postData)) client := &http.Client{} req, err := http.NewRequest("POST", url, body) if err != nil { return nil, err } contentType := "application/x-www-form-urlencoded;charset=utf-8" if len(params) > 0 && params[0] != "" { contentType = params[0] } req.Header.Set("Content-Type", contentType) req.Header.Set("Lang", lang) req.Header.Set("authorization", utils.MD5(utils.APP_EDB_LIB_NAME_EN+utils.EDB_LIB_Md5_KEY)) resp, err := client.Do(req) if err != nil { return nil, err } defer resp.Body.Close() b, err := io.ReadAll(resp.Body) utils.FileLog.Debug("HttpPost:" + string(b)) return b, err }