refactor: reorganize modules and add Linux build tooling
This commit is contained in:
70
module/finance/wallet/internal/logic/alipay/alipay.go
Normal file
70
module/finance/wallet/internal/logic/alipay/alipay.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package alipay
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bsm/full/module/finance/wallet/internal/config"
|
||||
"github.com/go-pay/gopay"
|
||||
"github.com/go-pay/gopay/alipay"
|
||||
)
|
||||
|
||||
type AliPay struct {
|
||||
ctx context.Context
|
||||
Client *alipay.Client
|
||||
Body *gopay.BodyMap
|
||||
}
|
||||
|
||||
func NewAlipay() (*AliPay, error) {
|
||||
// 初始化支付宝客户端
|
||||
// appid:应用ID
|
||||
// privateKey:应用私钥,支持PKCS1和PKCS8
|
||||
// isProd:是否是正式环境
|
||||
client, err := alipay.NewClient(config.Spec.Alipay.AppID, config.Spec.Alipay.PrivateKey, config.Spec.Alipay.IsProd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 打开Debug开关,输出日志,默认关闭
|
||||
client.DebugSwitch = gopay.DebugOn
|
||||
|
||||
// 设置支付宝请求 公共参数
|
||||
client.SetLocation(alipay.LocationShanghai) // 设置时区,不设置或出错均为默认服务器时间
|
||||
client.SetCharset(alipay.UTF8) // 设置字符编码,不设置默认 utf-8
|
||||
client.SetSignType(alipay.RSA2) // 设置签名类型,不设置默认 RSA2
|
||||
client.SetReturnUrl(config.Spec.Alipay.ReturnURL) // 设置返回URL
|
||||
client.SetNotifyUrl(config.Spec.Alipay.NotifyURL) // 设置异步通知URL
|
||||
|
||||
// 自动同步验签(只支持证书模式)
|
||||
// 传入 alipayCertPublicKey_RSA2.crt 内容
|
||||
client.AutoVerifySign([]byte(config.Spec.Alipay.PublicKeyRsa2Byte))
|
||||
|
||||
// 公钥证书模式
|
||||
err = client.SetCertSnByPath(config.Spec.Alipay.CertPublicKey, config.Spec.Alipay.CertRoot, config.Spec.Alipay.CertPublicKeyRsa2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &AliPay{
|
||||
Client: client,
|
||||
// ctx: context.Background(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (srv *AliPay) SetBody(body, orderNo string, amount int64) {
|
||||
srv.Body.Set("subject", config.Spec.Wallet.Name).
|
||||
Set("body", body). //finance_payment表的identity
|
||||
Set("product_code", "QUICK_WAP_WAY").
|
||||
Set("out_trade_no", orderNo).
|
||||
Set("total_amount", amount/100).
|
||||
Set("timeout_express", "60m").
|
||||
Set("quit_url", config.Spec.Alipay.QuitURL)
|
||||
}
|
||||
|
||||
func (srv *AliPay) TradeWapPay() (string, error) {
|
||||
result, err := srv.Client.TradeWapPay(srv.ctx, *srv.Body)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (srv *AliPay) TradeAppPay() (string, error) {
|
||||
result, err := srv.Client.TradeAppPay(srv.ctx, *srv.Body)
|
||||
return result, err
|
||||
}
|
||||
23
module/finance/wallet/internal/logic/alipay/app_pay.go
Normal file
23
module/finance/wallet/internal/logic/alipay/app_pay.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package alipay
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
pb "bsm/full/module/finance/wallet/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 支付宝APP支付
|
||||
func AppPay(ctx context.Context, in *pb.AlipayTradeAppPayRequest) (reply *pb.AlipayTradeAppPayReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: valid code
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
23
module/finance/wallet/internal/logic/alipay/page_pay.go
Normal file
23
module/finance/wallet/internal/logic/alipay/page_pay.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package alipay
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
pb "bsm/full/module/finance/wallet/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 支付宝电脑网站支付
|
||||
func PagePay(ctx context.Context, in *pb.AlipayTradePagePayRequest) (reply *pb.AlipayTradePagePayReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: valid code
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
23
module/finance/wallet/internal/logic/alipay/transfer.go
Normal file
23
module/finance/wallet/internal/logic/alipay/transfer.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package alipay
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
pb "bsm/full/module/finance/wallet/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 支付宝转账到个人支付宝账户
|
||||
func Transfer(ctx context.Context, in *pb.AlipayUniTransferRequest) (reply *pb.AlipayUniTransferReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: valid code
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
23
module/finance/wallet/internal/logic/alipay/wap_pay.go
Normal file
23
module/finance/wallet/internal/logic/alipay/wap_pay.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package alipay
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
pb "bsm/full/module/finance/wallet/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 支付宝wap支付
|
||||
func WapPay(ctx context.Context, in *pb.AlipayTradeWapPayRequest) (reply *pb.AlipayTradeWapPayReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: valid code
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user