瀏覽代碼

get参数 + 变空格的bug处理

xingzai 3 年之前
父節點
當前提交
eb1bbf66f3
共有 3 個文件被更改,包括 61 次插入12 次删除
  1. 0 2
      controllers/base_auth.go
  2. 6 6
      controllers/base_common.go
  3. 55 4
      controllers/report.go

+ 0 - 2
controllers/base_auth.go

@@ -113,7 +113,6 @@ func checkSign(postData map[string]string, ip string) (err error) {
 	}
 
 	appid := postData["appid"]
-	fmt.Println(appid)
 	if appid == "" {
 		err = errors.New("参数异常,缺少appid")
 		return
@@ -189,7 +188,6 @@ func checkSign(postData map[string]string, ip string) (err error) {
 	//md5.Sum([]byte(signStr+"key="+key))  这是md5加密出来后的每个字符的ascall码,需要再转换成对应的字符
 	//3,全转大写(md5(拼装的字符串后+分配给你的app_secret))
 	sign := strings.ToUpper(fmt.Sprintf("%x", md5.Sum([]byte(signStr+"secret="+openApiUserInfo.Secret))))
-	fmt.Println(sign)
 	if sign != ownSign {
 		utils.ApiLog.Println(fmt.Sprintf("签名校验异常,签名字符串:%v;服务端签名值:%v", signStr, sign))
 		return errors.New("签名校验异常,请核实签名")

+ 6 - 6
controllers/base_common.go

@@ -15,15 +15,15 @@ type BaseCommon struct {
 }
 
 type Response struct {
-	Code   int         `json:"code"`
-	Data   interface{} `json:"data"`
-	Msg    string      `json:"msg"`
+	Code int         `json:"code"`
+	Data interface{} `json:"data"`
+	Msg  string      `json:"msg"`
 }
 
 const (
-	SUCCESS     = 200 //成功
-	ERROR       = 400 //代表业务处理失败,前端同学需要做额外逻辑处理
-	SIGN_ERROR  = 401   //签名异常
+	SUCCESS    = 200 //成功
+	ERROR      = 400 //代表业务处理失败,前端同学需要做额外逻辑处理
+	SIGN_ERROR = 401 //签名异常
 )
 
 //返回数据

+ 55 - 4
controllers/report.go

@@ -6,7 +6,9 @@ import (
 	tables "hongze/hongze_open_api/models/tables/report"
 	"hongze/hongze_open_api/models/tables/wx_user"
 	"hongze/hongze_open_api/utils"
+	"net/url"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -34,7 +36,7 @@ func (c *ReportController) ListReport() {
 	currentIndex, _ := c.GetInt("_page")
 	keyWord := c.GetString("keyword")
 	reportType := c.GetString("report_type")
-	mobile := c.GetString("mobile")
+	//mobile := c.GetString("mobile")
 	var startSize int
 	if pageSize <= 0 {
 		pageSize = utils.PageSize20
@@ -43,6 +45,23 @@ func (c *ReportController) ListReport() {
 		currentIndex = 1
 	}
 	startSize = utils.StartIndex(currentIndex, pageSize)
+	//通过url获取mobile中的参数
+	var mobile string
+	URL, err := url.Parse(c.Ctx.Input.URI())
+	if err != nil {
+		fmt.Println(err)
+		c.FailWithMessage("获取报告失败")
+		return
+	}
+	urlParameter := URL.RawQuery
+	sliceUrl := strings.Split(urlParameter, "&")
+	if len(sliceUrl) > 0 {
+		for _, v := range sliceUrl {
+			if strings.Contains(v, "mobile=") {
+				mobile = strings.Replace(v, "mobile=", "", -1)
+			}
+		}
+	}
 	if mobile == "" {
 		c.FailWithMessage("mobile 必传")
 		return
@@ -120,16 +139,31 @@ func (c *ReportController) ListReport() {
 // @router /getReportInfo [get]
 func (c *ReportControllerCommon) GetReportInfo() {
 	researchReportId, _ := c.GetInt("research_report_id")
-	mobile := c.GetString("mobile")
+	//mobile := c.GetString("mobile")
 	if researchReportId < 1 {
 		c.FailWithMessage("请传入报告id")
 		return
 	}
+	var mobile string
+	URL, err := url.Parse(c.Ctx.Input.URI())
+	if err != nil {
+		fmt.Println(err)
+		c.FailWithMessage("获取报告失败")
+		return
+	}
+	urlParameter := URL.RawQuery
+	sliceUrl := strings.Split(urlParameter, "&")
+	if len(sliceUrl) > 0 {
+		for _, v := range sliceUrl {
+			if strings.Contains(v, "mobile=") {
+				mobile = strings.Replace(v, "mobile=", "", -1)
+			}
+		}
+	}
 	if mobile == "" {
 		c.FailWithMessage("mobile 必传")
 		return
 	}
-
 	var dateTxt = []byte(mobile)
 	resultDe := utils.DesBase64Decrypt(dateTxt)
 	deMobile := string(resultDe)
@@ -188,11 +222,28 @@ func (c *ReportControllerCommon) GetReportInfo() {
 // @router /getReportChapterInfo [get]
 func (c *ReportControllerCommon) GetResearchReportChapter() {
 	researchReportTypeId, _ := c.GetInt("ResearchReportTypeId")
-	mobile := c.GetString("mobile")
+	//mobile := c.GetString("mobile")
 	if researchReportTypeId < 1 {
 		c.FailWithMessage("请传入章节id")
 		return
 	}
+	//通过url获取mobile中的参数
+	var mobile string
+	URL, err := url.Parse(c.Ctx.Input.URI())
+	if err != nil {
+		fmt.Println(err)
+		c.FailWithMessage("获取报告失败")
+		return
+	}
+	urlParameter := URL.RawQuery
+	sliceUrl := strings.Split(urlParameter, "&")
+	if len(sliceUrl) > 0 {
+		for _, v := range sliceUrl {
+			if strings.Contains(v, "mobile=") {
+				mobile = strings.Replace(v, "mobile=", "", -1)
+			}
+		}
+	}
 	if mobile == "" {
 		c.FailWithMessage("mobile 必传")
 		return