plugin 云闪付,下单查询
This commit is contained in:
parent
aa2d29032f
commit
fc0680609e
|
@ -1,11 +1,8 @@
|
|||
package po
|
||||
|
||||
import "plugins/union_pay/internal/vo"
|
||||
|
||||
type Notify struct {
|
||||
MerchantId int `json:"merchantId" validate:"required"`
|
||||
OutTradeNo string `json:"outTradeNo" validate:"required"`
|
||||
RechargeAccount string `json:"rechargeAccount" validate:"required"`
|
||||
Status vo.OrderStatus `json:"status" validate:"required"`
|
||||
Sign string `json:"sign" validate:"required"`
|
||||
}
|
||||
|
|
|
@ -34,5 +34,5 @@ type OrderResp struct {
|
|||
}
|
||||
|
||||
func (o *OrderResp) GetMsg() string {
|
||||
return fmt.Sprintf("Msg:%s,SubMsg:%s,自定处理msg:%s", o.Msg, o.SubMsg, o.SubCode.GetMsg())
|
||||
return fmt.Sprintf("Msg:[%s],SubMsg:[%s],自定处理msg:[%s]", o.Msg, o.SubMsg, o.SubCode.GetMsg())
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ func (req *QueryReq) Validate() error {
|
|||
}
|
||||
|
||||
func (req *QueryReq) GetReId() string {
|
||||
return ""
|
||||
return req.TraceId
|
||||
}
|
||||
|
||||
func (req *QueryReq) ToJson() []byte {
|
||||
|
|
|
@ -1,18 +1,29 @@
|
|||
package po
|
||||
|
||||
import "plugins/union_pay/internal/vo"
|
||||
import (
|
||||
"fmt"
|
||||
"plugins/union_pay/internal/vo"
|
||||
)
|
||||
|
||||
type QueryReq struct {
|
||||
MerchantId string `validate:"required"`
|
||||
OutTradeNo string `validate:"required"`
|
||||
TimeStamp int64 `validate:"required"`
|
||||
Version string `validate:"required"`
|
||||
Sign string
|
||||
ChNlId string `validate:"required" json:"chnlId"` // 渠道方代码-必填
|
||||
Cmd string `validate:"required" json:"cmd"`
|
||||
OrigQid string `validate:"required" json:"origQid"`
|
||||
OrigDate string `validate:"required" json:"origDate"`
|
||||
TraceId string `validate:"required" json:"traceId"`
|
||||
}
|
||||
|
||||
type QueryResp struct {
|
||||
Code vo.Code `json:"code"`
|
||||
Status vo.OrderStatus `json:"status"`
|
||||
Message string `json:"message"`
|
||||
OutTradeNo string `json:"outTradeNo"`
|
||||
Msg string `json:"msg"`
|
||||
SubCode vo.SubCode `json:"subCode"`
|
||||
SubMsg string `json:"subMsg"`
|
||||
OperaSt vo.OperaSt `json:"operaSt"`
|
||||
CouponCd string `json:"couponCd"`
|
||||
CouponBeginTs string `json:"couponBeginTs"`
|
||||
CouponEndTs string `json:"couponEndTs"`
|
||||
}
|
||||
|
||||
func (o *QueryResp) GetMsg() string {
|
||||
return fmt.Sprintf("Msg:[%s],SubMsg:[%s],自定处理msg:[%s]", o.Msg, o.SubMsg, o.SubCode.GetMsg())
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ type ConfigExtra struct {
|
|||
RsaNpk string `json:"rsa_npk"` // 回调公钥
|
||||
}
|
||||
|
||||
func transformConfig(config *proto.Config) (*Config, error) {
|
||||
func transConfig(config *proto.Config) (*Config, error) {
|
||||
var extra ConfigExtra
|
||||
err := json.Unmarshal(config.Extra, &extra)
|
||||
if err != nil {
|
||||
|
@ -31,11 +31,11 @@ func transformConfig(config *proto.Config) (*Config, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func rechargeReq(in *proto.OrderRequest, chNlId string) *po.OrderReq {
|
||||
type Extra struct {
|
||||
func orderReq(in *proto.OrderRequest, chNlId string) *po.OrderReq {
|
||||
type OrderExtra struct {
|
||||
OrderDt string `json:"orderDt"`
|
||||
}
|
||||
var e Extra
|
||||
var e OrderExtra
|
||||
_ = json.Unmarshal(in.Order.Extra, &e)
|
||||
|
||||
return &po.OrderReq{
|
||||
|
@ -53,7 +53,7 @@ func rechargeReq(in *proto.OrderRequest, chNlId string) *po.OrderReq {
|
|||
}
|
||||
}
|
||||
|
||||
func rechargeResp(request *proto.OrderRequest, resp po.OrderResp) *proto.OrderResponse {
|
||||
func orderResp(request *proto.OrderRequest, resp po.OrderResp) *proto.OrderResponse {
|
||||
data, _ := json.Marshal(resp)
|
||||
result := &proto.Result{
|
||||
OrderNo: request.Order.OrderNo,
|
||||
|
@ -69,3 +69,30 @@ func rechargeResp(request *proto.OrderRequest, resp po.OrderResp) *proto.OrderRe
|
|||
}
|
||||
return &proto.OrderResponse{Result: result}
|
||||
}
|
||||
|
||||
func queryReq(in *proto.QueryRequest, chNlId string) *po.QueryReq {
|
||||
type OrderExtra struct {
|
||||
OrigDate string `json:"origDate"`
|
||||
}
|
||||
var e OrderExtra
|
||||
_ = json.Unmarshal(in.Order.Extra, &e)
|
||||
return &po.QueryReq{
|
||||
ChNlId: chNlId,
|
||||
Cmd: "couponAcqQuery",
|
||||
OrigQid: in.Order.OrderNo,
|
||||
OrigDate: e.OrigDate,
|
||||
TraceId: in.Order.OrderNo,
|
||||
}
|
||||
}
|
||||
|
||||
func queryResp(request *proto.QueryRequest, resp po.QueryResp) *proto.QueryResponse {
|
||||
data, _ := json.Marshal(resp)
|
||||
result := &proto.Result{
|
||||
OrderNo: request.Order.OrderNo,
|
||||
TradeNo: resp.CouponCd,
|
||||
Status: resp.OperaSt.GetOrderStatus(),
|
||||
Message: resp.GetMsg(),
|
||||
Data: data,
|
||||
}
|
||||
return &proto.QueryResponse{Result: result}
|
||||
}
|
||||
|
|
|
@ -29,12 +29,14 @@ const (
|
|||
type UnionPayService struct{}
|
||||
|
||||
func (p *UnionPayService) Order(ctx context.Context, request *proto.OrderRequest) (*proto.OrderResponse, error) {
|
||||
conf, err := transformConfig(request.Config)
|
||||
conf, err := transConfig(request.Config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uv := rechargeReq(request, conf.Extra.ChNlId)
|
||||
|
||||
uv := orderReq(request, conf.Extra.ChNlId)
|
||||
if err = uv.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response po.OrderResp
|
||||
url := fmt.Sprintf("%s%s", request.Config.BaseUri, orderMethod)
|
||||
err = requests.URL(url).Headers(headers(conf, uv, orderBizMethod)).BodyJSON(uv).ToJSON(&response).Fetch(ctx)
|
||||
|
@ -42,11 +44,26 @@ func (p *UnionPayService) Order(ctx context.Context, request *proto.OrderRequest
|
|||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||
}
|
||||
|
||||
return rechargeResp(request, response), nil
|
||||
return orderResp(request, response), nil
|
||||
}
|
||||
|
||||
func (p *UnionPayService) Query(ctx context.Context, request *proto.QueryRequest) (*proto.QueryResponse, error) {
|
||||
return nil, nil
|
||||
conf, err := transConfig(request.Config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uv := queryReq(request, conf.Extra.ChNlId)
|
||||
if err = uv.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response po.QueryResp
|
||||
url := fmt.Sprintf("%s%s", request.Config.BaseUri, queryMethod)
|
||||
err = requests.URL(url).Headers(headers(conf, uv, queryBizMethod)).BodyJSON(uv).ToJSON(&response).Fetch(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||
}
|
||||
|
||||
return queryResp(request, response), nil
|
||||
}
|
||||
|
||||
func (p *UnionPayService) Notify(_ context.Context, request *proto.NotifyRequest) (*proto.NotifyResponse, error) {
|
||||
|
|
|
@ -53,10 +53,10 @@ func TestQuery(t *testing.T) {
|
|||
request := &proto.QueryRequest{
|
||||
Config: config,
|
||||
Order: &proto.QueryRequest_Order{
|
||||
OrderNo: "test_zltx_4",
|
||||
OrderNo: "240403164049635931",
|
||||
TradeNo: "",
|
||||
Account: "",
|
||||
Extra: nil,
|
||||
Extra: []byte(`{"origDate":"20240704"}`),
|
||||
},
|
||||
}
|
||||
t.Run("TestQuery", func(t *testing.T) {
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package vo
|
||||
|
||||
import "codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin/proto"
|
||||
|
||||
// OperaSt 原操作状态;10表示原操作未被受理;00表示原操作成功;01表示原操作结果未明;其他表示原操作失败
|
||||
type OperaSt string
|
||||
|
||||
const (
|
||||
OperaStSuccess OperaSt = "00"
|
||||
OperaStNotAccepted OperaSt = "10"
|
||||
OperaStResultIsNotClear OperaSt = "01"
|
||||
)
|
||||
|
||||
var operaStMap = map[OperaSt]string{
|
||||
OperaStSuccess: "原操作成功",
|
||||
OperaStNotAccepted: "原操作未被受理",
|
||||
OperaStResultIsNotClear: "原操作结果未明",
|
||||
}
|
||||
|
||||
var queryOrderStatusMap = map[OperaSt]proto.Status{
|
||||
OperaStSuccess: proto.Status_SUCCESS,
|
||||
OperaStResultIsNotClear: proto.Status_ING,
|
||||
OperaStNotAccepted: proto.Status_INVALID,
|
||||
}
|
||||
|
||||
func (o OperaSt) GetText() string {
|
||||
msg, ok := operaStMap[o]
|
||||
if !ok {
|
||||
return "原操作失败"
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
func (o OperaSt) GetOrderStatus() proto.Status {
|
||||
if o == "" {
|
||||
return proto.Status_INVALID
|
||||
}
|
||||
if resultStatus, ok := queryOrderStatusMap[o]; ok {
|
||||
return resultStatus
|
||||
}
|
||||
return proto.Status_FAIL
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package vo
|
||||
|
||||
import (
|
||||
"codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin/proto"
|
||||
)
|
||||
|
||||
type OrderStatus string
|
||||
|
||||
const (
|
||||
OrderSuccess OrderStatus = "01" // 充值成功
|
||||
OrderPending OrderStatus = "02" // 充值处理中
|
||||
OrderFail OrderStatus = "03" // 充值失败
|
||||
OrderAbnormal OrderStatus = "04" // 充值异常,处理中
|
||||
)
|
||||
|
||||
var orderStatusMap = map[OrderStatus]proto.Status{
|
||||
OrderSuccess: proto.Status_SUCCESS,
|
||||
OrderPending: proto.Status_ING,
|
||||
OrderFail: proto.Status_FAIL,
|
||||
}
|
||||
|
||||
func (o OrderStatus) IsSuccess() bool {
|
||||
return o == OrderSuccess
|
||||
}
|
||||
|
||||
func (o OrderStatus) IsPending() bool {
|
||||
return o == OrderPending
|
||||
}
|
||||
|
||||
func (o OrderStatus) IsFail() bool {
|
||||
return o == OrderFail
|
||||
}
|
||||
|
||||
func (o OrderStatus) IsAbnormal() bool {
|
||||
return o == OrderAbnormal
|
||||
}
|
||||
|
||||
func (o OrderStatus) GetOrderStatus() proto.Status {
|
||||
if resultStatus, ok := orderStatusMap[o]; ok {
|
||||
return resultStatus
|
||||
}
|
||||
return proto.Status_ING
|
||||
}
|
|
@ -7,7 +7,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func rechargeReq(in *proto.OrderRequest) *po.OrderReq {
|
||||
func orderReq(in *proto.OrderRequest) *po.OrderReq {
|
||||
return &po.OrderReq{
|
||||
MerchantId: in.Config.AppId,
|
||||
OutTradeNo: in.Order.OrderNo,
|
||||
|
@ -21,7 +21,7 @@ func rechargeReq(in *proto.OrderRequest) *po.OrderReq {
|
|||
}
|
||||
}
|
||||
|
||||
func rechargeResp(request *proto.OrderRequest, resp po.OrderResp) *proto.OrderResponse {
|
||||
func orderResp(request *proto.OrderRequest, resp po.OrderResp) *proto.OrderResponse {
|
||||
data, _ := json.Marshal(resp)
|
||||
return &proto.OrderResponse{
|
||||
Result: &proto.Result{
|
||||
|
|
|
@ -26,7 +26,7 @@ const (
|
|||
type ZltxService struct{}
|
||||
|
||||
func (p *ZltxService) Order(ctx context.Context, request *proto.OrderRequest) (*proto.OrderResponse, error) {
|
||||
uv, err := req(rechargeReq(request), request.Config.AppKey)
|
||||
uv, err := req(orderReq(request), request.Config.AppKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ func (p *ZltxService) Order(ctx context.Context, request *proto.OrderRequest) (*
|
|||
return nil, fmt.Errorf("请求错误,msg:" + response.Message)
|
||||
}
|
||||
|
||||
return rechargeResp(request, response), nil
|
||||
return orderResp(request, response), nil
|
||||
}
|
||||
|
||||
func (p *ZltxService) Query(ctx context.Context, request *proto.QueryRequest) (*proto.QueryResponse, error) {
|
||||
|
|
Loading…
Reference in New Issue