蛋蛋星球RabbitMq消费项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

svc_wx_pay.go 1.3 KiB

1 month ago
1234567891011121314151617181920212223242526272829303132333435363738
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/enum"
  5. "github.com/gin-gonic/gin"
  6. "github.com/wechatpay-apiv3/wechatpay-go/core"
  7. "github.com/wechatpay-apiv3/wechatpay-go/core/option"
  8. "github.com/wechatpay-apiv3/wechatpay-go/utils"
  9. )
  10. func NewWxPayClient(ctx *gin.Context) (client *core.Client, err error) {
  11. sysCfgDb := db.SysCfgDb{}
  12. sysCfgDb.Set()
  13. sysCfg := sysCfgDb.SysCfgFindWithDb(enum.WxSpMchId, enum.WxSpMchApiV3Key, enum.WxSpMchCertificateSerialNumber)
  14. var (
  15. mchID string = sysCfg[enum.WxSpMchId] // 商户号
  16. mchCertificateSerialNumber string = sysCfg[enum.WxSpMchCertificateSerialNumber] // 商户证书序列号
  17. mchAPIv3Key string = sysCfg[enum.WxSpMchApiV3Key] // 商户APIv3密钥
  18. )
  19. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  20. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("./static/wx/merchant/apiclient_key.pem")
  21. if err != nil {
  22. return
  23. }
  24. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  25. opts := []core.ClientOption{
  26. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  27. }
  28. client, err = core.NewClient(ctx, opts...)
  29. if err != nil {
  30. return
  31. }
  32. return
  33. }