mtps校验签名?
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
package mtps
|
package mtps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha1"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -115,7 +118,7 @@ func (c *DeliveryHandler) pushToGy(waybill *model.Waybill, msg *mtpsapi.Callback
|
|||||||
params["mt_peisong_id"] = msg.MtPeisongID
|
params["mt_peisong_id"] = msg.MtPeisongID
|
||||||
params["courier_name"] = msg.CourierName
|
params["courier_name"] = msg.CourierName
|
||||||
params["delivery_id"] = msg.DeliveryID
|
params["delivery_id"] = msg.DeliveryID
|
||||||
params["sign"] = "ec61c8d88a1f864cc2cb1b875177fe1fb1402f05"
|
// params["sign"] = "ec61c8d88a1f864cc2cb1b875177fe1fb1402f05"
|
||||||
params["appkey"] = msg.AppKey
|
params["appkey"] = msg.AppKey
|
||||||
params["order_id"] = msg.OrderID
|
params["order_id"] = msg.OrderID
|
||||||
params["courier_phone"] = msg.CourierPhone
|
params["courier_phone"] = msg.CourierPhone
|
||||||
@@ -123,6 +126,9 @@ func (c *DeliveryHandler) pushToGy(waybill *model.Waybill, msg *mtpsapi.Callback
|
|||||||
params["timestamp"] = msg.Timestamp
|
params["timestamp"] = msg.Timestamp
|
||||||
params["cancel_reason_id"] = msg.CancelReasonId
|
params["cancel_reason_id"] = msg.CancelReasonId
|
||||||
params["cancel_reason"] = msg.CancelReason
|
params["cancel_reason"] = msg.CancelReason
|
||||||
|
urls := utils.Map2URLValues(params)
|
||||||
|
sign := signParams(urls)
|
||||||
|
params["sign"] = sign
|
||||||
request, err := http.NewRequest(http.MethodPost, "http://callback-jxgy.jxc4.com/mtps/status", strings.NewReader(utils.Map2URLValues(params).Encode()))
|
request, err := http.NewRequest(http.MethodPost, "http://callback-jxgy.jxc4.com/mtps/status", strings.NewReader(utils.Map2URLValues(params).Encode()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -132,6 +138,27 @@ func (c *DeliveryHandler) pushToGy(waybill *model.Waybill, msg *mtpsapi.Callback
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func signParams(params url.Values) string {
|
||||||
|
keys := make([]string, 0)
|
||||||
|
for k := range params {
|
||||||
|
if k != "sign" {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(keys)
|
||||||
|
finalStr := "b1M}9?:sTbsB[OF2gNORnN(|(iy9rB8(`7]|[wGLnbmt`evfM>E:A90DjHAW:UPE"
|
||||||
|
for _, key := range keys {
|
||||||
|
valStr := strings.Join(params[key], "")
|
||||||
|
if valStr != "" {
|
||||||
|
finalStr += key + valStr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// baseapi.SugarLogger.Debug(finalStr)
|
||||||
|
return fmt.Sprintf("%x", sha1.Sum([]byte(finalStr)))
|
||||||
|
}
|
||||||
|
|
||||||
func (c *DeliveryHandler) callbackMsg2Waybill(msg *mtpsapi.CallbackOrderMsg) (retVal *model.Waybill) {
|
func (c *DeliveryHandler) callbackMsg2Waybill(msg *mtpsapi.CallbackOrderMsg) (retVal *model.Waybill) {
|
||||||
retVal = &model.Waybill{
|
retVal = &model.Waybill{
|
||||||
VendorWaybillID: msg.MtPeisongID,
|
VendorWaybillID: msg.MtPeisongID,
|
||||||
|
|||||||
Reference in New Issue
Block a user