package server import ( "crypto/sha1" "encoding/hex" "io/ioutil" "sort" "strings" "github.com/gin-gonic/gin" "kpt.notice/apiserver/service" "kpt.notice/middleware/notice" "kpt.notice/pkg/log" ) // func getMsgType(c *gin.Context) { // name := c.PostForm("remind_type") // id, err := svc.QueryRemindTypeID(name) // eJSON(c, id, err) // } /* 获取临时二维码 */ func getCode(c *gin.Context) { sceneStr := c.Query("scene_str") log.Infof("ss getcode p sceneStr===== %s", sceneStr) resp, err := service.CreateQRCode(sceneStr) if err != nil { c.String(400, err.Error()) } c.Data(200, "image/jpg", resp) } // 服务器地址认证 func tokenAuth(c *gin.Context) { req := c.Request timestamp := req.FormValue("timestamp") nonce := req.FormValue("nonce") signnature := req.FormValue("signature") echostr := req.FormValue("echostr") token := "123" arr := []string{token, timestamp, nonce} sort.Strings(arr) str := strings.Join(arr, "") h := sha1.New() h.Write([]byte(str)) sha1str := hex.EncodeToString(h.Sum(nil)) if sha1str == signnature { c.String(200, echostr) } } /* 接收微信服务器推送的消息 */ func wxMessage(c *gin.Context) { body, err := ioutil.ReadAll(c.Request.Body) if err != nil { log.Errorf("wxMessage. %v", err) c.String(400, err.Error()) return } log.Infof("se wxMessage { body}====== %s", body) if err != nil { c.String(400, err.Error()) } output, err := service.ReceiveMessage(body) if output == nil { c.String(400, "error") } else { c.JSON(200, output) notice.ServerAcc.Server.Response(c.Writer, c.Request, output) } }