53 lines
945 B
Go
53 lines
945 B
Go
|
|
package handler
|
||
|
|
|
||
|
|
import (
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
"myschools.me/heritage/heritage-api/service"
|
||
|
|
)
|
||
|
|
|
||
|
|
func WechatQrGet(c *gin.Context) {
|
||
|
|
reqid := c.Param("id")
|
||
|
|
if reqid == "" {
|
||
|
|
c.JSON(http.StatusBadRequest, gin.H{
|
||
|
|
"error": "reqid is required",
|
||
|
|
})
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
resp, err := service.WechatQrGet(&reqid)
|
||
|
|
if err != nil {
|
||
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||
|
|
"error": err.Error(),
|
||
|
|
})
|
||
|
|
return
|
||
|
|
}
|
||
|
|
c.JSON(http.StatusOK, resp)
|
||
|
|
}
|
||
|
|
|
||
|
|
func WechatAuth(c *gin.Context) {
|
||
|
|
reqid := c.Param("id")
|
||
|
|
if reqid == "" {
|
||
|
|
c.JSON(http.StatusBadRequest, gin.H{
|
||
|
|
"error": "reqid is required",
|
||
|
|
})
|
||
|
|
return
|
||
|
|
}
|
||
|
|
code := c.Query("code")
|
||
|
|
if code == "" {
|
||
|
|
c.JSON(http.StatusBadRequest, gin.H{
|
||
|
|
"error": "code is required",
|
||
|
|
})
|
||
|
|
return
|
||
|
|
}
|
||
|
|
resp, err := service.WechatAuth(&reqid, &code)
|
||
|
|
if err != nil {
|
||
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||
|
|
"error": err.Error(),
|
||
|
|
})
|
||
|
|
return
|
||
|
|
}
|
||
|
|
c.JSON(http.StatusOK, resp)
|
||
|
|
}
|