用新京东回调接口

GetAPIByAppKey
This commit is contained in:
gazebo
2019-12-09 11:05:00 +08:00
parent 992711c5c2
commit 7995f507b1
3 changed files with 21 additions and 35 deletions

View File

@@ -149,7 +149,7 @@ func (p *PurchaseHandler) OrderDetail2Financial(orderData map[string]interface{}
} }
} }
} }
globals.SugarLogger.Debug(utils.Format4Output(orderFinancial.Discounts, false)) // globals.SugarLogger.Debug(utils.Format4Output(orderFinancial.Discounts, false))
} }
order1, err2 := getAPI("").OrderShoudSettlementService(orderFinancial.VendorOrderID) order1, err2 := getAPI("").OrderShoudSettlementService(orderFinancial.VendorOrderID)
if err = err2; err == nil { if err = err2; err == nil {

View File

@@ -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
} }

View File

@@ -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,13 +19,16 @@ 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) callbackMsg, mapData, callbackResponse := jdapi.GetCallbackMsg2(getUsefulRequest(c.Ctx))
globals.SugarLogger.Debug(utils.Format4Output(callbackMsg, true))
if callbackResponse == nil { if callbackResponse == nil {
if jdAPI := jd.GetAPIByToken(token); jdAPI != nil { if jdAPI := jd.GetAPIByAppKey(callbackMsg.AppKey); jdAPI != nil {
callbackResponse = handler(jdAPI, values, msgURL) if callbackResponse = jdAPI.CheckCallbackValidation2(mapData, callbackMsg.Sign); callbackResponse == nil {
callbackResponse = handler(jdAPI, callbackMsg.Param)
}
} else { } else {
callbackResponse = jdapi.Err2CallbackResponse(fmt.Errorf("没有匹配的token,非法请求"), "") callbackResponse = jdapi.Err2CallbackResponse(fmt.Errorf("没有匹配的appKey,非法请求"), "")
} }
} }
return callbackResponse return callbackResponse
@@ -34,11 +36,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)
@@ -90,11 +89,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)
@@ -120,11 +116,7 @@ func (c *DjswController) Token() {
func (c *DjswController) StockIsHave() { func (c *DjswController) StockIsHave() {
// globals.SugarLogger.Info(string(c.Ctx.Input.RequestBody)) // 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)
@@ -136,11 +128,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)
@@ -152,11 +141,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)