fix(proxy): 修复代理地址换行符问题并优化代理池初始化

- 将代理URL中的换行符由\r\n修改为\n,避免解析错误
- 代理相关配置文件及Dockerfile中统一调整换行符格式
- flyfishv2卡片发送模块设置正确的User-Agent头部
- 使用strutil.SplitAndTrim代替strings.Split优化代理IP列表处理
- 修正全局代理池单例初始化方式,确保线程安全
- 调整main.go中包引入顺序,提升代码规范性
This commit is contained in:
danial
2025-12-07 23:47:16 +08:00
parent 3014d1cddc
commit d5d681ea52
7 changed files with 11 additions and 10 deletions

View File

@@ -231,7 +231,7 @@ proxies = []
```go ```go
func GetProxyInfo() ProxyInfo { func GetProxyInfo() ProxyInfo {
return ProxyInfo{ return ProxyInfo{
Url: env.Get("proxyUrl", "https://share.proxy.qg.net/get?key=7ASQH2BI&num=2&area=&isp=0&format=txt&seq=\\r\\n&distinct=false"), Url: env.Get("proxyUrl", "https://share.proxy.qg.net/get?key=7ASQH2BI&num=2&area=&isp=0&format=txt&seq=\\n&distinct=false"),
AuthKey: env.Get("proxyAuthKey", "7ASQH2BI"), AuthKey: env.Get("proxyAuthKey", "7ASQH2BI"),
AuthPwd: env.Get("proxyAuthPwd", "34D6652FE7B6"), AuthPwd: env.Get("proxyAuthPwd", "34D6652FE7B6"),
} }

View File

@@ -22,7 +22,7 @@ ENV TZ=Asia/Shanghai \
shopAddr="" \ shopAddr="" \
proxy="" \ proxy="" \
proxyName="qkgo" \ proxyName="qkgo" \
proxyUrl="https://share.proxy.qg.net/get?key=7ASQH2BI&num=2&area=&isp=0&format=txt&seq=\r\n&distinct=false" \ proxyUrl="https://share.proxy.qg.net/get?key=7ASQH2BI&num=2&area=&isp=0&format=txt&seq=\n&distinct=false" \
proxyAuthKey="7ASQH2BI" \ proxyAuthKey="7ASQH2BI" \
proxyAuthPwd="34D6652FE7B6" proxyAuthPwd="34D6652FE7B6"

View File

@@ -10,7 +10,7 @@ type ProxyInfo struct {
func GetProxyInfo() ProxyInfo { func GetProxyInfo() ProxyInfo {
return ProxyInfo{ return ProxyInfo{
Url: env.Get("proxyUrl", "https://share.proxy.qg.net/get?key=7ASQH2BI&num=2&area=&isp=0&format=txt&seq=\\r\\n&distinct=false"), Url: env.Get("proxyUrl", "https://share.proxy.qg.net/get?key=7ASQH2BI&num=2&area=&isp=0&format=txt&seq=\\n&distinct=false"),
AuthKey: env.Get("proxyAuthKey", "7ASQH2BI"), AuthKey: env.Get("proxyAuthKey", "7ASQH2BI"),
AuthPwd: env.Get("proxyAuthPwd", "34D6652FE7B6"), AuthPwd: env.Get("proxyAuthPwd", "34D6652FE7B6"),
} }

View File

@@ -32,14 +32,13 @@ type Pool struct {
var ( var (
globalProxyPool *Pool globalProxyPool *Pool
once sync.Once
) )
// GetGlobalProxyPool 获取全局代理池实例 // GetGlobalProxyPool 获取全局代理池实例
func GetGlobalProxyPool() *Pool { func GetGlobalProxyPool() *Pool {
once.Do(func() { sync.OnceFunc(func() {
globalProxyPool = NewProxyPool() globalProxyPool = NewProxyPool()
}) })()
return globalProxyPool return globalProxyPool
} }

View File

@@ -8,6 +8,7 @@ import (
"gateway/internal/models/road" "gateway/internal/models/road"
"gateway/internal/otelTrace" "gateway/internal/otelTrace"
"gateway/internal/utils" "gateway/internal/utils"
"gateway/internal/utils/useragent"
"net/url" "net/url"
"regexp" "regexp"
"sort" "sort"
@@ -104,6 +105,7 @@ func (s *SendCardTaskTypeFlyFishV2) HandleSendCardTask(ctx context.Context, orde
SetHeader("accept", "application/json, text/javascript, */*; q=0.01"). SetHeader("accept", "application/json, text/javascript, */*; q=0.01").
SetHeader("content-type", "application/x-www-form-urlencoded; charset=UTF-8"). SetHeader("content-type", "application/x-www-form-urlencoded; charset=UTF-8").
SetHeader("origin", "https://apify.fkpay.online"). SetHeader("origin", "https://apify.fkpay.online").
SetHeader("user-agent", useragent.GetUserAgentByPlatform(useragent.PlatformPhone)).
SetHeader("referer", "https://apify.fkpay.online/show.html?orderId=FY17568845864231914279"). SetHeader("referer", "https://apify.fkpay.online/show.html?orderId=FY17568845864231914279").
SetTimeout(time.Second * 20).OnBeforeRequest(func(client *resty.Client, request *resty.Request) error { SetTimeout(time.Second * 20).OnBeforeRequest(func(client *resty.Client, request *resty.Request) error {
proxy, _ := utils.GetProxy(ctx, utils.GenerateId(), "SendCardTaskTypeFlyFishV2_cardTask") proxy, _ := utils.GetProxy(ctx, utils.GenerateId(), "SendCardTaskTypeFlyFishV2_cardTask")

View File

@@ -442,7 +442,8 @@ func (p *OrderBasedProxyStrategy) tryGetProxy(ctx context.Context) ([]string, er
return []string{}, fmt.Errorf("获取代理IP失败") return []string{}, fmt.Errorf("获取代理IP失败")
} }
proxyIPs := strings.Split(proxyIP, "\n") proxyIPs := strutil.SplitAndTrim(proxyIP, "\n")
slice.ForEach(proxyIPs, func(index int, item string) { slice.ForEach(proxyIPs, func(index int, item string) {
proxyIPs[index] = strutil.Trim(item) proxyIPs[index] = strutil.Trim(item)
}) })

View File

@@ -14,11 +14,10 @@ import (
"gateway/internal/service/supplier/third_party" "gateway/internal/service/supplier/third_party"
"gateway/internal/service/supplier/third_party/queue" "gateway/internal/service/supplier/third_party/queue"
"gateway/internal/utils" "gateway/internal/utils"
"log"
_ "net/http/pprof"
"github.com/beego/beego/v2/server/web" "github.com/beego/beego/v2/server/web"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"log"
_ "net/http/pprof"
) )
func main() { func main() {