1
This commit is contained in:
@@ -19,6 +19,35 @@ const (
|
||||
OrderPayStatusFailed = "FAILED" // 订单支付失败
|
||||
)
|
||||
|
||||
type T struct {
|
||||
Data struct {
|
||||
KsOrderNo string `json:"ks_order_no"`
|
||||
RefundType interface{} `json:"refund_type"`
|
||||
OutRefundNo interface{} `json:"out_refund_no"`
|
||||
KsSettleNo interface{} `json:"ks_settle_no"`
|
||||
Channel string `json:"channel"`
|
||||
OutOrderNo string `json:"out_order_no"`
|
||||
KsRefundFailReason interface{} `json:"ks_refund_fail_reason"`
|
||||
ApplyRefundReason interface{} `json:"apply_refund_reason"`
|
||||
PromotionAmount int `json:"promotion_amount"`
|
||||
DeveloperPromotionAmount int `json:"developer_promotion_amount"`
|
||||
ExtraInfo string `json:"extra_info"`
|
||||
SettleAmount interface{} `json:"settle_amount"`
|
||||
OrderAmount int `json:"order_amount"`
|
||||
EnablePromotion bool `json:"enable_promotion"`
|
||||
OutSettleNo interface{} `json:"out_settle_no"`
|
||||
RefundAmount interface{} `json:"refund_amount"`
|
||||
TradeNo string `json:"trade_no"`
|
||||
Attach string `json:"attach"`
|
||||
KsRefundNo interface{} `json:"ks_refund_no"`
|
||||
Status string `json:"status"`
|
||||
} `json:"data"`
|
||||
BizType string `json:"biz_type"`
|
||||
MessageId string `json:"message_id"`
|
||||
AppId string `json:"app_id"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
// KauiShouCallback 回调处理
|
||||
func (a *API) KauiShouCallback(request *http.Request) (*CallBackDetail, *RefundCallBack, string, string, error) {
|
||||
data, err := ioutil.ReadAll(request.Body)
|
||||
@@ -35,32 +64,20 @@ func (a *API) KauiShouCallback(request *http.Request) (*CallBackDetail, *RefundC
|
||||
switch callback.BizType {
|
||||
case CallbackTypePay:
|
||||
var payCallback *CallBackDetail
|
||||
if value, ok := callback.Data.(string); ok {
|
||||
if err := json.Unmarshal([]byte(value), &payCallback); err != nil {
|
||||
globals.SugarLogger.Debugf("err2 =========== :%s", utils.Format4Output(err, false))
|
||||
return nil, nil, "", callback.MessageId, err
|
||||
}
|
||||
} else {
|
||||
if err := json.Unmarshal([]byte(utils.Interface2String(value)), &payCallback); err != nil {
|
||||
globals.SugarLogger.Debugf("err3 =========== :%s", utils.Format4Output(err, false))
|
||||
return nil, nil, "", callback.MessageId, err
|
||||
}
|
||||
globals.SugarLogger.Debugf("payCallback : %s", utils.Format4Output(callback.Data, false))
|
||||
if err := utils.Map2StructByJson(callback.Data, &payCallback, false); err != nil {
|
||||
globals.SugarLogger.Debugf("err3 =========== :%s", utils.Format4Output(err, false))
|
||||
return nil, nil, "", callback.MessageId, err
|
||||
}
|
||||
return payCallback, nil, CallbackTypePay, callback.MessageId, err
|
||||
return payCallback, nil, CallbackTypePay, callback.MessageId, nil
|
||||
case CallbackTypeRefund:
|
||||
var refundCallback *RefundCallBack
|
||||
if value, ok := callback.Data.(string); ok {
|
||||
if err := json.Unmarshal([]byte(value), &refundCallback); err != nil {
|
||||
globals.SugarLogger.Debugf("err4 =========== :%s", utils.Format4Output(err, false))
|
||||
return nil, nil, "", callback.MessageId, err
|
||||
}
|
||||
} else {
|
||||
if err := json.Unmarshal([]byte(utils.Interface2String(value)), &refundCallback); err != nil {
|
||||
globals.SugarLogger.Debugf("err5 =========== :%s", utils.Format4Output(err, false))
|
||||
return nil, nil, "", callback.MessageId, err
|
||||
}
|
||||
globals.SugarLogger.Debugf("payCallback : %s", utils.Format4Output(callback.Data, false))
|
||||
if err := utils.Map2StructByJson(callback.Data, &refundCallback, false); err != nil {
|
||||
globals.SugarLogger.Debugf("err5 =========== :%s", utils.Format4Output(err, false))
|
||||
return nil, nil, "", callback.MessageId, err
|
||||
}
|
||||
return nil, refundCallback, CallbackTypeRefund, callback.MessageId, err
|
||||
return nil, refundCallback, CallbackTypeRefund, callback.MessageId, nil
|
||||
case CallbackTypeSettle:
|
||||
return nil, nil, "", callback.MessageId, errors.New("无效回调类型")
|
||||
default:
|
||||
|
||||
@@ -84,17 +84,30 @@ type KauiShouCallbackRes struct {
|
||||
Timestamp int64 `json:"timestamp"` // 流程变动的时间戳
|
||||
}
|
||||
|
||||
type T2 struct {
|
||||
}
|
||||
|
||||
type CallBackDetail struct {
|
||||
Channel string `json:"channel"` // 支付渠道。取值:UNKNOWN - 未知|WECHAT-微信|ALIPAY-支付宝
|
||||
OutOrderNo string `json:"out_order_no"` // 商户系统内部订单号
|
||||
Attach string `json:"attach"` // 预下单时携带的开发者自定义信息
|
||||
Status string `json:"status"` // 订单支付状态。 取值: PROCESSING-处理中|SUCCESS-成功|FAILED-失败
|
||||
KsOrderNo string `json:"ks_order_no"` // 快手小程序平台订单号
|
||||
OrderAmount int `json:"order_amount"` // 订单金额
|
||||
TradeNo string `json:"trade_no"` // 用户侧支付页交易单号
|
||||
ExtraInfo string `json:"extra_info"` // 订单来源信息,同支付查询接口
|
||||
EnablePromotion bool `json:"enable_promotion"` // 是否参与分销,true:分销,false:非分销
|
||||
PromotionAmount int `json:"promotion_amount"` // 预计分销金额,单位:分
|
||||
Channel string `json:"channel"` // 支付渠道。取值:UNKNOWN - 未知|WECHAT-微信|ALIPAY-支付宝
|
||||
OutOrderNo string `json:"out_order_no"` // 商户系统内部订单号
|
||||
Attach string `json:"attach"` // 预下单时携带的开发者自定义信息
|
||||
Status string `json:"status"` // 订单支付状态。 取值: PROCESSING-处理中|SUCCESS-成功|FAILED-失败
|
||||
KsOrderNo string `json:"ks_order_no"` // 快手小程序平台订单号
|
||||
OrderAmount int `json:"order_amount"` // 订单金额
|
||||
TradeNo string `json:"trade_no"` // 用户侧支付页交易单号
|
||||
ExtraInfo string `json:"extra_info"` // 订单来源信息,同支付查询接口
|
||||
EnablePromotion bool `json:"enable_promotion"` // 是否参与分销,true:分销,false:非分销
|
||||
PromotionAmount int `json:"promotion_amount"` // 预计分销金额,单位:分
|
||||
ApplyRefundReason interface{} `json:"apply_refund_reason"`
|
||||
DeveloperPromotionAmount int `json:"developer_promotion_amount"`
|
||||
KsRefundFailReason interface{} `json:"ks_refund_fail_reason"`
|
||||
KsRefundNo interface{} `json:"ks_refund_no"`
|
||||
KsSettleNo interface{} `json:"ks_settle_no"`
|
||||
OutRefundNo interface{} `json:"out_refund_no"`
|
||||
OutSettleNo interface{} `json:"out_settle_no"`
|
||||
RefundAmount interface{} `json:"refund_amount"`
|
||||
RefundType interface{} `json:"refund_type"`
|
||||
SettleAmount interface{} `json:"settle_amount"`
|
||||
}
|
||||
|
||||
// RefundParam 申请退单参数
|
||||
|
||||
@@ -2,13 +2,14 @@ package kuaishou_mini
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"go.uber.org/zap"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -106,10 +107,36 @@ func TestAaww(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLen(t *testing.T) {
|
||||
for {
|
||||
time.Sleep(1 * time.Second)
|
||||
a := time.Now().Unix()
|
||||
fmt.Println("a====", a)
|
||||
fmt.Println(a%3 == 0)
|
||||
data := `{"data":{"ks_order_no":"123060711428646148797","refund_type":null,"out_refund_no":null,"ks_settle_no":null,"channel":"WECHAT","out_order_no":"88423854448004","ks_refund_fail_reason":null,"apply_refund_reason":null,"promotion_amount":0,"developer_promotion_amount":0,"extra_info":"{\"url\":\"\",\"provider\":\"\",\"item_type\":\"UNKNOWN\",\"item_id\":\"\",\"author_id\":\"\",\"refer_id\":\"\",\"channel_mark\":\"\",\"provider_type\":\"\",\"trade_no\":\"4307400963202306073218531739\"}","settle_amount":null,"order_amount":2,"enable_promotion":false,"out_settle_no":null,"refund_amount":null,"trade_no":"4307400963202306073218531739","attach":"","ks_refund_no":null,"status":"SUCCESS"},"biz_type":"PAYMENT","message_id":"65299d6d-072e-4804-8ef4-23451024a0d9","app_id":"ks680887971696897880","timestamp":1686129660709}`
|
||||
ACCC(data)
|
||||
}
|
||||
|
||||
func ACCC(data string) (*CallBackDetail, *RefundCallBack, string, string, error) {
|
||||
globals.SugarLogger.Debugf("data================: %s", string(data))
|
||||
var callback *KauiShouCallbackRes
|
||||
if err := json.Unmarshal([]byte(data), &callback); err != nil {
|
||||
return nil, nil, "", "-1", err
|
||||
}
|
||||
|
||||
switch callback.BizType {
|
||||
case CallbackTypePay:
|
||||
var payCallback *CallBackDetail
|
||||
globals.SugarLogger.Debugf("payCallback : %s", utils.Format4Output(callback.Data, false))
|
||||
if err := utils.Map2StructByJson(callback.Data, &payCallback, false); err != nil {
|
||||
globals.SugarLogger.Debugf("err3 =========== :%s", utils.Format4Output(err, false))
|
||||
return nil, nil, "", callback.MessageId, err
|
||||
}
|
||||
return payCallback, nil, CallbackTypePay, callback.MessageId, nil
|
||||
case CallbackTypeRefund:
|
||||
var refundCallback *RefundCallBack
|
||||
if err := utils.Map2StructByJson(callback.Data, &refundCallback, false); err != nil {
|
||||
globals.SugarLogger.Debugf("err5 =========== :%s", utils.Format4Output(err, false))
|
||||
return nil, nil, "", callback.MessageId, err
|
||||
}
|
||||
return nil, refundCallback, CallbackTypeRefund, callback.MessageId, nil
|
||||
case CallbackTypeSettle:
|
||||
return nil, nil, "", callback.MessageId, errors.New("无效回调类型")
|
||||
default:
|
||||
return nil, nil, "", callback.MessageId, errors.New("无效回调类型")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user