package controllers

import (
	"bytes"
	"git.rosy.net.cn/jx-callback/business/partner/purchase/jdshop"
	"git.rosy.net.cn/jx-callback/globals/api"
	"github.com/astaxie/beego/server/web"
	"io/ioutil"
	"net/http"
)

type JdsController struct {
	web.Controller
}

// Msg 这个是京东秒送平台回调
func (c *JdsController) Msg() {
	if c.Ctx.Input.Method() == http.MethodPost {
		ctx := c.Ctx
		ctx.Request.Body = ioutil.NopCloser(bytes.NewReader(ctx.Input.RequestBody))
		call, err := api.JdShopAPI.GetCallbackMsg(ctx.Request)
		if err == nil {
			jdshop.OnCallbackMsg(call)
		}
		c.Data["json"] = call
		c.ServeJSON()
	} else {
		c.Abort("404")
	}
}
