package controllers

import (
	"net/http"

	"git.rosy.net.cn/baseapi/utils"
	"git.rosy.net.cn/jx-callback/business/jxstore/cms"
	"git.rosy.net.cn/jx-callback/globals/api"
	"github.com/astaxie/beego/server/web"
)

type DingDingController struct {
	web.Controller
}

func init() {

}

func (c *DingDingController) Msg() {
	if c.Ctx.Input.Method() == http.MethodPost {
		dataMap := utils.URLValues2Map(c.Ctx.Request.Form)
		obj, callbackResponse := api.DingDingAPI.GetCallbackMsg(dataMap, c.Ctx.Input.RequestBody)
		if callbackResponse == nil {
			callbackResponse = cms.OnDingDingMsg(obj)
			if callbackResponse == nil {
				callbackResponse = api.DingDingAPI.Err2CallbackResponse(nil)
			}
		}
		c.Data["json"] = callbackResponse
		c.ServeJSON()
	} else {
		c.Abort("404")
	}
}
