feat: payment pay

This commit is contained in:
zzw
2026-09-11 16:08:17 +08:00
parent f8c7419964
commit d9529a219d
33 changed files with 3108 additions and 89 deletions
@@ -0,0 +1,13 @@
package config
type Config struct {
Nacos NacosConf
}
type NacosConf struct {
Hosts []string
NamespaceId string `json:",optional"`
Group string `json:",optional"`
RegisterIP string `json:",optional"`
ConfigID string `json:",optional"`
}
@@ -0,0 +1,69 @@
package config
import (
"fmt"
"lone-services/pkg/utils"
wxpay "lone-services/pkg/wechat/pay"
)
func NewWechatPayConfig(clientCode string) (wxpay.Config, error) {
if clientCode == utils.StringEmpty {
return wxpay.Config{}, fmt.Errorf("wechat pay client_code empty")
}
prefix := "wechat." + clientCode
appID := utils.GetConfigString(prefix + ".app_id")
if appID == utils.StringEmpty {
appID = utils.GetConfigString("wechat.appid")
}
mchID := firstNonEmpty(
utils.GetConfigString(prefix+".pay_mchid"),
utils.GetConfigString("wechat.pay_mchid"),
)
serialNo := firstNonEmpty(
utils.GetConfigString(prefix+".pay_serial_no"),
utils.GetConfigString("wechat.pay_serial_no"),
)
privateKeyPath := firstNonEmpty(
utils.GetConfigString(prefix+".pay_private_key_path"),
utils.GetConfigString("wechat.pay_private_key_path"),
)
platformCertPath := firstNonEmpty(
utils.GetConfigString(prefix+".pay_platform_cert_path"),
utils.GetConfigString("wechat.pay_platform_cert_path"),
)
apiV3Key := firstNonEmpty(
utils.GetConfigString(prefix+".pay_apiv3_key"),
utils.GetConfigString("wechat.pay_apiv3_key"),
)
notifyURL := firstNonEmpty(
utils.GetConfigString(prefix+".pay_notify_url"),
utils.GetConfigString("wechat.pay_notify_url"),
)
if appID == utils.StringEmpty || mchID == utils.StringEmpty || serialNo == utils.StringEmpty ||
privateKeyPath == utils.StringEmpty || apiV3Key == utils.StringEmpty {
return wxpay.Config{}, fmt.Errorf("wechat pay config missing for client %s", clientCode)
}
return wxpay.Config{
AppID: appID,
MchID: mchID,
CertificateSerialNo: serialNo,
PrivateKeyPath: privateKeyPath,
PlatformCertPath: platformCertPath,
APIv3Key: apiV3Key,
NotifyURL: notifyURL,
}, nil
}
func firstNonEmpty(values ...string) string {
for _, v := range values {
if v != utils.StringEmpty {
return v
}
}
return utils.StringEmpty
}