富友支付支持
This commit is contained in:
92
pkg/fuiou/scan.go
Normal file
92
pkg/fuiou/scan.go
Normal file
@@ -0,0 +1,92 @@
|
||||
package fuiou
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// PreCreate 主扫统一下单(C扫B,生成用户扫码支付的二维码)。
|
||||
// orderType: 订单类型,WECHAT=微信主扫、ALIPAY=支付宝主扫。
|
||||
// reservedExpireMinute: 订单有效期分钟(reserved 字段,不参与签名)。
|
||||
func (c *Client) PreCreate(orderNo, amount, goodsDesc, termIP, orderType, reservedExpireMinute string) (*PreCreateResponse, error) {
|
||||
req := &PreCreateRequest{
|
||||
Version: "1.0",
|
||||
InsCd: c.InsCd,
|
||||
MchntCd: c.MchntCd,
|
||||
TermId: c.TermId,
|
||||
RandomStr: generateRandomStr(),
|
||||
OrderType: orderType,
|
||||
MchntOrderNo: orderNo,
|
||||
OrderAmt: amount,
|
||||
GoodsDesc: goodsDesc,
|
||||
TermIp: termIP,
|
||||
TxnBeginTs: time.Now().Format("20060102150405"),
|
||||
NotifyUrl: c.NotifyURL,
|
||||
ReservedExpireMinute: reservedExpireMinute,
|
||||
}
|
||||
|
||||
sign, err := c.Sign(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("签名失败: %w", err)
|
||||
}
|
||||
req.Sign = sign
|
||||
|
||||
var resp PreCreateResponse
|
||||
if err := c.DoRequest("/preCreate", req, &resp); err != nil {
|
||||
return nil, fmt.Errorf("请求富友失败: %w", err)
|
||||
}
|
||||
|
||||
if resp.ResultCode != "000000" {
|
||||
c.logger.Error("富友主扫下单失败",
|
||||
zap.String("order_no", orderNo),
|
||||
zap.String("result_code", resp.ResultCode),
|
||||
zap.String("result_msg", resp.ResultMsg),
|
||||
)
|
||||
return nil, fmt.Errorf("富友主扫下单失败: %s", resp.ResultMsg)
|
||||
}
|
||||
|
||||
c.logger.Info("富友主扫下单成功",
|
||||
zap.String("order_no", orderNo),
|
||||
zap.String("order_type", orderType),
|
||||
)
|
||||
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
// CommonQuery 主动查询订单状态。
|
||||
// orderType: 订单类型,须与下单时一致。
|
||||
func (c *Client) CommonQuery(orderNo, orderType string) (*CommonQueryResponse, error) {
|
||||
req := &CommonQueryRequest{
|
||||
Version: "1.0",
|
||||
InsCd: c.InsCd,
|
||||
MchntCd: c.MchntCd,
|
||||
TermId: c.TermId,
|
||||
RandomStr: generateRandomStr(),
|
||||
OrderType: orderType,
|
||||
MchntOrderNo: orderNo,
|
||||
}
|
||||
|
||||
sign, err := c.Sign(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("签名失败: %w", err)
|
||||
}
|
||||
req.Sign = sign
|
||||
|
||||
var resp CommonQueryResponse
|
||||
if err := c.DoRequest("/commonQuery", req, &resp); err != nil {
|
||||
return nil, fmt.Errorf("请求富友失败: %w", err)
|
||||
}
|
||||
|
||||
if resp.ResultCode != "000000" {
|
||||
c.logger.Error("富友订单查询失败",
|
||||
zap.String("order_no", orderNo),
|
||||
zap.String("result_code", resp.ResultCode),
|
||||
zap.String("result_msg", resp.ResultMsg),
|
||||
)
|
||||
return nil, fmt.Errorf("富友订单查询失败: %s", resp.ResultMsg)
|
||||
}
|
||||
|
||||
return &resp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user