zltx
This commit is contained in:
parent
24291408f8
commit
7be38bbb63
|
@ -3,7 +3,7 @@ module plugins/zltx
|
|||
go 1.21
|
||||
|
||||
require (
|
||||
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701062026-8d942924410e
|
||||
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701070232-7c96c21e16ac
|
||||
github.com/carlmjohnson/requests v0.23.5
|
||||
github.com/go-playground/validator/v10 v10.22.0
|
||||
github.com/hashicorp/go-plugin v1.6.1
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701062026-8d942924410e h1:1X0dk1OR8Zhf9gjZHRKpY7d/iYqX7UqMPqy8q+GxmXM=
|
||||
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701062026-8d942924410e/go.mod h1:QdW8HjHYQN8LCkFAB9e4oh7HziePCYnDXnUaKtmb8iQ=
|
||||
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701065841-5ae68878836f h1:2lKd9fMxqG4caY2VO05WqS4kmlXG0aNNM9Z++4ntdT4=
|
||||
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701065841-5ae68878836f/go.mod h1:QdW8HjHYQN8LCkFAB9e4oh7HziePCYnDXnUaKtmb8iQ=
|
||||
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701070232-7c96c21e16ac h1:SY71ZgI7jKQyREHxfe9F0FvH3E4AICh0MLrFao6oCFk=
|
||||
codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin v0.0.0-20240701070232-7c96c21e16ac/go.mod h1:QdW8HjHYQN8LCkFAB9e4oh7HziePCYnDXnUaKtmb8iQ=
|
||||
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
||||
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
|
||||
github.com/carlmjohnson/requests v0.23.5 h1:NPANcAofwwSuC6SIMwlgmHry2V3pLrSqRiSBKYbNHHA=
|
||||
|
|
|
@ -11,6 +11,8 @@ type Req interface {
|
|||
}
|
||||
|
||||
var _ Req = (*OrderReq)(nil)
|
||||
var _ Req = (*QueryReq)(nil)
|
||||
var _ Req = (*Notify)(nil)
|
||||
|
||||
func (req *OrderReq) Validate() error {
|
||||
err := validator.New().Struct(req)
|
||||
|
@ -22,6 +24,26 @@ func (req *OrderReq) Validate() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (req *QueryReq) Validate() error {
|
||||
err := validator.New().Struct(req)
|
||||
if err != nil {
|
||||
for _, err = range err.(validator.ValidationErrors) {
|
||||
return fmt.Errorf("参数有误:" + err.Error())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (req *Notify) Validate() error {
|
||||
err := validator.New().Struct(req)
|
||||
if err != nil {
|
||||
for _, err = range err.(validator.ValidationErrors) {
|
||||
return fmt.Errorf("参数有误:" + err.Error())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Resp interface {
|
||||
SetCodeStr()
|
||||
}
|
||||
|
|
|
@ -38,21 +38,22 @@ func rechargeResp(resp po.OrderResp) *proto.OrderResponse {
|
|||
func queryReq(in *proto.QueryRequest) *po.QueryReq {
|
||||
return &po.QueryReq{
|
||||
MerchantId: in.Config.AppId,
|
||||
//OutTradeNo: in.OutTradeNumber,
|
||||
OutTradeNo: in.Order.OrderNo,
|
||||
TimeStamp: time.Now().Unix(),
|
||||
Version: "1.0",
|
||||
}
|
||||
}
|
||||
|
||||
func queryResp(resp po.QueryResp) *proto.QueryResponse {
|
||||
_, _ = json.Marshal(resp)
|
||||
data, _ := json.Marshal(resp)
|
||||
return &proto.QueryResponse{
|
||||
//OutTradeNumber: in.OutTradeNumber,
|
||||
//TradeNumber: "",
|
||||
//Status: resp.Status.GetOrderStatus(),
|
||||
//TradePrice: in.Product.Price,
|
||||
//Data: data,
|
||||
//Message: resp.Message,
|
||||
Result: &proto.Result{
|
||||
Status: resp.Status.GetOrderStatus(),
|
||||
OrderNo: "",
|
||||
TradeNo: "",
|
||||
Message: resp.Message,
|
||||
Data: data,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package internal
|
|||
import (
|
||||
"codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin/proto"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/carlmjohnson/requests"
|
||||
"plugins/zltx/internal/po"
|
||||
|
@ -39,13 +40,22 @@ func (p *ZltxService) Order(ctx context.Context, request *proto.OrderRequest) (*
|
|||
}
|
||||
|
||||
func (p *ZltxService) Query(ctx context.Context, request *proto.QueryRequest) (*proto.QueryResponse, error) {
|
||||
return &proto.QueryResponse{Result: &proto.Result{
|
||||
Status: 0,
|
||||
OrderNo: "111",
|
||||
TradeNo: "111",
|
||||
Message: "11111",
|
||||
Data: nil,
|
||||
}}, nil
|
||||
uv, err := req(queryReq(request), request.Config.AppKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var response po.QueryResp
|
||||
err = requests.URL(request.Config.BaseUri + queryMethod).BodyForm(uv).ToJSON(&response).Fetch(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||
}
|
||||
|
||||
if !response.Code.IsSuccess() {
|
||||
return nil, errors.New("请求错误,msg:" + response.Message)
|
||||
}
|
||||
|
||||
return queryResp(response), nil
|
||||
}
|
||||
|
||||
func (p *ZltxService) Notify(ctx context.Context, request *proto.NotifyRequest) (*proto.NotifyResponse, error) {
|
||||
|
|
Loading…
Reference in New Issue