zvv

Go版本图床-Baidu+Qihoo+NetEasy+Jd+JueJin+Ali图床API

一个一个整理,纯属技术学习与爱好,再次感谢大神:https://github.com/aimerforreimu/auxpi

注意:请善待!!!

5,Baidu
github上的那个接口已经废掉了,所以自己分析了半天百度识图,又在网上找了半天,找到了一个还不错的:https://api.uomg.com/doc-image.baidu.html
这个是他封装好的,可能哪一天就不能用了,免费的东西就是不会稳的。

//百度识图的接口
func UploadToBaidu(img []byte, imgInfo string) string {
    body := new(bytes.Buffer)
    w := multipart.NewWriter(body)
    contentType := w.FormDataContentType()
    name := utils.GetFileNameByMimeType(imgInfo)
    file, _ := w.CreateFormFile("Filedata", name)
    _, _ = file.Write(img)
    _ = w.WriteField("file", "multipart")
    _ = w.Close()
    req, _ := http.NewRequest("POST", "https://api.uomg.com/api/image.baidu", body)
    req.Header.Set("Content-Type", contentType)
    resp, _ := http.DefaultClient.Do(req)
    defer resp.Body.Close()
    data, _ := ioutil.ReadAll(resp.Body)
    baidu := bed.BaiduResp{}
    err := json.Unmarshal([]byte(string(data)), &baidu)
    if err != nil {
        logging.AppLogger.Error("Upload To Baidu fail", zap.Error(err))
        return ""
    }
    return string(baidu.ImgUrl)
}


6,Qihoo
这个是360识图的口子,http://st.so.com/stu

func UploadToQihoo(img []byte, imgInfo string, imgType string) string {
    url := "http://st.so.com/stu"
    name := utils.GetFileNameByMimeType(imgInfo)

    file := &utils.FormFile{
        Name:  name,
        Key:   "upload",
        Value: img,
        Type:  imgType,
    }
    var header map[string]string
    data := utils.FormPost(file, url, header)
    var re = regexp.MustCompile(`(?m)data-imgkey="(.*)"`)
    imgKey := re.FindAllStringSubmatch(data, -1)[0][1]
    url = "https://ps.ssl.qhmsg.com/" + imgKey
    return url
}


7,NetEasy
网易的口子

func UploadToNetEasy(img []byte, imgInfo string, imgType string) string {
    url := "http://you.163.com/xhr/file/upload.json"
    name := utils.GetFileNameByMimeType(imgInfo)

    file := &utils.FormFile{
        Name:  name,
        Key:   "file",
        Value: img,
        Type:  imgType,
    }
    var header map[string]string
    data := utils.FormPost(file, url, header)
    netEasy := bed.NetEasyResp{}

    _ = json.Unmarshal([]byte(data), &netEasy)
    return netEasy.Data[0]
}


8,Jd
京东的口子

func UploadToJd(img []byte, imgInfo string, imgType string) string {
    url := "https://search.jd.com/image?op=upload"
    name := utils.GetFileNameByMimeType(imgInfo)

    file := &utils.FormFile{
        Name:  name,
        Key:   "file",
        Value: img,
        Type:  imgType,
    }
    var header map[string]string
    data := utils.FormPost(file, url, header)
    var pre = regexp.MustCompile(`(?m)ERROR`)

    if !pre.MatchString(data) {
        var re = regexp.MustCompile(`(?m)\("(.*)"\)`)
        imgFix := re.FindAllStringSubmatch(data, -1)[0][1]
        url = "https://img" + strconv.Itoa(rand.Intn(3)+11) + ".360buyimg.com/img/" + imgFix
        return url
    } else {
        return ""
    }

}


9,JueJin
掘金的。

func UploadToJueJin(img []byte, imgInfo string, imgType string) string {
    url := "https://cdn-ms.juejin.im/v1/upload?bucket=gold-user-assets"
    name := utils.GetFileNameByMimeType(imgInfo)

    file := &utils.FormFile{
        Name:  name,
        Key:   "file",
        Value: img,
        Type:  imgType,
    }
    var header map[string]string
    data := utils.FormPost(file, url, header)
    juejin := bed.JueJinResp{}
    _ = json.Unmarshal([]byte(data), &juejin)

    //神奇三断言 : )
    reJ, _ := juejin.D.(map[string]interface{})
    urls, _ := reJ["url"].(map[string]interface{})
    httpUrl, _ := urls["https"].(string)
    return httpUrl
}


10,Ali
阿里的

func UploadToAli(img []byte, imgInfo string, imgType string) string {
    url := "https://kfupload.alibaba.com/mupload"
    name := utils.GetFileNameByMimeType(imgInfo)

    file := &utils.FormFile{
        Name:  name,
        Key:   "file",
        Value: img,
        Type:  imgType,
    }
    //var header map[string]string
    data := utils.AliFormPost(file, url)
    ali := bed.AliResp{}
    _ = json.Unmarshal([]byte(data), &ali)
    return ali.Url
}

via。https://clawhub.club/posts/2019/08/11/Golang/Go%E7%89%88%E6%9C%AC%E5%9B%BE%E5%BA%8A-Baidu-Qihoo-NetEasy-Jd-JueJin-Ali%E5%9B%BE%E5%BA%8AAPI/

 

 

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »