微信红包 todo 插件加载证书

This commit is contained in:
李子铭 2024-09-02 11:36:45 +08:00
parent 740d48d4fe
commit 673859b923
3 changed files with 11 additions and 11 deletions

View File

@ -2,6 +2,6 @@ package main
// main 这只是一个演示
func main() {
wechatCpn()
//wechatRedPack()
//wechatCpn()
wechatRedPack()
}

View File

@ -37,9 +37,9 @@ func wechatRedPack() {
Config: getWechatRedPackConf(),
Order: &proto.QueryRequest_Order{
OrderNo: "",
TradeNo: "69445765514",
Account: "oO3vO5AxRWgTjmMD38FTvnB5Rq6o",
Extra: []byte(`{"app_id":"wx9ed74283ad25bca1"}`),
TradeNo: "202408211517304392270563",
Account: "",
Extra: []byte(`{"out_detail_no":"20240821151730439227056399842027"}`),
},
}
resQuery, err := instance.Query(context.Background(), wechatRedPackConf.Tag, queryRequest)

View File

@ -2,6 +2,7 @@ package wechat
import (
"context"
"crypto/x509"
"fmt"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
@ -34,12 +35,11 @@ func newClient(ctx context.Context, c *Server) (*core.Client, error) {
option.WithWechatPayAutoAuthCipher(c.MchID, c.MchCertificateSerialNumber, mchPrivateKey, c.MchAPIv3Key),
}
// 微信支付平台配置
////payCert, err := utils.LoadCertificateWithPath(fmt.Sprintf("%s/%s", filePath, "wechat_cert.pem"))
//payCert, err := utils.LoadCertificateWithPath(fmt.Sprintf("%s/%s", filePath, "wechatpay_2C10BB073B55C2191DF46CE443DA8B9064AB7F60.pem"))
//if err != nil {
// return nil, fmt.Errorf("MchID[%s] load pay certificate error:%v", c.MchID, err)
//}
//opts = append(opts, option.WithWechatPayCertificate([]*x509.Certificate{payCert}))
payCert, err := utils.LoadCertificateWithPath(fmt.Sprintf("%s/%s", filePath, "wechat_cert.pem"))
if err != nil {
return nil, fmt.Errorf("MchID[%s] load pay certificate error:%v", c.MchID, err)
}
opts = append(opts, option.WithWechatPayCertificate([]*x509.Certificate{payCert}))
client, err := core.NewClient(ctx, opts...)
if err != nil {
return nil, fmt.Errorf("MchID[%s] %v", c.MchID, err)