Browse Source

百度短链

master
huangjiajun 1 week ago
parent
commit
36bcf64041
1 changed files with 37 additions and 0 deletions
  1. +37
    -0
      baidu/api.go

+ 37
- 0
baidu/api.go View File

@@ -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
}

Loading…
Cancel
Save