12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- 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) {
- // sceneID := c.PostForm("scenne_id")
- sceneID := c.Query("scene_id")
- log.Infof("sceneID: %s", sceneID)
- resp, err := service.CreateQRCode(sceneID)
- 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) {
- // wxmsg := new(http.WxMessage)
- // if !Bind(c, wxmsg) {
- // return
- // }
- body, err := ioutil.ReadAll(c.Request.Body)
- if err != nil {
- c.String(400, err.Error())
- }
- output := service.ReceiveMessage(body)
- if output == nil {
- c.String(400, "error")
- } else {
- c.JSON(200, output)
- notice.ServerAcc.Server.Response(c.Writer, c.Request, output)
- }
- }
|