|
@@ -0,0 +1,211 @@
|
|
|
+package third
|
|
|
+
|
|
|
+import (
|
|
|
+ "bytes"
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "io"
|
|
|
+ "net/http"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+var (
|
|
|
+ card = "tzlbndf9pi7ebzky" //当前有效的卡密
|
|
|
+ baseUrl = "https://unlockdoc.smain.cn/api/api" //服务器的基础url
|
|
|
+ VipStatusUrl = "/user/getUserInfoPlus" //接口是否正常
|
|
|
+ VipRecordsUrl = "/user/getRecords" //获取当前用户的解析记录
|
|
|
+ VipProxyStatusUrl = "/user/getCountProxy" //获取当前解析客户端的信息
|
|
|
+ VipTaskPriceUrl = "/user/getTaskPrice" //查看文章是否可以解析
|
|
|
+ VipParseUrl = "/user/purchasePaperPlusProxy" //解析对应的文章
|
|
|
+)
|
|
|
+
|
|
|
+func getUserKey(card string) string {
|
|
|
+ return strings.TrimPrefix(card, "tzlbn")
|
|
|
+}
|
|
|
+
|
|
|
+func post(url string, body []byte) (result []byte, err error) {
|
|
|
+ client := &http.Client{Timeout: 30 * time.Second}
|
|
|
+
|
|
|
+ param, _ := encrypt(body)
|
|
|
+
|
|
|
+ resp, err := client.Post(url, "application/json", bytes.NewBuffer([]byte(param)))
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+
|
|
|
+ result, _ = io.ReadAll(resp.Body)
|
|
|
+
|
|
|
+ res, _ := decrypt(result)
|
|
|
+ fmt.Println("result: ", string(result), "\r\nres: ", res, "\nparam:", param, "\nreq:", string(body))
|
|
|
+
|
|
|
+ return []byte(res), nil
|
|
|
+}
|
|
|
+
|
|
|
+func GetUserInfoPlus() (bool, error) {
|
|
|
+ url := baseUrl + VipStatusUrl
|
|
|
+ _, err := post(url, []byte("{}"))
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return true, nil
|
|
|
+}
|
|
|
+
|
|
|
+type GetRecordsRequestParam struct {
|
|
|
+ UserToken string `json:"userToken"`
|
|
|
+ Email string `json:"email"`
|
|
|
+}
|
|
|
+
|
|
|
+type GetRecordsRespondData struct {
|
|
|
+ Id string `json:"id"` //记录编号
|
|
|
+ Email string `json:"email"` //email 实际为卡密
|
|
|
+ Date string `json:"date"` //时间
|
|
|
+ MarkdownUrl string `json:"markdown_url"` //解析后的md 文件路径
|
|
|
+ HtmlUrl string `json:"html_url"` //解析后的 html 文件路径
|
|
|
+ OnlineHtmlUrl string `json:"online_html_url"` //解析口在线观看路径
|
|
|
+ PdfUrl interface{} `json:"pdf_url"` //pdf 路径, 暂不支持
|
|
|
+ Source string `json:"source"` //原始文章路径
|
|
|
+ Title string `json:"title"` //标题
|
|
|
+ IsFail interface{} `json:"isFail"` //是否失败
|
|
|
+}
|
|
|
+type GetRecordsRespondParam struct {
|
|
|
+ Code int `json:"code"`
|
|
|
+ Message string `json:"message"`
|
|
|
+ Data []GetRecordsRespondData `json:"data"`
|
|
|
+}
|
|
|
+
|
|
|
+func GetRecords(card string) (*GetRecordsRespondParam, error) {
|
|
|
+ url := baseUrl + VipRecordsUrl
|
|
|
+
|
|
|
+ key := getUserKey(card)
|
|
|
+ req := GetRecordsRequestParam{
|
|
|
+ UserToken: key,
|
|
|
+ Email: key,
|
|
|
+ }
|
|
|
+
|
|
|
+ t, _ := json.Marshal(req)
|
|
|
+ res, err := post(url, t)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ var result GetRecordsRespondParam
|
|
|
+ err = json.Unmarshal(res, &result)
|
|
|
+
|
|
|
+ return &result, err
|
|
|
+}
|
|
|
+
|
|
|
+type GetCountProxyRequestParam struct {
|
|
|
+ Key string `json:"key"`
|
|
|
+}
|
|
|
+
|
|
|
+type GetCountProxyRespondData struct {
|
|
|
+ Key string `json:"key"` //用户卡信息
|
|
|
+ WatchDate string `json:"watchDate"` //有效期
|
|
|
+ IsExpire int `json:"isExpire"` //是否过期
|
|
|
+ UpdateDate string `json:"updateDate"` //更新时间
|
|
|
+ CreateDate string `json:"createDate"` //创建时间
|
|
|
+ Ip string `json:"ip"` //客户端ip
|
|
|
+ IsProxy interface{} `json:"isProxy"` //是否为代理用户
|
|
|
+ Email interface{} `json:"email"` //email
|
|
|
+}
|
|
|
+type GetCountProxyRespondParam struct {
|
|
|
+ Code int `json:"code"`
|
|
|
+ Message string `json:"message"`
|
|
|
+ Data GetCountProxyRespondData `json:"data"`
|
|
|
+}
|
|
|
+
|
|
|
+func GetCountProxy(card string) (*GetCountProxyRespondParam, error) {
|
|
|
+ url := baseUrl + VipProxyStatusUrl
|
|
|
+
|
|
|
+ key := getUserKey(card)
|
|
|
+ req := GetCountProxyRequestParam{
|
|
|
+ Key: key,
|
|
|
+ }
|
|
|
+
|
|
|
+ t, _ := json.Marshal(req)
|
|
|
+ res, err := post(url, t)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ var result GetCountProxyRespondParam
|
|
|
+ err = json.Unmarshal(res, &result)
|
|
|
+
|
|
|
+ return &result, err
|
|
|
+}
|
|
|
+
|
|
|
+type GetTaskPriceRequestParam struct {
|
|
|
+ Url string `json:"url"`
|
|
|
+}
|
|
|
+type GeTaskPriceRespondParam struct {
|
|
|
+ Code int `json:"code"`
|
|
|
+ Message string `json:"message"`
|
|
|
+ Data int `json:"data"` //路径是否正确
|
|
|
+}
|
|
|
+
|
|
|
+func GetTaskPrice(source string) (*GeTaskPriceRespondParam, error) {
|
|
|
+ url := baseUrl + VipTaskPriceUrl
|
|
|
+
|
|
|
+ req := GetTaskPriceRequestParam{
|
|
|
+ Url: source,
|
|
|
+ }
|
|
|
+
|
|
|
+ t, _ := json.Marshal(req)
|
|
|
+ res, err := post(url, t)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ var result GeTaskPriceRespondParam
|
|
|
+ err = json.Unmarshal(res, &result)
|
|
|
+
|
|
|
+ return &result, err
|
|
|
+}
|
|
|
+
|
|
|
+type PurchasePaperPlusProxyRequestParam struct {
|
|
|
+ CssUrl string `json:"cssUrl"`
|
|
|
+ Other string `json:"other"`
|
|
|
+ Email interface{} `json:"email"`
|
|
|
+ Url string `json:"url"`
|
|
|
+ UseNum int `json:"useNum"`
|
|
|
+ Key string `json:"key"`
|
|
|
+}
|
|
|
+
|
|
|
+type PurchasePaperPlusProxyRespondParam struct {
|
|
|
+ Code int `json:"code"`
|
|
|
+ Message string `json:"message"`
|
|
|
+ ResUrl string `json:"data"` //解析后的 可直接下载观看的路径
|
|
|
+}
|
|
|
+
|
|
|
+func PurchasePaperPlusProxy(card string, source string) (*PurchasePaperPlusProxyRespondParam, error) {
|
|
|
+ url := baseUrl + VipParseUrl
|
|
|
+
|
|
|
+ key := getUserKey(card)
|
|
|
+ req := PurchasePaperPlusProxyRequestParam{
|
|
|
+ CssUrl: "https://unlockdoc.smain.cn/assets/13062df20.css",
|
|
|
+ Other: "1",
|
|
|
+ Email: nil,
|
|
|
+ Url: source,
|
|
|
+ UseNum: 1,
|
|
|
+ Key: key,
|
|
|
+ }
|
|
|
+
|
|
|
+ t, _ := json.Marshal(req)
|
|
|
+ res, err := post(url, t)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ var result PurchasePaperPlusProxyRespondParam
|
|
|
+ err = json.Unmarshal(res, &result)
|
|
|
+
|
|
|
+ return &result, err
|
|
|
+}
|