用新京东回调接口
GetAPIByAppKey
This commit is contained in:
@@ -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)
|
||||
if err = err2; err == nil {
|
||||
|
||||
@@ -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,13 +19,16 @@ 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)
|
||||
func (c *DjswController) handleMsg(isNeedDecode bool, handler func(*jdapi.API, interface{}) *jdapi.CallbackResponse) (callbackResponse *jdapi.CallbackResponse) {
|
||||
callbackMsg, mapData, callbackResponse := jdapi.GetCallbackMsg2(getUsefulRequest(c.Ctx))
|
||||
globals.SugarLogger.Debug(utils.Format4Output(callbackMsg, true))
|
||||
if callbackResponse == nil {
|
||||
if jdAPI := jd.GetAPIByToken(token); jdAPI != nil {
|
||||
callbackResponse = handler(jdAPI, values, msgURL)
|
||||
if jdAPI := jd.GetAPIByAppKey(callbackMsg.AppKey); jdAPI != nil {
|
||||
if callbackResponse = jdAPI.CheckCallbackValidation2(mapData, callbackMsg.Sign); callbackResponse == nil {
|
||||
callbackResponse = handler(jdAPI, callbackMsg.Param)
|
||||
}
|
||||
} else {
|
||||
callbackResponse = jdapi.Err2CallbackResponse(fmt.Errorf("没有匹配的token,非法请求"), "")
|
||||
callbackResponse = jdapi.Err2CallbackResponse(fmt.Errorf("没有匹配的appKey,非法请求"), "")
|
||||
}
|
||||
}
|
||||
return callbackResponse
|
||||
@@ -34,11 +36,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)
|
||||
@@ -90,11 +89,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)
|
||||
@@ -120,11 +116,7 @@ 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)
|
||||
@@ -136,11 +128,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)
|
||||
@@ -152,11 +141,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