var (
mchID string = "123456" // 商户号
mchCertificateSerialNumber string = "123456" // 商户证书序列号
mchAPIv3Key string = "123456" // 商户APIv3密钥
)
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("C:/Users/Administrator/Desktop/小游戏微信支付/1516803781_20220721_cert/apiclient_key.pem")
if err != nil {
log.Fatal("error:",err.Error())
}
ctx := context.Background()
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
}
client, err := core.NewClient(ctx, opts...)
if err != nil {
log.Printf("new wechat pay client err:%s", err)
}
svc := transferbatch.TransferBatchApiService{Client: client}
resp, result, err := svc.InitiateBatchTransfer(ctx,
transferbatch.InitiateBatchTransferRequest{
Appid: core.String("ccc"),//商户appid
BatchName: core.String("3699游戏"),
BatchRemark: core.String("3699小游戏"),
OutBatchNo: core.String("plfk2020042013"),
TotalAmount: core.Int64(30),
TotalNum: core.Int64(1),
TransferDetailList: []transferbatch.TransferDetailInput{transferbatch.TransferDetailInput{
TransferAmount: core.Int64(30),
OutDetailNo: core.String("x23zy545Bd5435"),
TransferRemark: core.String("游戏提现"),
Openid: core.String("o-2233"),//用户openid
}},
},
)
if err != nil {
// 处理错误
log.Printf("call InitiateBatchTransfer err:%s", err)
} else {
// 处理返回结果
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
}