You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.7 KiB
Go

3 years ago
/**
* @Author: jager
* @Email: lhj168os@gmail.com
* @File: main
* @Date: 2021/12/20 2:24
* @package: ss
* @Version: v1.0.0
*
* @Description:
*
*/
package main
import (
"github.com/gin-gonic/gin"
"github.com/jageros/hawox/contextx"
"github.com/jageros/hawox/httpx"
"github.com/jageros/hawox/logx"
"net/http"
"stock/msg"
"time"
)
func main() {
ctx, cancel := contextx.Default()
defer cancel()
logx.Init(logx.DebugLevel, logx.SetCaller(), logx.SetRequest())
defer logx.Sync()
httpx.InitializeHttpServer(ctx, func(engine *gin.Engine) {
r := engine.Group("/api")
r.GET("/sayhello", func(c *gin.Context) {
httpx.PkgMsgWrite(c, map[string]interface{}{"say": "hello world!"})
})
r.POST("/receive", func(c *gin.Context) {
rMsg := &msg.RData{}
err := c.BindXML(rMsg)
if err != nil {
logx.Error(err)
} else {
logx.Info(rMsg)
}
wMsg := &xml{
ToUserName: rMsg.FromUserName,
FromUserName: rMsg.ToUserName,
CreateTime: int(time.Now().Unix()),
MsgType: "text",
Content: "收到,谢谢!",
}
c.XML(http.StatusOK, wMsg)
//c.XML(http.StatusOK, wMsg)
//err = msg.Rcv(rMsg.FromUserName)
//if err != nil {
// logx.Error(err)
//}
//c.String(http.StatusOK, "success")
})
r.GET("/receive", func(c *gin.Context) {
echostr := c.Query("echostr")
logx.Infof("=== %s ===", echostr)
c.String(http.StatusOK, echostr)
})
}, func(s *httpx.Server) {
s.Mode = "debug"
s.Port = 8567
})
err := ctx.Wait()
logx.Infof("Stop With: %v", err)
}
type xml struct {
ToUserName string `xml:"ToUserName"`
FromUserName string `xml:"FromUserName"`
CreateTime int `xml:"CreateTime"`
MsgType string `xml:"MsgType"`
Content string `xml:"Content"`
}