- use auto router for callback msg.

- first normal demo api FinishedPickup added.
This commit is contained in:
gazebo
2018-08-20 15:08:36 +08:00
parent eeeab319fa
commit b69bac1182
16 changed files with 154 additions and 889 deletions

View File

@@ -1,56 +1,32 @@
package controllers
import (
"net/http"
"git.rosy.net.cn/baseapi/platformapi/elmapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/partner/purchase/elm"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/legacy/elm/controller"
"github.com/astaxie/beego"
)
// Operations about ELMOrder
type ELMOrderController struct {
type ElemeController struct {
beego.Controller
}
func (c *ELMOrderController) URLMapping() {
c.Mapping("MsgPost", c.MsgPost)
c.Mapping("MsgGet", c.MsgGet)
}
// @Title all msg
// @Description create object
// @Success 200 {string} models.Object.Id
// @Failure 403 body is empty
// @router /msg [post]
func (c *ELMOrderController) MsgPost() {
obj, callbackResponse := api.ElmAPI.GetCallbackMsg(c.Ctx.Input.RequestBody)
if callbackResponse == nil {
if globals.CallLegacyMsgHandler {
cc := &controller.OrderController{}
callbackResponse = cc.OrderMessage(obj)
}
if globals.CallNewMsgHandler {
if globals.CallLegacyMsgHandler {
utils.CallFuncAsync(func() {
elm.OnCallbackMsg(obj)
})
} else {
callbackResponse = elm.OnCallbackMsg(obj)
}
// https://open.shop.ele.me/openapi/documents/httppushmethod
func (c *ElemeController) Msg() {
if c.Ctx.Input.Method() == http.MethodPost {
obj, callbackResponse := api.ElmAPI.GetCallbackMsg(c.Ctx.Input.RequestBody)
if callbackResponse == nil {
callbackResponse = elm.OnCallbackMsg(obj)
}
c.Data["json"] = callbackResponse
c.ServeJSON()
} else if c.Ctx.Input.Method() == http.MethodGet { // 应用需要支持推送地址的GET访问当GET请求访问时请直接返回{“message”:“ok”},用于推送地址的可用性测试。
c.Data["json"] = elmapi.SuccessResponse
c.ServeJSON()
} else {
c.Abort("404")
}
c.Data["json"] = callbackResponse
c.ServeJSON()
}
// @Title all msg test
// @Description create object
// @Success 200 {string} models.Object.Id
// @router /msg [get]
func (c *ELMOrderController) MsgGet() {
c.Data["json"] = elmapi.SuccessResponse
c.ServeJSON()
}