req.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. package third
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. "io"
  7. "net/http"
  8. "strings"
  9. "time"
  10. )
  11. var (
  12. card = "tzlbndf9pi7ebzky" //当前有效的卡密
  13. baseUrl = "https://unlockdoc.smain.cn/api/api" //服务器的基础url
  14. VipStatusUrl = "/user/getUserInfoPlus" //接口是否正常
  15. VipRecordsUrl = "/user/getRecords" //获取当前用户的解析记录
  16. VipProxyStatusUrl = "/user/getCountProxy" //获取当前解析客户端的信息
  17. VipTaskPriceUrl = "/user/getTaskPrice" //查看文章是否可以解析
  18. VipParseUrl = "/user/purchasePaperPlusProxy" //解析对应的文章
  19. )
  20. func getUserKey(card string) string {
  21. return strings.TrimPrefix(card, "tzlbn")
  22. }
  23. func post(url string, body []byte) (result []byte, err error) {
  24. client := &http.Client{Timeout: 30 * time.Second}
  25. param, _ := encrypt(body)
  26. resp, err := client.Post(url, "application/json", bytes.NewBuffer([]byte(param)))
  27. if err != nil {
  28. return nil, err
  29. }
  30. defer resp.Body.Close()
  31. result, _ = io.ReadAll(resp.Body)
  32. res, _ := decrypt(result)
  33. fmt.Println("result: ", string(result), "\r\nres: ", res, "\nparam:", param, "\nreq:", string(body))
  34. return []byte(res), nil
  35. }
  36. func GetUserInfoPlus() (bool, error) {
  37. url := baseUrl + VipStatusUrl
  38. _, err := post(url, []byte("{}"))
  39. if err != nil {
  40. return false, err
  41. }
  42. return true, nil
  43. }
  44. type GetRecordsRequestParam struct {
  45. UserToken string `json:"userToken"`
  46. Email string `json:"email"`
  47. }
  48. type GetRecordsRespondData struct {
  49. Id string `json:"id"` //记录编号
  50. Email string `json:"email"` //email 实际为卡密
  51. Date string `json:"date"` //时间
  52. MarkdownUrl string `json:"markdown_url"` //解析后的md 文件路径
  53. HtmlUrl string `json:"html_url"` //解析后的 html 文件路径
  54. OnlineHtmlUrl string `json:"online_html_url"` //解析口在线观看路径
  55. PdfUrl interface{} `json:"pdf_url"` //pdf 路径, 暂不支持
  56. Source string `json:"source"` //原始文章路径
  57. Title string `json:"title"` //标题
  58. IsFail interface{} `json:"isFail"` //是否失败
  59. }
  60. type GetRecordsRespondParam struct {
  61. Code int `json:"code"`
  62. Message string `json:"message"`
  63. Data []GetRecordsRespondData `json:"data"`
  64. }
  65. func GetRecords(card string) (*GetRecordsRespondParam, error) {
  66. url := baseUrl + VipRecordsUrl
  67. key := getUserKey(card)
  68. req := GetRecordsRequestParam{
  69. UserToken: key,
  70. Email: key,
  71. }
  72. t, _ := json.Marshal(req)
  73. res, err := post(url, t)
  74. if err != nil {
  75. return nil, err
  76. }
  77. var result GetRecordsRespondParam
  78. err = json.Unmarshal(res, &result)
  79. return &result, err
  80. }
  81. type GetCountProxyRequestParam struct {
  82. Key string `json:"key"`
  83. }
  84. type GetCountProxyRespondData struct {
  85. Key string `json:"key"` //用户卡信息
  86. WatchDate string `json:"watchDate"` //有效期
  87. IsExpire int `json:"isExpire"` //是否过期
  88. UpdateDate string `json:"updateDate"` //更新时间
  89. CreateDate string `json:"createDate"` //创建时间
  90. Ip string `json:"ip"` //客户端ip
  91. IsProxy interface{} `json:"isProxy"` //是否为代理用户
  92. Email interface{} `json:"email"` //email
  93. }
  94. type GetCountProxyRespondParam struct {
  95. Code int `json:"code"`
  96. Message string `json:"message"`
  97. Data GetCountProxyRespondData `json:"data"`
  98. }
  99. func GetCountProxy(card string) (*GetCountProxyRespondParam, error) {
  100. url := baseUrl + VipProxyStatusUrl
  101. key := getUserKey(card)
  102. req := GetCountProxyRequestParam{
  103. Key: key,
  104. }
  105. t, _ := json.Marshal(req)
  106. res, err := post(url, t)
  107. if err != nil {
  108. return nil, err
  109. }
  110. var result GetCountProxyRespondParam
  111. err = json.Unmarshal(res, &result)
  112. return &result, err
  113. }
  114. type GetTaskPriceRequestParam struct {
  115. Url string `json:"url"`
  116. }
  117. type GeTaskPriceRespondParam struct {
  118. Code int `json:"code"`
  119. Message string `json:"message"`
  120. Data int `json:"data"` //路径是否正确
  121. }
  122. func GetTaskPrice(source string) (*GeTaskPriceRespondParam, error) {
  123. url := baseUrl + VipTaskPriceUrl
  124. req := GetTaskPriceRequestParam{
  125. Url: source,
  126. }
  127. t, _ := json.Marshal(req)
  128. res, err := post(url, t)
  129. if err != nil {
  130. return nil, err
  131. }
  132. var result GeTaskPriceRespondParam
  133. err = json.Unmarshal(res, &result)
  134. return &result, err
  135. }
  136. type PurchasePaperPlusProxyRequestParam struct {
  137. CssUrl string `json:"cssUrl"`
  138. Other string `json:"other"`
  139. Email interface{} `json:"email"`
  140. Url string `json:"url"`
  141. UseNum int `json:"useNum"`
  142. Key string `json:"key"`
  143. }
  144. type PurchasePaperPlusProxyRespondParam struct {
  145. Code int `json:"code"`
  146. Message string `json:"message"`
  147. ResUrl string `json:"data"` //解析后的 可直接下载观看的路径
  148. }
  149. func PurchasePaperPlusProxy(card string, source string) (*PurchasePaperPlusProxyRespondParam, error) {
  150. url := baseUrl + VipParseUrl
  151. key := getUserKey(card)
  152. req := PurchasePaperPlusProxyRequestParam{
  153. CssUrl: "https://unlockdoc.smain.cn/assets/13062df20.css",
  154. Other: "1",
  155. Email: nil,
  156. Url: source,
  157. UseNum: 1,
  158. Key: key,
  159. }
  160. t, _ := json.Marshal(req)
  161. res, err := post(url, t)
  162. if err != nil {
  163. return nil, err
  164. }
  165. var result PurchasePaperPlusProxyRespondParam
  166. err = json.Unmarshal(res, &result)
  167. return &result, err
  168. }