Compare commits
1 Commits
main
...
feat-cjy-c
| Author | SHA1 | Date | |
|---|---|---|---|
| 18d829acd3 |
@ -65,21 +65,15 @@ func QuestionnaireSurveyCreate(c *gin.Context) {
|
||||
service.Error(c, err)
|
||||
return
|
||||
}
|
||||
ip := c.ClientIP()
|
||||
address, err := utils.GetAddressByIP(ip)
|
||||
if req.Longitude == "" || req.Latitude == "" {
|
||||
service.Error(c, errors.New("获取定位失败"))
|
||||
return
|
||||
}
|
||||
address, err := utils.ReverseGeo(req.Longitude, req.Latitude, "ZhCN")
|
||||
if err != nil {
|
||||
service.Error(c, errors.New("获取地址失败"))
|
||||
return
|
||||
}
|
||||
//if req.Longitude == "" || req.Latitude == "" {
|
||||
// service.Error(c, errors.New("获取定位失败"))
|
||||
// return
|
||||
//}
|
||||
//address, err := utils.ReverseGeo(req.Longitude, req.Latitude, "ZhCN")
|
||||
//if err != nil {
|
||||
// service.Error(c, errors.New("获取地址失败"))
|
||||
// return
|
||||
//}
|
||||
surveyInfo, err := service.BundleProvider.GetQuestionnaireSurveyInfo(c, &bundle.GetQuestionnaireSurveyInfoRequest{UserTel: req.UserTel})
|
||||
if err != nil {
|
||||
service.Error(c, err)
|
||||
|
||||
@ -1006,7 +1006,9 @@ func generateArtistMetricsAnalysis(resp *cast.ArtistMetricsSeriesResp) (string,
|
||||
}
|
||||
|
||||
// 构建 prompt
|
||||
prompt := fmt.Sprintf(`根据以下艺人各平台运营数据分析各平台数据表现,结合相关数据简要表述优点,文字内容在150-200字之间(标点符号不计入字数,回复时不需要返回具体字数)。注意:回复时请使用平台名称,如TIKTOK、INS等而非数字。重要:不要逐一列举所有平台名称,只需提及有亮点的平台即可:\n%s`, dataSummary.String())
|
||||
prompt := fmt.Sprintf(`根据以下艺人各平台运营数据分析各平台数据表现,结合相关数据简要表述优点,文字内容在150-200字之间(标点符号不计入字数,回复时不需要返回具体字数)。
|
||||
系统支持的平台枚举如下(数字对应平台名称):1=TIKTOK, 2=YouTube, 3=Instagram, 4=Dailymotion, 5=Bluesky。
|
||||
注意:回复时只能使用以上列出的平台名称,不得提及任何其他平台。重要:不要逐一列举所有平台名称,只需提及有亮点的平台即可:\n%s`, dataSummary.String())
|
||||
|
||||
// 调用 AI
|
||||
req := modelQwen.ChatRequest{
|
||||
|
||||
@ -2,28 +2,11 @@ package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const baiduIPLocationAPI = "https://api.map.baidu.com/location/ip"
|
||||
|
||||
// 建议把 ak 放配置;这里先保留你给的 key,后续可改为从配置读取。
|
||||
const baiduMapAK = "T8DGBYxbZ1iAeXx1J57McKigyHJHulPQ"
|
||||
|
||||
type baiduIPResp struct {
|
||||
Status int `json:"status"`
|
||||
Address string `json:"address"`
|
||||
Content struct {
|
||||
Address string `json:"address"`
|
||||
} `json:"content"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
type ReverseGeocodingReq struct {
|
||||
Ak string `json:"ak"`
|
||||
Coordtype string `json:"coordtype"`
|
||||
@ -103,50 +86,3 @@ func ReverseGeo(longitude, latitude string, language string) (address string, er
|
||||
|
||||
return address, nil
|
||||
}
|
||||
func GetAddressByIP(ip string) (string, error) {
|
||||
ip = strings.TrimSpace(ip)
|
||||
if ip == "" {
|
||||
return "", fmt.Errorf("ip is empty")
|
||||
}
|
||||
|
||||
q := url.Values{}
|
||||
q.Set("ip", ip)
|
||||
q.Set("coor", "bd09ll")
|
||||
q.Set("ak", baiduMapAK)
|
||||
|
||||
reqURL := baiduIPLocationAPI + "?" + q.Encode()
|
||||
client := &http.Client{Timeout: 5 * time.Second}
|
||||
resp, err := client.Get(reqURL)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return "", fmt.Errorf("baidu api status: %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r baiduIPResp
|
||||
if err := json.Unmarshal(body, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if r.Status != 0 {
|
||||
if r.Message == "" {
|
||||
r.Message = "baidu api error"
|
||||
}
|
||||
return "", fmt.Errorf("%s", r.Message)
|
||||
}
|
||||
|
||||
if strings.TrimSpace(r.Content.Address) != "" {
|
||||
return r.Content.Address, nil
|
||||
}
|
||||
if strings.TrimSpace(r.Address) != "" {
|
||||
return r.Address, nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user