Skip to content

Commit

Permalink
[Fix] 🐛 NewBing Proxy Error
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry-zklcdc committed Jul 27, 2023
1 parent fbe4d52 commit 568b99e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ Go_Proxy_BingAI_SOCKS_URL=192.168.0.88:1070
# Socks 账号、密码 可选
Go_Proxy_BingAI_SOCKS_USER=xxx
Go_Proxy_BingAI_SOCKS_PWD=xxx
# KievRPSSecAuth Cookie的值
USER_KievRPSSecAuth=xxx
# 默认用户 Cookie 设置,可选,不推荐使用,固定前缀 Go_Proxy_BingAI_USER_TOKEN 可设置多个,未登录用户将随机使用,多人共用将很快触发图形验证,并很快达到该账号的24小时限制
Go_Proxy_BingAI_USER_TOKEN_1=xxx
Go_Proxy_BingAI_USER_TOKEN_2=xxx
Expand Down
4 changes: 4 additions & 0 deletions common/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var (
// user token
USER_TOKEN_ENV_NAME_PREFIX = "Go_Proxy_BingAI_USER_TOKEN"
USER_TOKEN_LIST []string
// KievRPSSecAuth Cookie
USER_KievRPSSecAuth string
// 访问权限密钥,可选
AUTH_KEY string
AUTH_KEY_COOKIE_NAME = "BingAI_Auth_Key"
Expand All @@ -34,6 +36,8 @@ func initEnv() {
SOCKS_PWD = os.Getenv("Go_Proxy_BingAI_SOCKS_PWD")
// auth
AUTH_KEY = os.Getenv("Go_Proxy_BingAI_AUTH_KEY")
// KievRPSSecAuth Cookie
USER_KievRPSSecAuth = os.Getenv("USER_KievRPSSecAuth")
}

func initUserToken() {
Expand Down
8 changes: 8 additions & 0 deletions common/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ func NewSingleHostReverseProxy(target *url.URL) *httputil.ReverseProxy {
}
req.Header.Set("X-Forwarded-For", randIP)

if USER_KievRPSSecAuth != "" {
// 添加 KievRPSSecAuth Cookie
req.AddCookie(&http.Cookie{
Name: "KievRPSSecAuth",
Value: USER_KievRPSSecAuth,
})
}

// 未登录用户
ckUserToken, _ := req.Cookie(USER_TOKEN_COOKIE_NAME)
if ckUserToken == nil || ckUserToken.Value == "" {
Expand Down
3 changes: 2 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ services:
- $PWD/go-proxy-bingai:/app/go-proxy-bingai
ports:
- 8080:8080
# environment:
environment:
- USER_KievRPSSecAuth=xxx
# - Go_Proxy_BingAI_SOCKS_URL=192.168.0.88:1070
# - Go_Proxy_BingAI_SOCKS_USER=xxx
# - Go_Proxy_BingAI_SOCKS_PWD=xxx
Expand Down

0 comments on commit 568b99e

Please sign in to comment.