package yeepaycli import ( "context" "github.com/yop-platform/yop-go-sdk/yop/client" "github.com/yop-platform/yop-go-sdk/yop/constants" "github.com/yop-platform/yop-go-sdk/yop/request" "github.com/yop-platform/yop-go-sdk/yop/response" "net/http" "service/library/configcenter" "time" ) const ( DefaultOrderTimeoutSeconds = 900 // 默认订单超时时间,单位: s ) var defaultYeepayClient *YeepayClient type YeepayClient struct { client *client.YopClient AppId string ParentMerchantNo string // 父商编 系统商或平台商场景下为主商户商户编号,否则为收单商户编号 MerchantNo string // 子商编 收单商户商编 NotifyUrl string // 回调通知 PrivateKey string // 私钥 } func GetDefaultYeepayClient() *YeepayClient { return defaultYeepayClient } func Init(cfg *configcenter.YeepayClientConfig) { cli := &client.YopClient{ Client: &http.Client{ Transport: http.DefaultTransport, }, } defaultYeepayClient = &YeepayClient{ client: cli, AppId: cfg.Appid, ParentMerchantNo: cfg.ParentMerchantNo, MerchantNo: cfg.MerchantNo, NotifyUrl: cfg.NotifyUrl, PrivateKey: cfg.PrivateKey, } } // 验签 func (c *YeepayClient) ParseNotify() { } // 易宝支付 聚合支付 type AggPayParam struct { Description string OutTradeNo string // 商家订单id,我们自己的订单id TotalAmount int64 // 金额,单位:分 RedirectUrl string // 页面通知地址 支付成功后页面回调地址 如不指定页面回调地址,支付完成后会停留在易宝的支付成功页 PayWay string PayChannel string Ip string } func (c *YeepayClient) AggPay(ctx context.Context, param *AggPayParam) (resp *response.YopResponse, err error) { req := request.NewYopRequest(constants.POST_HTTP_METHOD, "/rest/v1.0/aggpay/tutelage/pre-pay") req.AppId = c.AppId req.IsvPriKey = request.IsvPriKey{Value: c.PrivateKey, CertType: request.RSA2048} req.AddParam("parentMerchantNo", c.ParentMerchantNo) req.AddParam("merchantNo", c.MerchantNo) req.AddParam("orderId", param.OutTradeNo) req.AddParam("orderAmount", float64(param.TotalAmount)/100.0) req.AddParam("expiredTime", time.Now().Add(DefaultOrderTimeoutSeconds).Format("2006-01-02 15:04:05")) req.AddParam("goodsName", param.Description) req.AddParam("notifyUrl", c.NotifyUrl) req.AddParam("payWay", param.PayWay) req.AddParam("channel", param.PayChannel) req.AddParam("scene", "ONLINE") req.AddParam("userIp", param.Ip) resp, err = c.client.Request(req) if err != nil { return } return }