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