Commit 23e0bb79 authored by shajiaiming's avatar shajiaiming

优化

parent 0c74287d
...@@ -6,7 +6,6 @@ import ( ...@@ -6,7 +6,6 @@ import (
"bwallet/pkg/util" "bwallet/pkg/util"
"bwallet/service/article_service" "bwallet/service/article_service"
"bwallet/validate_service" "bwallet/validate_service"
"fmt"
"github.com/Unknwon/com" "github.com/Unknwon/com"
"github.com/astaxie/beego/validation" "github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
...@@ -186,13 +185,11 @@ func DeleteArticle(c *gin.Context) { ...@@ -186,13 +185,11 @@ func DeleteArticle(c *gin.Context) {
articleService := article_service.Article{Id: id} articleService := article_service.Article{Id: id}
exists, err := articleService.ExistById() exists, err := articleService.ExistById()
if err != nil { if err != nil {
fmt.Println(err,1111)
handler.SendResponse(c, errno.ErrArticleNotFound, nil) handler.SendResponse(c, errno.ErrArticleNotFound, nil)
return return
} }
if !exists { if !exists {
fmt.Println(err,2222)
handler.SendResponse(c, errno.ErrArticleNotFound, nil) handler.SendResponse(c, errno.ErrArticleNotFound, nil)
return return
} }
......
...@@ -2,6 +2,7 @@ package article_service ...@@ -2,6 +2,7 @@ package article_service
import ( import (
"bwallet/models" "bwallet/models"
"bwallet/pkg/errno"
"bwallet/pkg/util" "bwallet/pkg/util"
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
...@@ -44,7 +45,6 @@ func (a *Article) Get() (*models.Article, error) { ...@@ -44,7 +45,6 @@ func (a *Article) Get() (*models.Article, error) {
params["id"] = article.Content params["id"] = article.Content
params["language"] = "1" params["language"] = "1"
params["timestamp"] = strconv.FormatInt(time.Now().UTC().Unix(), 10) 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) req, err := http.NewRequest(http.MethodGet, "https://iapi.bishijie.com/article/detail", nil)
if err != nil { if err != nil {
...@@ -55,18 +55,26 @@ func (a *Article) Get() (*models.Article, error) { ...@@ -55,18 +55,26 @@ func (a *Article) Get() (*models.Article, error) {
condition.Add("id", article.Content) condition.Add("id", article.Content)
condition.Add("language", params["language"]) condition.Add("language", params["language"])
condition.Add("timestamp", params["timestamp"]) 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() req.URL.RawQuery = condition.Encode()
//fmt.Println(req.URL.String()) //fmt.Println(req.URL.String())
r, err := http.DefaultClient.Do(req) r, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
body, err := ioutil.ReadAll(r.Body) body, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
result := map[string]interface{}{} result := map[string]interface{}{}
json.Unmarshal(body, &result) json.Unmarshal(body, &result)
if _, ok := result["code"]; ok {
return nil, errno.InternalServerError
}
article.Content = result["content"].(string) 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