transfer_middleware/cmd/rpc/internal/logic/po/zltx/zltxOrder.go

125 lines
3.0 KiB
Go
Raw Normal View History

2024-06-07 11:11:04 +08:00
package zltx
import (
"encoding/json"
"fmt"
"trasfer_middleware/cmd/rpc/internal/logic/po/zltx/types"
"trasfer_middleware/cmd/rpc/internal/logic/vo"
"trasfer_middleware/cmd/rpc/pb/transfer"
"trasfer_middleware/pkg/request"
)
type ZltxOrder struct {
Conf *types.ZLTXConf
RequestBody map[string]string
}
type ZltxOrderRequest struct {
*ZltxOrder
RequestBody map[string]string
}
func NewZltxOrder(conf types.ZLTXConf) *ZltxOrder {
return &ZltxOrder{
Conf: &conf,
}
}
func (r *ZltxOrder) SetData(data map[string]interface{}) *ZltxOrderRequest {
/*data["timeStamp"] = time.Now().Unix()
2024-06-07 11:11:04 +08:00
a := data
delete(a, "extendParameter")
delete(a, "sign")
data["sign"] = common.ZltxSign(a, "8db16e8cc8363ed4eb4c14f9520bcc32")*/
2024-06-07 11:11:04 +08:00
//data := common.MergeMaps(common.ToMap(p), common.ToMap(r), common.ToMap(e))*/
requestBody := make(map[string]string, len(data))
for key, value := range data {
requestBody[key] = fmt.Sprintf("%v", value)
}
return &ZltxOrderRequest{
ZltxOrder: r,
RequestBody: requestBody,
}
}
func (r *ZltxOrderRequest) request(url string) (*request.Response, error) {
req := request.Request{
Method: "POST",
Url: fmt.Sprintf("%s%s", r.Conf.Host, url),
Data: r.RequestBody,
}
resp, _ := req.Send()
return &resp, nil
}
func (r *ZltxOrderRequest) RechargeOrder() (*transfer.DefaultRes, error) {
var res transfer.DefaultRes
req, err := r.request(vo.ZLTX_RECHARGE)
if err != nil {
return nil, err
}
_ = json.Unmarshal([]byte(req.Text), &res)
return &res, nil
}
func (r *ZltxOrderRequest) RechargeQuery() (*transfer.ZltxOrderCardQueryRes, error) {
var res transfer.ZltxOrderCardQueryRes
req, err := r.request(vo.ZLTX_RECHARGE_QUERY)
if err != nil {
return nil, err
}
_ = json.Unmarshal([]byte(req.Text), &res)
return &res, nil
}
func (r *ZltxOrderRequest) CardOrder() (*transfer.DefaultRes, error) {
var res transfer.DefaultRes
req, err := r.request(vo.ZLTX_CARD)
if err != nil {
return nil, err
}
_ = json.Unmarshal([]byte(req.Text), &res)
return &res, nil
}
func (r *ZltxOrderRequest) CardQuery() (*transfer.ZltxOrderCardQueryRes, error) {
var res transfer.ZltxOrderCardQueryRes
req, err := r.request(vo.ZLTX_CARD_QUERY)
if err != nil {
return nil, err
}
_ = json.Unmarshal([]byte(req.Text), &res)
return &res, nil
}
func (r *ZltxOrderRequest) OrderSendSms() (*transfer.ZltxOrderSmsRes, error) {
var res transfer.ZltxOrderSmsRes
req, err := r.request(vo.ZLTX_CARD_ISSUE)
if err != nil {
return nil, err
}
_ = json.Unmarshal([]byte(req.Text), &res)
return &res, nil
}
func (r *ZltxOrderRequest) RechargeProduct() (*types.RechargeProductRes, error) {
var res types.RechargeProductRes
req, err := r.request(vo.ZLTX_RECHARGE_PRODUCT)
if err != nil {
return nil, err
}
_ = json.Unmarshal([]byte(req.Text), &res)
return &res, nil
}
func (r *ZltxOrderRequest) RechargeInfo() (*transfer.ZltxRechargeInfoRes, error) {
var res transfer.ZltxRechargeInfoRes
req, err := r.request(vo.ZLTX_RECHARGE_INFO)
if err != nil {
return nil, err
}
_ = json.Unmarshal([]byte(req.Text), &res)
return &res, nil
}