Ver código fonte

fix:api推送百度

master
燕鹏 3 anos atrás
pai
commit
e9d5072d47
  1. 7
      controllers/BlogController.go
  2. 30
      utils/data_zz.go

7
controllers/BlogController.go

@ -86,6 +86,7 @@ func (this *BlogController) Save() {
}
this.ServeJSON()
userService.CountBlog(uid.(int64))
utils.PostDataZZ(blog.Id)
return
}
@ -129,6 +130,7 @@ func (this *BlogController) Edit() {
}
this.ServeJSON()
userService.CountBlog(uid.(int64))
utils.PostDataZZ(id)
return
}
@ -138,12 +140,12 @@ func (this *BlogController) Get() {
idStr := this.Ctx.Input.Param(":id")
id, _ := strconv.ParseInt(idStr, 10, 64)
blog, err := blogService.GetBlog(id)
blog.User.Salt = ""
blog.User.UserPwd = ""
if err != nil {
this.Redirect("/404", 302)
return
}
blog.User.Salt = ""
blog.User.UserPwd = ""
if uid := this.GetSession("userid"); uid != nil {
if blog.UserId == uid.(int64) {
this.Data["IsAuthor"] = true
@ -161,6 +163,7 @@ func (this *BlogController) Get() {
userService.CountBrows(blog.UserId)
blogService.EditBlogBrows(id)
}
//utils.PostDataZZ(id)
return
}

30
utils/data_zz.go

@ -0,0 +1,30 @@
package utils
import (
"io/ioutil"
"net/http"
"strconv"
"strings"
)
//const baseUrl = "http://localhost/blog/"
const baseUrl = "https://www.aiprose.com/blog/"
func PostDataZZ(id int64) {
//if len(ids) < 1 {
// return
//}
//dataStr := ""
//for id := range ids{
// dataStr = dataStr + baseUrl + string(id) + "\n"
//}
dataStr := baseUrl + strconv.FormatInt(id, 10)
url := "http://data.zz.baidu.com/urls?site=www.aiprose.com&token=lO2wHMVqVq8SC9Ag"
res, err := http.Post(url, "text/plain", strings.NewReader(dataStr))
if err != nil {
println(err)
}
defer res.Body.Close()
content, err := ioutil.ReadAll(res.Body)
println(string(content))
}
Carregando…
Cancelar
Salvar