|
@@ -59,7 +59,7 @@ func Auth(c *gin.Context) {
|
|
if !isExist {
|
|
if !isExist {
|
|
isExist, err = authService.MD5Check()
|
|
isExist, err = authService.MD5Check()
|
|
if !isExist {
|
|
if !isExist {
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR_AUTH, "")
|
|
|
|
|
|
+ appG.Response(http.StatusOK, e.ERROR_AUTH, "密码错误!")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -294,3 +294,57 @@ func GetWxCode(c *gin.Context) {
|
|
}
|
|
}
|
|
appG.Response(http.StatusOK, e.SUCCESS, dataMap)
|
|
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)
|
|
|
|
+}
|