v5_priapi.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package yu_okx
  2. import (
  3. "encoding/json"
  4. yu_const "gogs.qqck.cn/s/tools/const"
  5. yu_curl "gogs.qqck.cn/s/tools/curl"
  6. yu_fast "gogs.qqck.cn/s/tools/fast"
  7. yu_hex "gogs.qqck.cn/s/tools/hex"
  8. yu_json "gogs.qqck.cn/s/tools/json"
  9. yu_rand "gogs.qqck.cn/s/tools/rand"
  10. yu_strconv "gogs.qqck.cn/s/tools/strconv"
  11. "time"
  12. )
  13. type V5Priapi struct {
  14. host string
  15. curl *yu_curl.Request
  16. }
  17. func NewV5Priapi() (t *V5Priapi) {
  18. t = &V5Priapi{}
  19. j_bootid := make([]byte, 36)
  20. yu_rand.Rand.ReadEx(j_bootid, yu_const.HexLowerBytes)
  21. j_bootid[8], j_bootid[13], j_bootid[18], j_bootid[23] = '-', '-', '-', '-'
  22. j_bootid_s := yu_fast.B2S(j_bootid)
  23. t.host = "https://www.okx.ac"
  24. t.curl = yu_curl.NewRequest()
  25. t.curl.SetHeader("change", "1")
  26. t.curl.SetUserAgent("OKEx-guanwang/6.72.1 (V1916A; U; Android 9; zh-CN;) locale=zh-CN")
  27. t.curl.SetHeader("devid", j_bootid_s)
  28. t.curl.SetHeader("platform", "android")
  29. t.curl.SetHeader("real-app-version", "6.72.1")
  30. t.curl.SetHeader("x-utc", "+08:00")
  31. t.curl.SetHeader("fingerprint-id", j_bootid_s)
  32. t.curl.SetHeader("risk-params", "fingerprint-id="+j_bootid_s+"&session-id="+j_bootid_s+"_app_start_"+yu_strconv.FormatInt64(time.Now().UnixMilli()))
  33. t.curl.SetHeader("lua-version", "6.73.2")
  34. t.curl.SetHeader("app_web_mode", "pro")
  35. t.curl.SetHeader("x-id", yu_hex.Lower(yu_rand.Bytes(16))) // 3457f9e63a8ecee647b3b3a61fdddc1d
  36. return
  37. }
  38. func (t *V5Priapi) Close() {
  39. t.curl.Close()
  40. }
  41. // SetProxy 设置代理
  42. //
  43. // @Description:
  44. // @param proxy 格式 ProxyType://user:pass@host:port,ProxyType: http, socks4, socks4a, socks5, socks5h,设置为""以取消代理
  45. func (t *V5Priapi) SetProxy(proxy string) *V5Priapi {
  46. t.curl.SetProxy(proxy)
  47. return t
  48. }
  49. func (t *V5Priapi) request(method string, path string, post any, resp any) bool {
  50. switch method {
  51. case "GET":
  52. t.curl.Get(t.host + path)
  53. case "POST":
  54. j_json, j_err := json.Marshal(post)
  55. if j_err != nil {
  56. return false
  57. }
  58. t.curl.Post(t.host+path, j_json)
  59. }
  60. if t.curl.RespStatusCode() != 200 {
  61. return false
  62. }
  63. if resp == nil {
  64. return true
  65. }
  66. // Code string `json:"code"`
  67. // Msg string `json:"msg"`
  68. // Data any `json:"data"`
  69. // println(t.curl.RespBodyS())
  70. j_data := yu_json.GetBytes(t.curl.RespBody(), "data").String()
  71. if j_data == "" {
  72. return false
  73. }
  74. return json.Unmarshal(yu_fast.S2B(j_data), resp) == nil
  75. }