- 京东回调改用http.Request
This commit is contained in:
@@ -2,13 +2,20 @@ package jdapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
CallbackPrefix = "/djsw/"
|
||||
)
|
||||
|
||||
// 如下的常量其实都是京东回调消息的
|
||||
const (
|
||||
OrderStatusAddComment = "12001"
|
||||
@@ -78,7 +85,7 @@ type CallbackResponse struct {
|
||||
}
|
||||
|
||||
type CallbackOrderMsg struct {
|
||||
ID int `json:"-"` // 用于传递Jdorder的主键值,减少一次读库操作
|
||||
MsgURL string `json:"msgURL"`
|
||||
BillID string `json:"billId"`
|
||||
OutBillID string `json:"outBillId"`
|
||||
StatusID string `json:"statusId"`
|
||||
@@ -87,6 +94,7 @@ type CallbackOrderMsg struct {
|
||||
}
|
||||
|
||||
type CallbackDeliveryStatusMsg struct {
|
||||
MsgURL string `json:"msgURL"`
|
||||
OrderID string `json:"orderId"`
|
||||
DeliveryStatusTime string `json:"deliveryStatusTime"`
|
||||
DeliveryManNo string `json:"deliveryManNo"`
|
||||
@@ -119,6 +127,7 @@ const (
|
||||
)
|
||||
|
||||
type CallbackStoreStockMsg struct {
|
||||
MsgURL string `json:"msgURL"`
|
||||
StationNo string `json:"stationNo"`
|
||||
SkuId int64 `json:"skuId"`
|
||||
Have bool `json:"have"`
|
||||
@@ -166,7 +175,12 @@ func (a *API) CheckCallbackValidation(values url.Values) (callbackResponse *Call
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *API) getCommonOrderCallbackMsg(data []byte, msg interface{}, needDecode bool) (callbackResponse *CallbackResponse) {
|
||||
func (a *API) getCommonOrderCallbackMsg(request *http.Request, msg interface{}, needDecode bool) (callbackResponse *CallbackResponse) {
|
||||
data, err := ioutil.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
return Err2CallbackResponse(err, "")
|
||||
}
|
||||
baseapi.SugarLogger.Debug(string(data))
|
||||
result, err := utils.HTTPBody2Values(data, needDecode)
|
||||
if err != nil {
|
||||
return FormatErrorResponse
|
||||
@@ -183,28 +197,34 @@ func (a *API) getCommonOrderCallbackMsg(data []byte, msg interface{}, needDecode
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *API) GetOrderCallbackMsg(data []byte) (msg *CallbackOrderMsg, callbackResponse *CallbackResponse) {
|
||||
func (a *API) GetOrderCallbackMsg(request *http.Request) (msg *CallbackOrderMsg, callbackResponse *CallbackResponse) {
|
||||
msg = new(CallbackOrderMsg)
|
||||
callbackResponse = a.getCommonOrderCallbackMsg(data, msg, false)
|
||||
if callbackResponse = a.getCommonOrderCallbackMsg(request, msg, false); callbackResponse == nil {
|
||||
msg.MsgURL = getMsgURLFromRequest(request)
|
||||
}
|
||||
return msg, callbackResponse
|
||||
}
|
||||
|
||||
func (a *API) GetOrderApplyCancelCallbackMsg(data []byte) (msg *CallbackOrderMsg, callbackResponse *CallbackResponse) {
|
||||
func (a *API) GetOrderApplyCancelCallbackMsg(request *http.Request) (msg *CallbackOrderMsg, callbackResponse *CallbackResponse) {
|
||||
msg = new(CallbackOrderMsg)
|
||||
callbackResponse = a.getCommonOrderCallbackMsg(data, msg, true)
|
||||
if callbackResponse = a.getCommonOrderCallbackMsg(request, msg, true); callbackResponse == nil {
|
||||
msg.MsgURL = getMsgURLFromRequest(request)
|
||||
}
|
||||
return msg, callbackResponse
|
||||
}
|
||||
|
||||
func (a *API) GetOrderDeliveryCallbackMsg(data []byte) (msg *CallbackDeliveryStatusMsg, callbackResponse *CallbackResponse) {
|
||||
msg = new(CallbackDeliveryStatusMsg)
|
||||
callbackResponse = a.getCommonOrderCallbackMsg(data, msg, true)
|
||||
func (a *API) GetOrderDeliveryCallbackMsg(request *http.Request) (msg *CallbackDeliveryStatusMsg, callbackResponse *CallbackResponse) {
|
||||
if callbackResponse = a.getCommonOrderCallbackMsg(request, &msg, true); callbackResponse == nil {
|
||||
msg.MsgURL = getMsgURLFromRequest(request)
|
||||
}
|
||||
return msg, callbackResponse
|
||||
}
|
||||
|
||||
func (a *API) GetStoreStockCallbackMsg(data []byte) (msg *CallbackStoreStockMsg, callbackResponse *CallbackResponse) {
|
||||
func (a *API) GetStoreStockCallbackMsg(request *http.Request) (msg *CallbackStoreStockMsg, callbackResponse *CallbackResponse) {
|
||||
msg = new(CallbackStoreStockMsg)
|
||||
msg.MsgURL = getMsgURLFromRequest(request)
|
||||
var tmpMsg map[string]interface{}
|
||||
callbackResponse = a.getCommonOrderCallbackMsg(data, &tmpMsg, true)
|
||||
callbackResponse = a.getCommonOrderCallbackMsg(request, &tmpMsg, true)
|
||||
if callbackResponse == nil {
|
||||
msg.StationNo = utils.Interface2String(tmpMsg["stationNo"])
|
||||
msg.SkuId = utils.Str2Int64(utils.Interface2String(tmpMsg["skuId"]))
|
||||
@@ -212,12 +232,15 @@ func (a *API) GetStoreStockCallbackMsg(data []byte) (msg *CallbackStoreStockMsg,
|
||||
msg.OperPin = utils.Interface2String(tmpMsg["operPin"])
|
||||
msg.OperTime = utils.Str2Int64(utils.Interface2String(tmpMsg["operTime"]))
|
||||
msg.OperSource = int(utils.Str2Int64((utils.Interface2String(tmpMsg["operSource"]))))
|
||||
have := utils.Interface2String(tmpMsg["have"])
|
||||
if have == "true" {
|
||||
msg.Have = true
|
||||
} else {
|
||||
msg.Have = false
|
||||
}
|
||||
msg.Have = utils.Interface2String(tmpMsg["have"]) == "true"
|
||||
}
|
||||
return msg, callbackResponse
|
||||
}
|
||||
|
||||
func getMsgURLFromRequest(request *http.Request) (msgURL string) {
|
||||
index := strings.Index(request.URL.Path, CallbackPrefix)
|
||||
if index >= 0 {
|
||||
msgURL = request.URL.Path[index+len(CallbackPrefix):]
|
||||
}
|
||||
return msgURL
|
||||
}
|
||||
|
||||
@@ -78,9 +78,15 @@ type AfsServiceResponse struct {
|
||||
OrderType int `json:"orderType"`
|
||||
PickwareAddress string `json:"pickwareAddress"`
|
||||
|
||||
QuestionDesc string `json:"questionDesc"`
|
||||
QuestionPic string `json:"questionPic"`
|
||||
QuestionTypeCid int `json:"questionTypeCid"`
|
||||
QuestionDesc string `json:"questionDesc"`
|
||||
QuestionPic string `json:"questionPic"`
|
||||
QuestionTypeCid int `json:"questionTypeCid"`
|
||||
|
||||
ApplyDeal string `json:"applyDeal"`
|
||||
DeliveryState string `json:"deliveryState"`
|
||||
DeliveryMan string `json:"deliveryMan"`
|
||||
DeliveryMobile string `json:"deliveryMobile"`
|
||||
|
||||
StationID string `json:"stationId"`
|
||||
StationName string `json:"stationName"`
|
||||
StationNumOutSystem string `json:"stationNumOutSystem"`
|
||||
|
||||
Reference in New Issue
Block a user