京东回调api切换至新接口
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)
|
return partner.CurAPIManager.GetAPI(model.VendorIDJD, appOrgCode).(*jdapi.API)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAPIByToken(token string) (apiObj *jdapi.API) {
|
func GetAPIByAppKey(appKey string) (apiObj *jdapi.API) {
|
||||||
if token == "" {
|
if appKey == "" {
|
||||||
apiObj = getAPI("")
|
apiObj = getAPI("")
|
||||||
} else {
|
} else {
|
||||||
apiList := partner.CurAPIManager.GetAppOrgCodeList(model.VendorIDJD)
|
apiList := partner.CurAPIManager.GetAppOrgCodeList(model.VendorIDJD)
|
||||||
for _, v := range apiList {
|
for _, v := range apiList {
|
||||||
jdAPI := partner.CurAPIManager.GetAPI(model.VendorIDJD, v).(*jdapi.API)
|
jdAPI := partner.CurAPIManager.GetAPI(model.VendorIDJD, v).(*jdapi.API)
|
||||||
if jdAPI.GetToken() == token {
|
if jdAPI.GetAppKey() == appKey {
|
||||||
apiObj = jdAPI
|
apiObj = jdAPI
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
@@ -20,24 +19,15 @@ type DjswController struct {
|
|||||||
beego.Controller
|
beego.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *DjswController) handleMsg(isNeedDecode bool, handler func(*jdapi.API, url.Values, string) *jdapi.CallbackResponse) (callbackResponse *jdapi.CallbackResponse) {
|
func (c *DjswController) handleMsg(isNeedDecode bool, handler func(*jdapi.API, interface{}) *jdapi.CallbackResponse) (callbackResponse *jdapi.CallbackResponse) {
|
||||||
values, token, msgURL, callbackResponse := jdapi.GetCallbackMsg(getUsefulRequest(c.Ctx), isNeedDecode)
|
if callbackMsg, mapData, response := jdapi.GetCallbackMsg2(getUsefulRequest(c.Ctx)); response == nil {
|
||||||
if callbackResponse == nil {
|
if jdAPI := jd.GetAPIByAppKey(callbackMsg.Token); jdAPI != nil {
|
||||||
if jdAPI := jd.GetAPIByToken(token); jdAPI != nil {
|
if response = jdAPI.CheckCallbackValidation2(mapData, callbackMsg.Sign); response == nil {
|
||||||
callbackResponse = handler(jdAPI, values, msgURL)
|
callbackResponse = handler(jdAPI, callbackMsg.Param)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
callbackResponse = jdapi.Err2CallbackResponse(fmt.Errorf("没有匹配的token,非法请求"), "")
|
callbackResponse = jdapi.Err2CallbackResponse(fmt.Errorf("没有匹配的token,非法请求"), "")
|
||||||
}
|
globals.SugarLogger.Warnf("handleMsg failed, can not find api for:%s", callbackMsg.Token)
|
||||||
}
|
|
||||||
if beego.BConfig.RunMode == "beta" ||
|
|
||||||
beego.BConfig.RunMode == "alpha" {
|
|
||||||
if callbackMsg, mapData, response := jdapi.GetCallbackMsg2(getUsefulRequest(c.Ctx)); response == nil {
|
|
||||||
if jdAPI := jd.GetAPIByToken(callbackMsg.Token); jdAPI != nil {
|
|
||||||
response = jdAPI.CheckCallbackValidation2(mapData, callbackMsg.Sign)
|
|
||||||
globals.SugarLogger.Debugf("handleMsg response:%v", response)
|
|
||||||
} else {
|
|
||||||
globals.SugarLogger.Debugf("handleMsg failed, can not find api for:%s", callbackMsg.Token)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return callbackResponse
|
return callbackResponse
|
||||||
@@ -45,11 +35,8 @@ func (c *DjswController) handleMsg(isNeedDecode bool, handler func(*jdapi.API, u
|
|||||||
|
|
||||||
func (c *DjswController) orderStatus(isCancelOrder bool) {
|
func (c *DjswController) orderStatus(isCancelOrder bool) {
|
||||||
if c.Ctx.Input.Method() == http.MethodPost {
|
if c.Ctx.Input.Method() == http.MethodPost {
|
||||||
callbackResponse := c.handleMsg(isCancelOrder, func(a *jdapi.API, values url.Values, msgURL string) (callbackResponse *jdapi.CallbackResponse) {
|
callbackResponse := c.handleMsg(isCancelOrder, func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) {
|
||||||
obj, callbackResponse := a.GetOrderCallbackMsg(values, msgURL)
|
callbackResponse = jd.OnOrderMsg(obj.(*jdapi.CallbackOrderMsg))
|
||||||
if callbackResponse == nil {
|
|
||||||
callbackResponse = jd.OnOrderMsg(obj)
|
|
||||||
}
|
|
||||||
return callbackResponse
|
return callbackResponse
|
||||||
})
|
})
|
||||||
c.Data["json"] = c.transferResponse("orderStatus", callbackResponse)
|
c.Data["json"] = c.transferResponse("orderStatus", callbackResponse)
|
||||||
@@ -101,11 +88,8 @@ func (c *DjswController) ApplyCancelOrder() {
|
|||||||
|
|
||||||
func (c *DjswController) PushDeliveryStatus() {
|
func (c *DjswController) PushDeliveryStatus() {
|
||||||
if c.Ctx.Input.Method() == http.MethodPost {
|
if c.Ctx.Input.Method() == http.MethodPost {
|
||||||
callbackResponse := c.handleMsg(true, func(a *jdapi.API, values url.Values, msgURL string) (callbackResponse *jdapi.CallbackResponse) {
|
callbackResponse := c.handleMsg(true, func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) {
|
||||||
obj, callbackResponse := a.GetOrderDeliveryCallbackMsg(values, msgURL)
|
callbackResponse = jd.OnWaybillMsg(obj.(*jdapi.CallbackDeliveryStatusMsg))
|
||||||
if callbackResponse == nil {
|
|
||||||
callbackResponse = jd.OnWaybillMsg(obj)
|
|
||||||
}
|
|
||||||
return callbackResponse
|
return callbackResponse
|
||||||
})
|
})
|
||||||
c.Data["json"] = c.transferResponse("PushDeliveryStatus", callbackResponse)
|
c.Data["json"] = c.transferResponse("PushDeliveryStatus", callbackResponse)
|
||||||
@@ -129,13 +113,8 @@ func (c *DjswController) Token() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *DjswController) StockIsHave() {
|
func (c *DjswController) StockIsHave() {
|
||||||
// globals.SugarLogger.Info(string(c.Ctx.Input.RequestBody))
|
|
||||||
if c.Ctx.Input.Method() == http.MethodPost {
|
if c.Ctx.Input.Method() == http.MethodPost {
|
||||||
callbackResponse := c.handleMsg(true, func(a *jdapi.API, values url.Values, msgURL string) (callbackResponse *jdapi.CallbackResponse) {
|
callbackResponse := c.handleMsg(true, func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) {
|
||||||
_, callbackResponse = a.GetStoreStockCallbackMsg(values, msgURL)
|
|
||||||
if callbackResponse == nil {
|
|
||||||
// globals.SugarLogger.Debugf("StockIsHave, obj:%s", utils.Format4Output(obj, false))
|
|
||||||
}
|
|
||||||
return callbackResponse
|
return callbackResponse
|
||||||
})
|
})
|
||||||
c.Data["json"] = c.transferResponse("StockIsHave", callbackResponse)
|
c.Data["json"] = c.transferResponse("StockIsHave", callbackResponse)
|
||||||
@@ -147,11 +126,8 @@ func (c *DjswController) StockIsHave() {
|
|||||||
|
|
||||||
func (c *DjswController) SinglePromoteCreate() {
|
func (c *DjswController) SinglePromoteCreate() {
|
||||||
if c.Ctx.Input.Method() == http.MethodPost {
|
if c.Ctx.Input.Method() == http.MethodPost {
|
||||||
callbackResponse := c.handleMsg(false, func(a *jdapi.API, values url.Values, msgURL string) (callbackResponse *jdapi.CallbackResponse) {
|
callbackResponse := c.handleMsg(false, func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) {
|
||||||
obj, callbackResponse := a.GetOrderCallbackMsg(values, msgURL)
|
callbackResponse = jd.OnActMsg(obj.(*jdapi.CallbackOrderMsg))
|
||||||
if callbackResponse == nil {
|
|
||||||
callbackResponse = jd.OnActMsg(obj)
|
|
||||||
}
|
|
||||||
return callbackResponse
|
return callbackResponse
|
||||||
})
|
})
|
||||||
c.Data["json"] = c.transferResponse("SinglePromoteCreate", callbackResponse)
|
c.Data["json"] = c.transferResponse("SinglePromoteCreate", callbackResponse)
|
||||||
@@ -163,11 +139,8 @@ func (c *DjswController) SinglePromoteCreate() {
|
|||||||
|
|
||||||
func (c *DjswController) StoreCrud() {
|
func (c *DjswController) StoreCrud() {
|
||||||
if c.Ctx.Input.Method() == http.MethodPost {
|
if c.Ctx.Input.Method() == http.MethodPost {
|
||||||
callbackResponse := c.handleMsg(false, func(a *jdapi.API, values url.Values, msgURL string) (callbackResponse *jdapi.CallbackResponse) {
|
callbackResponse := c.handleMsg(false, func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) {
|
||||||
obj, callbackResponse := a.GetOrderCallbackMsg(values, msgURL)
|
callbackResponse = jd.OnStoreMsg(obj.(*jdapi.CallbackOrderMsg))
|
||||||
if callbackResponse == nil {
|
|
||||||
callbackResponse = jd.OnStoreMsg(obj)
|
|
||||||
}
|
|
||||||
return callbackResponse
|
return callbackResponse
|
||||||
})
|
})
|
||||||
c.Data["json"] = c.transferResponse("StoreCrud", callbackResponse)
|
c.Data["json"] = c.transferResponse("StoreCrud", callbackResponse)
|
||||||
|
|||||||
Reference in New Issue
Block a user