60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package internal
|
||
|
||
import (
|
||
"codeup.aliyun.com/6552e56cc3b2728a4557fc18/plugin/proto"
|
||
"context"
|
||
"fmt"
|
||
"github.com/carlmjohnson/requests"
|
||
"plugins/zltx/internal/po"
|
||
)
|
||
|
||
const (
|
||
Tag = "zltx"
|
||
orderMethod = "/recharge/order"
|
||
queryMethod = "/recharge/query"
|
||
balanceMethod = "/recharge/info"
|
||
)
|
||
|
||
type ZltxService struct {
|
||
}
|
||
|
||
func (p *ZltxService) Order(ctx context.Context, request *proto.OrderRequest) (*proto.OrderResponse, error) {
|
||
uv, err := req(rechargeReq(request), request.Config.AppKey)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
var response po.OrderResp
|
||
err = requests.URL(request.Config.BaseUri + orderMethod).BodyForm(uv).ToJSON(&response).Fetch(ctx)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||
}
|
||
|
||
response.SetCodeStr()
|
||
if !response.CodeStr.IsRechargeSuccess() {
|
||
return nil, fmt.Errorf("请求错误,msg:" + response.Message)
|
||
}
|
||
|
||
return rechargeResp(response), nil
|
||
}
|
||
|
||
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
|
||
}
|
||
|
||
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
|
||
}
|