Skip to content
This repository has been archived by the owner on Oct 15, 2023. It is now read-only.

Commit

Permalink
update bx
Browse files Browse the repository at this point in the history
  • Loading branch information
linweiyuan committed Jul 2, 2023
1 parent a944a6d commit 7c71ca0
Showing 1 changed file with 66 additions and 64 deletions.
130 changes: 66 additions & 64 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,71 +61,8 @@ var (
{"H": 16},
{"SWF": false},
}
)

//goland:noinspection GoUnhandledErrorResult
func init() {
cli, _ := tls_client.NewHttpClient(tls_client.NewNoopLogger(), options...)
client = &cli
proxy := os.Getenv("http_proxy")
if proxy != "" {
(*client).SetProxy(proxy)
}
}

//goland:noinspection GoUnusedExportedFunction
func SetTLSClient(cli *tls_client.HttpClient) {
client = cli
}

//goland:noinspection SpellCheckingInspection,GoUnhandledErrorResult
func GetOpenAIToken() (string, error) {
bda := getBDA()
bda = base64.StdEncoding.EncodeToString([]byte(bda))
form := url.Values{
"bda": {bda},
"public_key": {"35536E1E-65B4-4D96-9D97-6ADB7EFF8147"},
"site": {"https://chat.openai.com"},
"userbrowser": {bv},
"capi_version": {"1.5.2"},
"capi_mode": {"lightbox"},
"style_theme": {"default"},
"rnd": {strconv.FormatFloat(rand.Float64(), 'f', -1, 64)},
}
req, _ := http.NewRequest(http.MethodPost, "https://tcr9i.chat.openai.com/fc/gt2/public_key/35536E1E-65B4-4D96-9D97-6ADB7EFF8147", strings.NewReader(form.Encode()))
req.Header.Set("Accept", "*/*")
req.Header.Set("Accept-Encoding", "gzip, deflate, br")
req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
req.Header.Set("DNT", "1")
req.Header.Set("Origin", "https://tcr9i.chat.openai.com")
req.Header.Set("Referer", "https://tcr9i.chat.openai.com/v2/1.5.2/enforcement.64b3a4e29686f93d52816249ecbf9857.html")
req.Header.Set("User-Agent", bv)
resp, err := (*client).Do(req)
if err != nil {
return "", err
}

defer resp.Body.Close()
if resp.StatusCode != 200 {
return "", errors.New("status code " + resp.Status)
}

type arkoseResponse struct {
Token string `json:"token"`
}
var arkose arkoseResponse
err = json.NewDecoder(resp.Body).Decode(&arkose)
if err != nil {
return "", err
}

return arkose.Token, nil
}

//goland:noinspection SpellCheckingInspection
func getBDA() string {
bx := fmt.Sprintf(`
bx = fmt.Sprintf(`
[{
"key": "api_type",
"value": "js"
Expand Down Expand Up @@ -338,7 +275,72 @@ func getBDA() string {
getFe(),
getIfeHash(),
)
bx20230702 = fmt.Sprintf(`[{"key":"fe","value":%s}]`, getFe())
)

//goland:noinspection GoUnhandledErrorResult
func init() {
cli, _ := tls_client.NewHttpClient(tls_client.NewNoopLogger(), options...)
client = &cli
proxy := os.Getenv("http_proxy")
if proxy != "" {
(*client).SetProxy(proxy)
}
}

//goland:noinspection GoUnusedExportedFunction
func SetTLSClient(cli *tls_client.HttpClient) {
client = cli
}

//goland:noinspection SpellCheckingInspection,GoUnhandledErrorResult
func GetOpenAIToken() (string, error) {
bda := getBDA()
bda = base64.StdEncoding.EncodeToString([]byte(bda))
form := url.Values{
"bda": {bda},
"public_key": {"35536E1E-65B4-4D96-9D97-6ADB7EFF8147"},
"site": {"https://chat.openai.com"},
"userbrowser": {bv},
"capi_version": {"1.5.2"},
"capi_mode": {"lightbox"},
"style_theme": {"default"},
"rnd": {strconv.FormatFloat(rand.Float64(), 'f', -1, 64)},
}
req, _ := http.NewRequest(http.MethodPost, "https://tcr9i.chat.openai.com/fc/gt2/public_key/35536E1E-65B4-4D96-9D97-6ADB7EFF8147", strings.NewReader(form.Encode()))
req.Header.Set("Accept", "*/*")
req.Header.Set("Accept-Encoding", "gzip, deflate, br")
req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
req.Header.Set("DNT", "1")
req.Header.Set("Origin", "https://tcr9i.chat.openai.com")
req.Header.Set("Referer", "https://tcr9i.chat.openai.com/v2/1.5.2/enforcement.64b3a4e29686f93d52816249ecbf9857.html")
req.Header.Set("User-Agent", bv)
resp, err := (*client).Do(req)
if err != nil {
return "", err
}

defer resp.Body.Close()
if resp.StatusCode != 200 {
return "", errors.New("status code " + resp.Status)
}

type arkoseResponse struct {
Token string `json:"token"`
}
var arkose arkoseResponse
err = json.NewDecoder(resp.Body).Decode(&arkose)
if err != nil {
return "", err
}

return arkose.Token, nil
}

//goland:noinspection SpellCheckingInspection
func getBDA() string {
bx = bx20230702
bt := time.Now().UnixMicro() / 1000000
bw := strconv.FormatInt(bt-(bt%21600), 10)
return encrypt(bx, bv+bw)
Expand Down

0 comments on commit 7c71ca0

Please sign in to comment.