Merge remote-tracking branch 'origin/mark' into yonghui
This commit is contained in:
@@ -26,14 +26,14 @@ func getAPI(appOrgCode string) (apiObj *jdapi.API) {
|
||||
return partner.CurAPIManager.GetAPI(model.VendorIDJD, appOrgCode).(*jdapi.API)
|
||||
}
|
||||
|
||||
func GetAPIByAppKey(appKey string) (apiObj *jdapi.API) {
|
||||
if appKey == "" {
|
||||
func GetAPIByToken(token string) (apiObj *jdapi.API) {
|
||||
if token == "" {
|
||||
apiObj = getAPI("")
|
||||
} else {
|
||||
apiList := partner.CurAPIManager.GetAppOrgCodeList(model.VendorIDJD)
|
||||
for _, v := range apiList {
|
||||
jdAPI := partner.CurAPIManager.GetAPI(model.VendorIDJD, v).(*jdapi.API)
|
||||
if jdAPI.GetAppKey() == appKey {
|
||||
if jdAPI.GetToken() == token {
|
||||
apiObj = jdAPI
|
||||
break
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
@@ -19,15 +20,13 @@ type DjswController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (c *DjswController) handleMsg(isNeedDecode bool, handler func(*jdapi.API, interface{}) *jdapi.CallbackResponse) (callbackResponse *jdapi.CallbackResponse) {
|
||||
if callbackMsg, mapData, response := jdapi.GetCallbackMsg2(getUsefulRequest(c.Ctx)); response == nil {
|
||||
if jdAPI := jd.GetAPIByAppKey(callbackMsg.AppKey); jdAPI != nil {
|
||||
if response = jdAPI.CheckCallbackValidation2(mapData, callbackMsg.Sign); response == nil {
|
||||
callbackResponse = handler(jdAPI, callbackMsg.Param)
|
||||
}
|
||||
func (c *DjswController) handleMsg(isNeedDecode bool, handler func(*jdapi.API, url.Values, string) *jdapi.CallbackResponse) (callbackResponse *jdapi.CallbackResponse) {
|
||||
values, token, msgURL, callbackResponse := jdapi.GetCallbackMsg(getUsefulRequest(c.Ctx), isNeedDecode)
|
||||
if callbackResponse == nil {
|
||||
if jdAPI := jd.GetAPIByToken(token); jdAPI != nil {
|
||||
callbackResponse = handler(jdAPI, values, msgURL)
|
||||
} else {
|
||||
callbackResponse = jdapi.Err2CallbackResponse(fmt.Errorf("没有匹配的token,非法请求"), "")
|
||||
globals.SugarLogger.Warnf("handleMsg failed, can not find api for:%s", callbackMsg.AppKey)
|
||||
}
|
||||
}
|
||||
return callbackResponse
|
||||
@@ -35,8 +34,11 @@ func (c *DjswController) handleMsg(isNeedDecode bool, handler func(*jdapi.API, i
|
||||
|
||||
func (c *DjswController) orderStatus(isCancelOrder bool) {
|
||||
if c.Ctx.Input.Method() == http.MethodPost {
|
||||
callbackResponse := c.handleMsg(isCancelOrder, func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) {
|
||||
callbackResponse = jd.OnOrderMsg(obj.(*jdapi.CallbackOrderMsg))
|
||||
callbackResponse := c.handleMsg(isCancelOrder, func(a *jdapi.API, values url.Values, msgURL string) (callbackResponse *jdapi.CallbackResponse) {
|
||||
obj, callbackResponse := a.GetOrderCallbackMsg(values, msgURL)
|
||||
if callbackResponse == nil {
|
||||
callbackResponse = jd.OnOrderMsg(obj)
|
||||
}
|
||||
return callbackResponse
|
||||
})
|
||||
c.Data["json"] = c.transferResponse("orderStatus", callbackResponse)
|
||||
@@ -88,8 +90,11 @@ func (c *DjswController) ApplyCancelOrder() {
|
||||
|
||||
func (c *DjswController) PushDeliveryStatus() {
|
||||
if c.Ctx.Input.Method() == http.MethodPost {
|
||||
callbackResponse := c.handleMsg(true, func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) {
|
||||
callbackResponse = jd.OnWaybillMsg(obj.(*jdapi.CallbackDeliveryStatusMsg))
|
||||
callbackResponse := c.handleMsg(true, func(a *jdapi.API, values url.Values, msgURL string) (callbackResponse *jdapi.CallbackResponse) {
|
||||
obj, callbackResponse := a.GetOrderDeliveryCallbackMsg(values, msgURL)
|
||||
if callbackResponse == nil {
|
||||
callbackResponse = jd.OnWaybillMsg(obj)
|
||||
}
|
||||
return callbackResponse
|
||||
})
|
||||
c.Data["json"] = c.transferResponse("PushDeliveryStatus", callbackResponse)
|
||||
@@ -113,8 +118,13 @@ func (c *DjswController) Token() {
|
||||
}
|
||||
|
||||
func (c *DjswController) StockIsHave() {
|
||||
// globals.SugarLogger.Info(string(c.Ctx.Input.RequestBody))
|
||||
if c.Ctx.Input.Method() == http.MethodPost {
|
||||
callbackResponse := c.handleMsg(true, func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) {
|
||||
callbackResponse := c.handleMsg(true, func(a *jdapi.API, values url.Values, msgURL string) (callbackResponse *jdapi.CallbackResponse) {
|
||||
_, callbackResponse = a.GetStoreStockCallbackMsg(values, msgURL)
|
||||
if callbackResponse == nil {
|
||||
// globals.SugarLogger.Debugf("StockIsHave, obj:%s", utils.Format4Output(obj, false))
|
||||
}
|
||||
return callbackResponse
|
||||
})
|
||||
c.Data["json"] = c.transferResponse("StockIsHave", callbackResponse)
|
||||
@@ -126,8 +136,11 @@ func (c *DjswController) StockIsHave() {
|
||||
|
||||
func (c *DjswController) SinglePromoteCreate() {
|
||||
if c.Ctx.Input.Method() == http.MethodPost {
|
||||
callbackResponse := c.handleMsg(false, func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) {
|
||||
callbackResponse = jd.OnActMsg(obj.(*jdapi.CallbackOrderMsg))
|
||||
callbackResponse := c.handleMsg(false, func(a *jdapi.API, values url.Values, msgURL string) (callbackResponse *jdapi.CallbackResponse) {
|
||||
obj, callbackResponse := a.GetOrderCallbackMsg(values, msgURL)
|
||||
if callbackResponse == nil {
|
||||
callbackResponse = jd.OnActMsg(obj)
|
||||
}
|
||||
return callbackResponse
|
||||
})
|
||||
c.Data["json"] = c.transferResponse("SinglePromoteCreate", callbackResponse)
|
||||
@@ -139,8 +152,11 @@ func (c *DjswController) SinglePromoteCreate() {
|
||||
|
||||
func (c *DjswController) StoreCrud() {
|
||||
if c.Ctx.Input.Method() == http.MethodPost {
|
||||
callbackResponse := c.handleMsg(false, func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) {
|
||||
callbackResponse = jd.OnStoreMsg(obj.(*jdapi.CallbackOrderMsg))
|
||||
callbackResponse := c.handleMsg(false, func(a *jdapi.API, values url.Values, msgURL string) (callbackResponse *jdapi.CallbackResponse) {
|
||||
obj, callbackResponse := a.GetOrderCallbackMsg(values, msgURL)
|
||||
if callbackResponse == nil {
|
||||
callbackResponse = jd.OnStoreMsg(obj)
|
||||
}
|
||||
return callbackResponse
|
||||
})
|
||||
c.Data["json"] = c.transferResponse("StoreCrud", callbackResponse)
|
||||
|
||||
Reference in New Issue
Block a user