7 changed files with 96 additions and 132 deletions
@ -1,76 +0,0 @@ |
|||
package ym |
|||
|
|||
import ( |
|||
"encoding/json" |
|||
"errors" |
|||
"fmt" |
|||
"github.com/parnurzeal/gorequest" |
|||
"net/http" |
|||
"net/url" |
|||
) |
|||
|
|||
var ( |
|||
Token = `` |
|||
BaseURL = &url.URL{ |
|||
Host: `api.jfbym.com`, |
|||
Scheme: `http`, |
|||
Path: `/api/YmServer/customApi`, |
|||
} |
|||
Proxy = &url.URL{ |
|||
Host: `127.0.0.1:7890`, |
|||
Scheme: `http`, |
|||
} |
|||
) |
|||
|
|||
type RespCommonVerify struct { |
|||
Msg string `json:"msg"` |
|||
Code int `json:"code"` |
|||
Data struct { |
|||
Code int `json:"code"` |
|||
Data string `json:"data"` |
|||
Time float64 `json:"time"` |
|||
Externel int `json:"externel"` |
|||
UniqueCode string `json:"unique_code"` |
|||
FilePath string `json:"file_path"` |
|||
} `json:"data"` |
|||
} |
|||
|
|||
func CommonVerify(imgBase64 string, method int) (result string, errs []error) { |
|||
if Token == `` { |
|||
return ``, []error{errors.New(`token is empty`)} |
|||
} |
|||
content := fmt.Sprintf( |
|||
`image=%s&type=%d&token=%s`, imgBase64, |
|||
method, Token, |
|||
) |
|||
target := BaseURL.String() |
|||
req := gorequest.New().Post(target).Send(content).Set( |
|||
`Content-Type`, `application/x-www-form-urlencoded`, |
|||
) |
|||
if Proxy != nil { |
|||
req.Proxy(Proxy.String()) |
|||
} |
|||
var resp *http.Response |
|||
var body string |
|||
resp, body, errs = req.End() |
|||
if errs != nil { |
|||
return result, errs |
|||
} |
|||
if resp.StatusCode != 200 { |
|||
return result, []error{ |
|||
fmt.Errorf( |
|||
`server error: status code %d`, resp.StatusCode, |
|||
), |
|||
} |
|||
} |
|||
v := &RespCommonVerify{} |
|||
err := json.Unmarshal([]byte(body), v) |
|||
if err != nil { |
|||
return result, []error{fmt.Errorf(`can not parse data: %s`, body)} |
|||
} |
|||
if v.Code != 10000 { |
|||
return result, []error{fmt.Errorf(`server error: %s`, v.Msg)} |
|||
} |
|||
result = v.Data.Data |
|||
return result, nil |
|||
} |
@ -1,13 +0,0 @@ |
|||
package rproxy |
|||
|
|||
import ( |
|||
"git.realxlfd.cc/RealXLFD/golib/cli/logger" |
|||
) |
|||
|
|||
var ( |
|||
l = &logger.Logger{} |
|||
) |
|||
|
|||
func SetLogLevel(level logger.Level) { |
|||
l.Level = level |
|||
} |
@ -0,0 +1,20 @@ |
|||
package rproxy |
|||
|
|||
import ( |
|||
"log" |
|||
|
|||
"git.realxlfd.cc/RealXLFD/golib/cli/logger" |
|||
) |
|||
|
|||
var ( |
|||
Logger = &logger.Logger{} |
|||
) |
|||
|
|||
func SetLogLevel(level logger.Level) { |
|||
Logger.Level = level |
|||
} |
|||
|
|||
func init() { |
|||
log.SetFlags(0) |
|||
log.SetOutput(Logger.ToErrorWriter()) |
|||
} |
Loading…
Reference in new issue