baishaojie 9 ヶ月 前
コミット
c818aae707
3 ファイル変更55 行追加1 行削除
  1. BIN
      TMRWatchComm
  2. BIN
      TMRWatchComm.zip
  3. 55 1
      http/handle/api/user.go

BIN
TMRWatchComm


BIN
TMRWatchComm.zip


+ 55 - 1
http/handle/api/user.go

@@ -59,7 +59,7 @@ func Auth(c *gin.Context) {
 	if !isExist {
 		isExist, err = authService.MD5Check()
 		if !isExist {
-			appG.Response(http.StatusInternalServerError, e.ERROR_AUTH, "")
+			appG.Response(http.StatusOK, e.ERROR_AUTH, "密码错误!")
 			return
 		}
 	}
@@ -294,3 +294,57 @@ func GetWxCode(c *gin.Context) {
 	}
 	appG.Response(http.StatusOK, e.SUCCESS, dataMap)
 }
+
+func GetYqWxCode(c *gin.Context) {
+	appG := app.Gin{C: c}
+	code := c.Query("code")
+
+	url := "https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=%s"
+	var appid, secret, jsCode, grantType string
+	jsCode = code
+
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	wxConfigList, err := tx.SQL(" select * from wx_config where system = ? ", "yq").Query().List()
+	if err != nil {
+		logs.Error("GetWxCode-error1:", err)
+		appG.Response(http.StatusInternalServerError, e.ERROR, false)
+		return
+	}
+
+	for _, wx := range wxConfigList {
+		grantType = wx["grantType"].(string)
+		appid = wx["appid"].(string)
+		secret = wx["secret"].(string)
+	}
+	url = fmt.Sprintf(url, appid, secret, jsCode, grantType)
+
+	client := &http.Client{Timeout: 5 * time.Second}
+	payload := strings.NewReader(``)
+	req, err := http.NewRequest(http.MethodGet, url, payload)
+	if err != nil {
+		appG.Response(http.StatusInternalServerError, e.ERROR_AUTH_TOKEN, err)
+		return
+	}
+	res, err := client.Do(req)
+	if err != nil {
+		appG.Response(http.StatusInternalServerError, e.ERROR_AUTH_TOKEN, err)
+		return
+	}
+	defer res.Body.Close()
+
+	body, err := ioutil.ReadAll(res.Body)
+	if err != nil {
+		appG.Response(http.StatusInternalServerError, e.ERROR_AUTH_TOKEN, err)
+		return
+	}
+
+	var data interface{}
+	json.Unmarshal(body, &data)
+	dataMap := data.(map[string]interface{})
+	if _, ok := dataMap["code"]; !ok {
+		dataMap["code"] = ""
+	}
+	appG.Response(http.StatusOK, e.SUCCESS, dataMap)
+}