From 36bcf64041857bb428878a25d92cab8225104c66 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Fri, 13 Dec 2024 18:34:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BE=E5=BA=A6=E7=9F=AD=E9=93=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- baidu/api.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 baidu/api.go diff --git a/baidu/api.go b/baidu/api.go new file mode 100644 index 0000000..24eb28d --- /dev/null +++ b/baidu/api.go @@ -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 +}