Pārlūkot izejas kodu

百度短链

master
huangjiajun pirms 1 nedēļas
vecāks
revīzija
36bcf64041
1 mainītis faili ar 37 papildinājumiem un 0 dzēšanām
  1. +37
    -0
      baidu/api.go

+ 37
- 0
baidu/api.go Parādīt failu

@@ -0,0 +1,37 @@
package baidu

import (
utils "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils"
"encoding/json"
"fmt"
)

func BaiduShortenUrl(token, url string) (string, error) {
host := "https://dwz.cn/admin/v2/create"
args := map[string]string{
"Url": url,
"TermOfValidity": "1-year",
}

resp, err := utils.CurlPost(host, utils.Serialize(args), map[string]string{
"Content-Type": "application/json",
"Token": token,
})
// {"Code":0,"IsNew":true,"ShortUrl":"https://dwz.cn/4kSgiKVl","LongUrl":"https://open.taobao.com/search.htm?q=taobao.tbk.sc.material","ErrMsg":""}
if err != nil {
return "", err
}
var tmp struct {
Code int `json:"Code"`
IsNew bool `json:"IsNew"`
ShortURL string `json:"ShortUrl"`
LongURL string `json:"LongUrl"`
ErrMsg string `json:"ErrMsg"`
}
fmt.Println("======分享==========", string(resp))

if err = json.Unmarshal(resp, &tmp); err != nil {
return "", err
}
return tmp.ShortURL, nil
}

Notiek ielāde…
Atcelt
Saglabāt