Commit 23e0bb79 authored by shajiaiming's avatar shajiaiming

优化

parent 0c74287d
......@@ -6,7 +6,6 @@ import (
"bwallet/pkg/util"
"bwallet/service/article_service"
"bwallet/validate_service"
"fmt"
"github.com/Unknwon/com"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
......@@ -186,13 +185,11 @@ func DeleteArticle(c *gin.Context) {
articleService := article_service.Article{Id: id}
exists, err := articleService.ExistById()
if err != nil {
fmt.Println(err,1111)
handler.SendResponse(c, errno.ErrArticleNotFound, nil)
return
}
if !exists {
fmt.Println(err,2222)
handler.SendResponse(c, errno.ErrArticleNotFound, nil)
return
}
......
......@@ -2,6 +2,7 @@ package article_service
import (
"bwallet/models"
"bwallet/pkg/errno"
"bwallet/pkg/util"
"encoding/json"
"io/ioutil"
......@@ -44,7 +45,6 @@ func (a *Article) Get() (*models.Article, error) {
params["id"] = article.Content
params["language"] = "1"
params["timestamp"] = strconv.FormatInt(time.Now().UTC().Unix(), 10)
params["sign"] = util.StringToMd5("app_id=8415d8c1c4f762d8&id=" + params["id"] + "&language=1&timestamp=" + params["timestamp"] + "09395dc651588c375d066666e072a714")
req, err := http.NewRequest(http.MethodGet, "https://iapi.bishijie.com/article/detail", nil)
if err != nil {
......@@ -55,18 +55,26 @@ func (a *Article) Get() (*models.Article, error) {
condition.Add("id", article.Content)
condition.Add("language", params["language"])
condition.Add("timestamp", params["timestamp"])
condition.Add("sign", params["sign"])
sign := util.StringToMd5(condition.Encode() + "09395dc651588c375d066666e072a714")
condition.Add("sign",sign)
req.URL.RawQuery = condition.Encode()
//fmt.Println(req.URL.String())
r, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return nil, err
}
result := map[string]interface{}{}
json.Unmarshal(body, &result)
if _, ok := result["code"]; ok {
return nil, errno.InternalServerError
}
article.Content = result["content"].(string)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment