You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

102 lines
2.5 KiB

package captchasolver
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/url"
"strings"
"time"
)
func ProviderDeathByCaptchaCreateCaptchaRequestV2(deathByCaptchaUsername string, deathByCaptchaPassword string, captchaUrl string, googleKey string) string {
httpClient := http.Client{}
formValues := url.Values{
"username": {deathByCaptchaUsername},
"password": {deathByCaptchaPassword},
"type": {"4"},
"token_params": {fmt.Sprintf(`{"proxy": "", "proxytype": "", "googlekey": "%s","pageurl": "%s"}`, googleKey, captchaUrl)},
}
req, err := http.NewRequest("POST", "http://api.dbcapi.me/api/captcha", strings.NewReader(formValues.Encode()))
if err != nil {
log.Print(err)
return ""
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Accept", "application/json")
req.Header.Add("Expect", "")
resp, err := httpClient.Do(req)
if err != nil {
log.Print(err)
return ""
}
respBody, err := io.ReadAll(resp.Body)
if err != nil {
log.Print(err)
return ""
}
var resBodyJson map[string]any
err = json.Unmarshal(respBody, &resBodyJson)
if err != nil {
log.Print(err)
return ""
}
if _, exists := resBodyJson["captcha"]; !exists {
return ""
}
captchaIDFloat := resBodyJson["captcha"].(float64)
captchaID := int(captchaIDFloat)
captchaIDStr := fmt.Sprintf("%d", captchaID)
return captchaIDStr
}
func ProviderDeathByCaptchaGetCaptchaResult(captchaID string) string {
client := &http.Client{}
req, err := http.NewRequest("GET", fmt.Sprintf("http://api.dbcapi.me/api/captcha/%s", captchaID), nil)
if err != nil {
log.Print(err)
return ""
}
req.Header.Add("Accept", "application/json")
res, err := client.Do(req)
if err != nil {
log.Print(err)
return ""
}
respBody, _ := io.ReadAll(res.Body)
var resBodyJson map[string]any
err = json.Unmarshal(respBody, &resBodyJson)
if err != nil {
log.Print(err)
return ""
}
if _, exists := resBodyJson["text"]; !exists {
return ""
}
return resBodyJson["text"].(string)
}
func ProviderDeathByCaptchaV2E2E(deathByCaptchaUsername string, deathByCaptchaPassword string, url string, dataSiteKey string) string {
captchaReqID := ProviderDeathByCaptchaCreateCaptchaRequestV2(deathByCaptchaUsername, deathByCaptchaPassword, url, dataSiteKey)
log.Println(captchaReqID)
captchaAnswer := ""
for captchaAnswer == "" {
time.Sleep(500 * time.Millisecond)
captchaAnswer = ProviderDeathByCaptchaGetCaptchaResult(captchaReqID)
}
log.Printf("Captcha ID: %s; Captcha Answer: %s\n", captchaReqID, captchaAnswer)
return captchaAnswer
}