🎨 沙盒短网址

This commit is contained in:
Liang Ding 2019-05-17 13:14:46 +08:00
parent f32e0a21d3
commit f764d61323
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
1 changed files with 19 additions and 19 deletions

View File

@ -23,7 +23,6 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/b3log/wide/conf"
"github.com/b3log/wide/session"
@ -116,23 +115,24 @@ func ShortURLHandler(w http.ResponseWriter, r *http.Request) {
return
}
url := args["url"].(string)
result.Data = args["url"].(string)
resp, _ := http.Post("http://dwz.cn/create.php", "application/x-www-form-urlencoded",
strings.NewReader("url="+url))
var response map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
logger.Error(err)
result.Succ = false
return
}
shortURL := url
if 0 == response["status"].(float64) {
shortURL = response["tinyurl"].(string)
}
result.Data = shortURL
// 百度短网址服务需要认证才可以使用
//resp, _ := http.Post("http://dwz.cn/create.php", "application/x-www-form-urlencoded",
// strings.NewReader("url="+url))
//
//var response map[string]interface{}
//if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
// logger.Error(err)
// result.Succ = false
//
// return
//}
//
//shortURL := url
//if 0 == response["status"].(float64) {
// shortURL = response["tinyurl"].(string)
//}
//
//result.Data = shortURL
}