|
|
|
@@ -10,6 +10,8 @@ import ( |
|
|
|
) |
|
|
|
|
|
|
|
// AcceptWechatEvent |
|
|
|
// https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Receiving_event_pushes.html |
|
|
|
// https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Passive_user_reply_message.html |
|
|
|
func AcceptWechatEvent(ctx *context.Context) { |
|
|
|
b, _ := ioutil.ReadAll(ctx.Req.Request.Body) |
|
|
|
we := wechat.WechatEvent{} |
|
|
|
@@ -17,8 +19,10 @@ func AcceptWechatEvent(ctx *context.Context) { |
|
|
|
|
|
|
|
log.Info("accept wechat event= %+v", we) |
|
|
|
var replyStr string |
|
|
|
if we.Event == "subscribe" { |
|
|
|
switch we.Event { |
|
|
|
case wechat.WECHAT_EVENT_SUBSCRIBE, wechat.WECHAT_EVENT_SCAN: |
|
|
|
replyStr = wechat.HandleSubscribeEvent(we) |
|
|
|
break |
|
|
|
} |
|
|
|
|
|
|
|
if replyStr == "" { |
|
|
|
@@ -29,7 +33,7 @@ func AcceptWechatEvent(ctx *context.Context) { |
|
|
|
ToUserName: we.FromUserName, |
|
|
|
FromUserName: we.ToUserName, |
|
|
|
CreateTime: time.Now().Unix(), |
|
|
|
MsgType: "text", |
|
|
|
MsgType: wechat.WECHAT_MSG_TYPE_TEXT, |
|
|
|
Content: replyStr, |
|
|
|
} |
|
|
|
ctx.XML(200, reply) |
|
|
|
|