zltx 回调

This commit is contained in:
李子铭 2024-07-01 15:40:23 +08:00
parent 7e7b69c5bf
commit feae7d4bd8
2 changed files with 26 additions and 22 deletions

View File

@ -3,7 +3,6 @@ package internal
import ( import (
"codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin/proto" "codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin/proto"
"encoding/json" "encoding/json"
"net/http"
"plugins/zltx/internal/po" "plugins/zltx/internal/po"
"time" "time"
) )
@ -58,15 +57,14 @@ func queryResp(request *proto.QueryRequest, resp po.QueryResp) *proto.QueryRespo
} }
func notifyResp(poReq po.Notify) *proto.NotifyResponse { func notifyResp(poReq po.Notify) *proto.NotifyResponse {
headers := make(http.Header) data, _ := json.Marshal(poReq)
headers.Add("content-type", "text/plain")
_, _ = json.Marshal(headers)
return &proto.NotifyResponse{ return &proto.NotifyResponse{
//Result: poReq.Status.IsSuccess(), Result: &proto.Result{
//Msg: "回调返回", Status: poReq.Status.GetOrderStatus(),
//Data: dto.NotifyResponseData{ OrderNo: poReq.OutTradeNo,
// Headers: h, TradeNo: "",
// Body: []byte("success"), Message: "",
//}, Data: data,
},
} }
} }

View File

@ -3,6 +3,7 @@ package internal
import ( import (
"codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin/proto" "codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin/proto"
"context" "context"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/carlmjohnson/requests" "github.com/carlmjohnson/requests"
@ -10,10 +11,9 @@ import (
) )
const ( const (
Tag = "zltx" Tag = "zltx"
orderMethod = "/recharge/order" orderMethod = "/recharge/order"
queryMethod = "/recharge/query" queryMethod = "/recharge/query"
balanceMethod = "/recharge/info"
) )
type ZltxService struct { type ZltxService struct {
@ -58,12 +58,18 @@ func (p *ZltxService) Query(ctx context.Context, request *proto.QueryRequest) (*
return queryResp(request, response), nil return queryResp(request, response), nil
} }
func (p *ZltxService) Notify(ctx context.Context, request *proto.NotifyRequest) (*proto.NotifyResponse, error) { func (p *ZltxService) Notify(_ context.Context, request *proto.NotifyRequest) (*proto.NotifyResponse, error) {
return &proto.NotifyResponse{Result: &proto.Result{ var poReq po.Notify
Status: 0, err := json.Unmarshal(request.Body, &poReq)
OrderNo: "11", if err != nil {
TradeNo: "112", return nil, fmt.Errorf("解析异常msg:" + err.Error())
Message: "111", }
Data: nil, err = poReq.Validate()
}}, nil if err != nil {
return nil, err
}
if !verify(poReq, request.Config.AppKey) {
return nil, errors.New("验签不通过")
}
return notifyResp(poReq), nil
} }