diff --git a/utils/router.go b/utils/router.go index 65ce222..fc210ad 100644 --- a/utils/router.go +++ b/utils/router.go @@ -48,8 +48,8 @@ func Router(data map[string]interface{}) { if err != nil { return } - key := fmt.Sprintf("group_message:%f:%f", gid, uid) - exists, err := tools.CheckKeyExists(fmt.Sprintf("group_message:%d:%d", int64(gid), int64(uid))) + key := fmt.Sprintf("group_message:%d:%d", int64(gid), int64(uid)) + exists, err := tools.CheckKeyExists(key) if err != nil || !exists { redisClient.RPush(context.Background(), key, jsonString, 0) // tools.SetValue(key, string(jsonString), 10*time.Second) diff --git a/workers/ai.go b/workers/ai.go index 2cef2e8..490432d 100644 --- a/workers/ai.go +++ b/workers/ai.go @@ -6,15 +6,15 @@ import ( "encoding/json" "fmt" "go-bot/tools" + "os" "io" "log" - "net/http" - "os" "regexp" "strconv" "strings" + "github.com/imroc/req/v3" openai "github.com/sashabaranov/go-openai" ) @@ -159,7 +159,7 @@ func (a *AI) GetMsg() string { if len(matches) > 0 { msgId = matches[1] - println("msgId:", msgId) + // println("msgId:", msgId) } else { msgId = "" log.Println("未找到回复消息") @@ -185,7 +185,9 @@ func (a *AI) GetMsg() string { // println("filePath:", filePath) if filePath == "" { log.Println("获取图片失败") - return "获取图片失败" + // return "获取图片失败" + // 下载picUrl文件 + } base64Img := Image2Base64(filePath, picUrl) if base64Img == "" { @@ -223,7 +225,7 @@ func (a *AI) GetMsg() string { ) if err != nil { log.Println("ChatCompletion error: ", err) - return "请求失败" + return "请求失败,api可能不支持图片上传" } msg += resp.Choices[0].Message.Content @@ -315,10 +317,16 @@ func Image2Base64(path string, picUrl string) string { } // 如果文件路径不可用,则尝试从 URL 下载图片 - resp, err := http.Get(picUrl) + + client := req.C(). + SetUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"). + SetTLSFingerprintChrome() // 模拟 Chrome 浏览器的 TLS 握手指纹,让网站相信这是 Chrome 浏览器在访问,予以通行。 + + resp, err := client.R().Get(picUrl) if err != nil { return "" } + defer resp.Body.Close() if data, err := io.ReadAll(resp.Body); err == nil { diff --git a/workers/pkg.go b/workers/pkg.go index c2c4e8c..768f1a1 100644 --- a/workers/pkg.go +++ b/workers/pkg.go @@ -46,7 +46,7 @@ func (a *Pkg) GetMsg() string { SetSuccessResult(&pkg). Get(url) if err != nil { - return "服务器网络错误!" + return "网络错误!" } defer resp.Body.Close()