diff --git a/app/hdl/hdl_wx_open.go b/app/hdl/hdl_wx_open.go new file mode 100644 index 0000000..d0c9d2b --- /dev/null +++ b/app/hdl/hdl_wx_open.go @@ -0,0 +1,34 @@ +package hdl + +import ( + "applet/app/utils" + "fmt" + "github.com/gin-gonic/gin" + "net/http" +) + +type ReqWxMessage struct { + AppId string `json:"AppId"` + FromUserName string `json:"CreateTime"` + InfoType string `json:"InfoType"` + ComponentVerifyTicket string `json:"ComponentVerifyTicket"` // text | image | voice | shortvideo | location +} + +func SetTicket(c *gin.Context) { + params := c.QueryMap("*") + utils.FilePutContents("SetTicket_Get", utils.SerializeStr(params)) + + var wxMsg ReqWxMessage + err := c.BindXML(&wxMsg) + if err != nil { + fmt.Println("setTicket>>>>>>>>", err.Error()) + } + utils.FilePutContents("SetTicket_XML", utils.SerializeStr(wxMsg)) + c.String(http.StatusOK, "success") + return +} + +func WechatMsgRecieve(c *gin.Context) { + + return +} diff --git a/app/router/router.go b/app/router/router.go index e3c7689..3aee848 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -51,6 +51,11 @@ func Init() *gin.Engine { func route(r *gin.RouterGroup) { r.GET("/test", hdl.Demo) + wxOpenNotify := r.Group("/wxOpenNotify") + { + wxOpenNotify.Any("/:APPID/wechatMsgRecieve", hdl.WechatMsgRecieve) + wxOpenNotify.Any("/setTicket", hdl.SetTicket) + } r.Use(mw.DB) // 以下接口需要用到数据库 { diff --git a/app/utils/file.go b/app/utils/file.go index 70a2927..93ed08f 100644 --- a/app/utils/file.go +++ b/app/utils/file.go @@ -1,11 +1,22 @@ package utils import ( + "os" "path" "strings" + "time" ) // 获取文件后缀 func FileExt(fname string) string { return strings.ToLower(strings.TrimLeft(path.Ext(fname), ".")) } + +func FilePutContents(fileName string, content string) { + fd, _ := os.OpenFile("./tmp/"+fileName+".log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) + fd_time := time.Now().Format("2006-01-02 15:04:05") + fd_content := strings.Join([]string{"[", fd_time, "] ", content, "\n"}, "") + buf := []byte(fd_content) + fd.Write(buf) + fd.Close() +}