diff --git a/upstream/hdh/hdh.go b/upstream/hdh/hdh.go index bdd1d71554991a173c97fc35ef0f5ea1f6ca7531..809d3b4e5ff5b85bb931fb337440036cc7d79ffe 100644 --- a/upstream/hdh/hdh.go +++ b/upstream/hdh/hdh.go @@ -3,9 +3,11 @@ package hdh //会订货 import ( "context" + "errors" "github.com/gogf/gf/crypto/gmd5" "github.com/gogf/gf/encoding/gjson" "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/net/ghttp" "github.com/gogf/gf/os/gtime" "github.com/gogf/gf/util/gconv" "time" @@ -54,3 +56,13 @@ func post(ctx context.Context, method string, req interface{}) (res string, err res = resp.ReadAllString() return } + +//检测回调sign +func CheckSign(r *ghttp.Request) (body string, err error) { + signStr := gconv.String(r.GetHeader("sign")) + body = r.GetBodyString() + if sign(body) != signStr { + err = errors.New("sign错误") + } + return +} diff --git a/upstream/hdh/hdh_goods.go b/upstream/hdh/hdh_goods.go index d4ceb10d0d1d82de3b60c1618b997e1196bddbdd..033c00e66ee77253043fc76b3bc4f0d8445f42b0 100644 --- a/upstream/hdh/hdh_goods.go +++ b/upstream/hdh/hdh_goods.go @@ -3,6 +3,7 @@ package hdh import ( "context" "encoding/json" + "github.com/gogf/gf/net/ghttp" ) type GoodsNotifyRes struct { @@ -224,3 +225,13 @@ func GetGoodsInfo(ctx context.Context, req *GoodsInfoReq) (res *GoodsInfoRes, er err = json.Unmarshal([]byte(result), &res) return } + +//商å“回调 +func GoodsCallBack(r *ghttp.Request) (res *GoodsNotifyRes, err error) { + body, err := CheckSign(r) + if nil != err { + return + } + err = json.Unmarshal([]byte(body), &res) + return +} diff --git a/upstream/hdh/hdh_order.go b/upstream/hdh/hdh_order.go index 7a6b187595045ae45eab01c6e12782688da50625..95607bf66a6da2d4dcd2bfddd75b225923d9c541 100644 --- a/upstream/hdh/hdh_order.go +++ b/upstream/hdh/hdh_order.go @@ -3,6 +3,7 @@ package hdh import ( "context" "encoding/json" + "github.com/gogf/gf/net/ghttp" ) type OerCreateReq struct { @@ -63,27 +64,6 @@ type PkgList struct { PkgNo string `json:"pkgNo"` //åŒ…è£¹å· } -//物æµè½¨è¿¹å›žè°ƒæŽ¥å£ -type ExpressNotifyRes struct { - OrderNum string `json:"orderNum"` //订å•å· - PkgList []struct { - ExpressCode int `json:"expressCode"` //物æµçжæ€code - ExpressList []struct { - ExpressCompany string `json:"expressCompany"` //物æµå…¬å¸ - ExpressDetail []struct { - Express string `json:"express"` //物æµèŠ‚ç‚¹ - Time string `json:"time"` //æ—¶é—´ - } `json:"expressDetail"` //物æµè¯¦æƒ… - ExpressNum string `json:"expressNum"` //物æµå•å· - } `json:"expressList"` //物æµè½¨è¿¹ä¿¡æ¯ - OrderStatus string `json:"orderStatus"` //å订å•çŠ¶æ€ - OrderStatusCode int `json:"orderStatusCode"` //订å•状æ€codeå‚考订å•状æ€å—å…¸ - PkgNo string `json:"pkgNo"` //包裹å·(一笔订å•å¯èƒ½è¢«æ‹†åˆ†ä¸ºå¤šä¸ªåŒ…裹) - Status string `json:"status"` //包裹物æµè½¨è¿¹çŠ¶æ€ å‚考物æµçжæ€å—å…¸ - } `json:"pkgList"` //åŒ…è£¹ä¿¡æ¯ - UserOrderNum string `json:"userOrderNum"` //用户订å•å· -} - //åˆ›å»ºè®¢å• func OrderCreate(ctx context.Context, req *OerCreateReq) (res *OerCreateRes, err error) { @@ -94,3 +74,13 @@ func OrderCreate(ctx context.Context, req *OerCreateReq) (res *OerCreateRes, err err = json.Unmarshal([]byte(result), &res) return } + +//订å•回调 +func OrderCallBack(r *ghttp.Request) (res *OrderNotifyRes, err error) { + body, err := CheckSign(r) + if nil != err { + return + } + err = json.Unmarshal([]byte(body), &res) + return +} diff --git a/upstream/hdh/hdh_order_express.go b/upstream/hdh/hdh_order_express.go new file mode 100644 index 0000000000000000000000000000000000000000..ec69a7f097182cc34eec0f82fc7f6db9605af472 --- /dev/null +++ b/upstream/hdh/hdh_order_express.go @@ -0,0 +1,79 @@ +package hdh + +import ( + "context" + "encoding/json" + "github.com/gogf/gf/net/ghttp" +) + +//物æµè½¨è¿¹å›žè°ƒæŽ¥å£ +type ExpressNotifyRes struct { + OrderNum string `json:"orderNum"` //订å•å· + PkgList []struct { + ExpressCode int `json:"expressCode"` //物æµçжæ€code + ExpressList []struct { + ExpressCompany string `json:"expressCompany"` //物æµå…¬å¸ + ExpressDetail []struct { + Express string `json:"express"` //物æµèŠ‚ç‚¹ + Time string `json:"time"` //æ—¶é—´ + } `json:"expressDetail"` //物æµè¯¦æƒ… + ExpressNum string `json:"expressNum"` //物æµå•å· + } `json:"expressList"` //物æµè½¨è¿¹ä¿¡æ¯ + OrderStatus string `json:"orderStatus"` //å订å•çŠ¶æ€ + OrderStatusCode int `json:"orderStatusCode"` //订å•状æ€codeå‚考订å•状æ€å—å…¸ + PkgNo string `json:"pkgNo"` //包裹å·(一笔订å•å¯èƒ½è¢«æ‹†åˆ†ä¸ºå¤šä¸ªåŒ…裹) + Status string `json:"status"` //包裹物æµè½¨è¿¹çŠ¶æ€ å‚考物æµçжæ€å—å…¸ + } `json:"pkgList"` //åŒ…è£¹ä¿¡æ¯ + UserOrderNum string `json:"userOrderNum"` //用户订å•å· +} + +//物æµä¿¡æ¯æŸ¥è¯¢è¯·æ±‚ +type ExpressQueryReq struct { + AppID string `json:"appId"` + OrderNum string `json:"orderNum"` +} + +//物æµä¿¡æ¯æŸ¥è¯¢è¿”回 +type ExpressQueryRes struct { + Code string `json:"code"` + Data []struct { + ExpressCode int `json:"expressCode"` + ExpressList []struct { + ExpressDetail []interface{} `json:"expressDetail"` + } `json:"expressList"` + ItemList []struct { + ChannelName string `json:"channelName"` + ChannelType string `json:"channelType"` + ItemId string `json:"itemId"` + Number int `json:"number"` + SkuId string `json:"skuId"` + } `json:"itemList"` + OrderStatus string `json:"orderStatus"` + OrderStatusCode int `json:"orderStatusCode"` + PkgNo string `json:"pkgNo"` + Status string `json:"status"` + } `json:"data"` + Message string `json:"message"` + Success int `json:"success"` +} + +//物æµä¿¡æ¯æŸ¥è¯¢ +func ExpressQuery(ctx context.Context, req *ExpressQueryReq) (res *ExpressQueryRes, err error) { + + result, err := post(ctx, "/track/query_track.do", req) + if nil != err { + return + } + err = json.Unmarshal([]byte(result), &res) + return +} + +//物æµä¿¡æ¯å›žè°ƒ +func ExpressNotify(r *ghttp.Request) (res *ExpressNotifyRes, err error) { + body, err := CheckSign(r) + if nil != err { + return + } + err = json.Unmarshal([]byte(body), &res) + return +}