transfer_middleware/test/market/market_api.go

61 lines
1.7 KiB
Go
Raw Normal View History

2024-06-18 16:34:14 +08:00
package market
import (
"encoding/json"
"qteam/app/utils/encrypt"
"qteam/config"
"time"
)
func NewMarketClient(cfg config.MarketConfig) *MarketClient {
cfg.Sign = "-----BEGIN RSA PRIVATE KEY-----\n" + cfg.Sign + "\n-----END RSA PRIVATE KEY-----"
return &MarketClient{
cfg: cfg,
}
}
/*
MarketSend
券码生成接口
- 请求地址/openApi/v1/market/key/send
- 说明发券接口应支持使用同一流水号进行重复请求当调用该接口失败时 以使用同一流水号进行再次请求接口需要根据请求的流水号进行判断若无该流水 号的券码信息则新生成后返回若有该流水号的券码信息则直接返回该券码的信息
orderNo: 订单号
VoucherId: 制码批次号
MobileNo: 11 手机号可传空字符串
SendMsg: 是否发送短信2- 发送 1-不发送
*/
func (this *MarketClient) MarketSend(orderNo, VoucherId, MobileNo, SendMsg string) (res MarketResponse, err error) {
url := "/openApi/v1/market/key/send"
request := MarketSendRequest{
AppId: this.cfg.AppId,
ReqCode: this.cfg.ReqCode,
MemId: this.cfg.MemId,
PosId: this.cfg.PosId,
TimeTamp: time.Now().Format("20060102150405"),
VoucherId: VoucherId,
ReqSerialNo: orderNo,
VoucherNum: 1,
MobileNo: MobileNo,
SendMsg: SendMsg,
}
request.Sign, err = MakeRsaSign(this.cfg.Sign, request.toMap())
if err != nil {
return res, err
}
bytes, err := json.Marshal(request)
if err != nil {
return res, err
}
data, err := this.doPost(url, bytes)
if err != nil {
return res, err
}
err = json.Unmarshal(data, &res)
// 加密
res.Data.ShortUrl = encrypt.AesEncryptCBC([]byte(res.Data.ShortUrl), []byte(this.cfg.SecretKey))
return res, err
}