zltx 回调
This commit is contained in:
parent
7e7b69c5bf
commit
feae7d4bd8
|
@ -3,7 +3,6 @@ package internal
|
|||
import (
|
||||
"codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin/proto"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"plugins/zltx/internal/po"
|
||||
"time"
|
||||
)
|
||||
|
@ -58,15 +57,14 @@ func queryResp(request *proto.QueryRequest, resp po.QueryResp) *proto.QueryRespo
|
|||
}
|
||||
|
||||
func notifyResp(poReq po.Notify) *proto.NotifyResponse {
|
||||
headers := make(http.Header)
|
||||
headers.Add("content-type", "text/plain")
|
||||
_, _ = json.Marshal(headers)
|
||||
data, _ := json.Marshal(poReq)
|
||||
return &proto.NotifyResponse{
|
||||
//Result: poReq.Status.IsSuccess(),
|
||||
//Msg: "回调返回",
|
||||
//Data: dto.NotifyResponseData{
|
||||
// Headers: h,
|
||||
// Body: []byte("success"),
|
||||
//},
|
||||
Result: &proto.Result{
|
||||
Status: poReq.Status.GetOrderStatus(),
|
||||
OrderNo: poReq.OutTradeNo,
|
||||
TradeNo: "",
|
||||
Message: "",
|
||||
Data: data,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package internal
|
|||
import (
|
||||
"codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin/proto"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/carlmjohnson/requests"
|
||||
|
@ -13,7 +14,6 @@ const (
|
|||
Tag = "zltx"
|
||||
orderMethod = "/recharge/order"
|
||||
queryMethod = "/recharge/query"
|
||||
balanceMethod = "/recharge/info"
|
||||
)
|
||||
|
||||
type ZltxService struct {
|
||||
|
@ -58,12 +58,18 @@ func (p *ZltxService) Query(ctx context.Context, request *proto.QueryRequest) (*
|
|||
return queryResp(request, response), nil
|
||||
}
|
||||
|
||||
func (p *ZltxService) Notify(ctx context.Context, request *proto.NotifyRequest) (*proto.NotifyResponse, error) {
|
||||
return &proto.NotifyResponse{Result: &proto.Result{
|
||||
Status: 0,
|
||||
OrderNo: "11",
|
||||
TradeNo: "112",
|
||||
Message: "111",
|
||||
Data: nil,
|
||||
}}, nil
|
||||
func (p *ZltxService) Notify(_ context.Context, request *proto.NotifyRequest) (*proto.NotifyResponse, error) {
|
||||
var poReq po.Notify
|
||||
err := json.Unmarshal(request.Body, &poReq)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("解析异常,msg:" + err.Error())
|
||||
}
|
||||
err = poReq.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !verify(poReq, request.Config.AppKey) {
|
||||
return nil, errors.New("验签不通过")
|
||||
}
|
||||
return notifyResp(poReq), nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue