Browse Source

信息微信回调

longyu 2 years ago
parent
commit
4f3b3706ac
1 changed files with 34 additions and 0 deletions
  1. 34 0
      controllers/wechat.go

+ 34 - 0
controllers/wechat.go

@@ -374,6 +374,9 @@ func (this *WechatCommonController) Notify() {
 	fmt.Println("signature:", signature)
 	fmt.Println("timestamp:", timestamp)
 	fmt.Println("nonce:", nonce)
+
+	method := this.Ctx.Input.Method()
+	fmt.Println("Method:", method)
 	body := this.Ctx.Input.RequestBody
 	paramsMap := this.Ctx.Input.Params()
 	fmt.Println("paramsMap")
@@ -387,3 +390,34 @@ func (this *WechatCommonController) Notify() {
 	utils.FileLog.Info("notify paramsJson result:" + string(paramsJson))
 	this.Ctx.WriteString(echostr)
 }
+
+type Notify struct {
+	ToUserName   string `xml:"ToUserName"`
+	FromUserName string `xml:"FromUserName"`
+	CreateTime   int    `xml:"CreateTime"`
+	MsgType      string `xml:"MsgType"`
+	Event        string `xml:"Event"`
+	EventKey     string `xml:"EventKey"`
+}
+
+//func init() {
+//	str := `<xml><ToUserName><![CDATA[gh_5dc508325c6f]]></ToUserName>
+//<FromUserName><![CDATA[oN0jD1eTfIAf68Y2n24RrvIGXFw4]]></FromUserName>
+//<CreateTime>1654671283</CreateTime>
+//<MsgType><![CDATA[event]]></MsgType>
+//<Event><![CDATA[subscribe]]></Event>
+//<EventKey><![CDATA[]]></EventKey>
+//</xml>`
+//
+//	item := new(Notify)
+//	err := xml.Unmarshal([]byte(str), &item)
+//	if err != nil {
+//		fmt.Println(err.Error())
+//	}
+//	fmt.Println(item.ToUserName)
+//	fmt.Println(item.FromUserName)
+//	fmt.Println(item.CreateTime)
+//	fmt.Println(item.MsgType)
+//	fmt.Println(item.Event)
+//	fmt.Println(item.EventKey)
+//}