This commit is contained in:
richboo111
2023-06-01 17:23:17 +08:00
5 changed files with 118 additions and 2 deletions

View File

@@ -70,7 +70,7 @@ func TestCancel(t *testing.T) {
//
func TestQueryOrderInfo(t *testing.T) {
dadaapi = New("dada154e2a41fd6cef3", "7f97d8f258b70b450f04e7ab274ed8f8", "6660", "http://callback.jxc4.com/dadadelivery/msg", true)
result, err := dadaapi.QueryOrderInfo("1100561003845430062")
result, err := dadaapi.QueryOrderInfo("1100568013516213472")
if err != nil {
t.Fatal(err)
}

View File

@@ -8,6 +8,7 @@ import (
"git.rosy.net.cn/jx-callback/globals"
"go.uber.org/zap"
"testing"
"time"
)
var (
@@ -105,5 +106,10 @@ func TestAaww(t *testing.T) {
}
func TestLen(t *testing.T) {
fmt.Println(len("ChJrc01wUGF5Lm9yZGVyVG9rZW4SUP-S69vDW6NXUdGJJzqMLVObb1kgoXHrLPA-DPFFatGblYLtl9RfSthO5gpYCYgqVvxssxqhTaEo7o_IMSFE3vaj_kCyB9VXrN6cUMzbR7I5GhKdjrmQJwdL5mBuRor3eHSGhfsiIM_Zx5g9T__A6TwjoclKptFlQTKaRvh5aIr_EAJvYYR0KAUwAQ"))
for {
time.Sleep(1 * time.Second)
a := time.Now().Unix()
fmt.Println("a====", a)
fmt.Println(a%3 == 0)
}
}

View File

@@ -145,3 +145,62 @@ func (a *API) GetRiderLatestPosition(sfOrderID string) (retVal *RiderLatestPosit
return nil, err
}
}
// 添加小费
func (a *API) AddTipFee(deliveryId string, fee int64) error {
param := &Addordergratuityfee{
DevId: a.devId,
OrderId: deliveryId,
PushTime: time.Now().Unix(),
GratuityFee: fee,
OrderType: 0,
ShopId: 0,
ShopType: 0,
serialNumber: "",
}
resp := a.HttpPostJson("addordergratuityfee", param)
if resp.HttpStatusCode != HttpStatusSuccessCode {
return errors.New("HTTP请求错误请检查重试")
}
if resp.BaseRetVal.ErrorCode != SuccessCode {
return fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
}
var retVal *AddordergratuityfeeResp
s, _ := json.Marshal(resp.BaseRetVal.Result)
if err := json.Unmarshal(s, &retVal); err == nil {
return nil
} else {
return err
}
}
// 获取运单小费
func (a *API) QueryTipFee(sfOrderId string) (int64, error) {
resp := a.HttpPostJson("getordergratuityfee", map[string]interface{}{
"dev_id": a.devId,
"order_id": sfOrderId,
"push_time": time.Now().Unix()},
)
if resp.HttpStatusCode != HttpStatusSuccessCode {
return 0, errors.New("HTTP请求错误请检查重试")
}
if resp.BaseRetVal.ErrorCode != SuccessCode {
return 0, fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
}
var retVal *QueryOrderTipFee
s, _ := json.Marshal(resp.BaseRetVal.Result)
if err := json.Unmarshal(s, &retVal); err == nil {
return retVal.TotalGratuityFee, nil
} else {
return 0, err
}
}
type QueryOrderTipFee struct {
SfOrderId string //顺丰订单号新版本V1.9+升级为JS开头的15位字符串类型, 老版本为int类型
ShopOrderId string //商家订单号
TotalGratuityFee int64 //该订单总的加小费金额
TotalGratuityTimes int64 //该订单总的加小费次数
GratuityFeeList interface{} // 加小费列表,未加则是空数组
PushTime string //推送时间
}

View File

@@ -496,3 +496,25 @@ type MultiPickupInfo struct {
}
//#endregion
// 添加小费请求参数
type Addordergratuityfee struct {
DevId int64 `json:"dev_id"` // 开发者ID
OrderId string `json:"order_id"` // 订单id
PushTime int64 `json:"push_time"` // 推送时间;秒级时间戳
GratuityFee int64 `json:"gratuity_fee"` // 订单小费单位分加小费最低不能少于100分
OrderType int64 `json:"order_type"` // 订单ID类型
ShopId int64 `json:"shop_id"` // 店铺id
ShopType int64 `json:"shop_type"` // 店铺ID类型
serialNumber string `json:"serial_number"` // 加小费传入的唯一标识,用来幂等处理
}
// 添加小费返回参数
type AddordergratuityfeeResp struct {
SfOrderId string `json:"sf_order_id"` // 顺丰订单号
ShopOrderId string `json:"shop_order_id"` // 商家订单号
GratuityFee int `json:"gratuity_fee"` // 本次加小费金额
TotalGratuityFee int `json:"total_gratuity_fee"` // 该订单总的加小费金额
PushTime string `json:"push_time"` // 推送时间
}

View File

@@ -128,3 +128,32 @@ type LiquidatedDamagesFee struct {
ReturnMsg string `json:"return_msg"` // 返回信息,如非空,为错误原因,如签名失败、参数格式校验错误
ReturnCode string `json:"return_code"` // 状态ok/fail表示成功
}
// 支付小费
func (a *API) AddTip(orderId, deliveryId string, tipFee int) error {
param := a.MakeUURequestHead()
param["order_code"] = deliveryId // 运单号
param["origin_id"] = orderId // 订单单号
param["onlinefee"] = tipFee // 小费金额
resp, err := a.AccessAPI(BaseURL, "payonlinefee.ashx", RequestPost, param)
if err != nil {
return err
}
var result *AddTipResult
if err := utils.Map2StructByJson(resp, result, false); err != nil {
return err
}
if result.ReturnCode != "ok" {
return fmt.Errorf(result.ReturnMsg)
}
return nil
}
type AddTipResult struct {
ReturnCode string `json:"return_code"` // 状态ok/fail表示成功
ReturnMsg string `json:"return_msg"` // 通知消息
AppID string `json:"appid"`
NonceStr string `json:"nonce_str"`
Sign string `json:"sign"`
}