fix: pay pkg error
This commit is contained in:
@@ -2,6 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
wxpay "lone-services/pkg/wechat/pay"
|
||||
@@ -13,11 +14,15 @@ func NewWechatPayConfig(clientCode string) (wxpay.Config, error) {
|
||||
}
|
||||
|
||||
prefix := "wechat." + clientCode
|
||||
appID := utils.GetConfigString(prefix + ".app_id")
|
||||
if appID == utils.StringEmpty {
|
||||
appID = utils.GetConfigString("wechat.appid")
|
||||
}
|
||||
alias := clientAppAlias(clientCode)
|
||||
|
||||
appID := firstNonEmpty(
|
||||
utils.GetConfigString(prefix+".app_id"),
|
||||
utils.GetConfigString(prefix+".appid"),
|
||||
utils.GetConfigString("wechat."+alias+"_appid"),
|
||||
utils.GetConfigString("wechat.appid"),
|
||||
utils.GetConfigString("wechat.app_id"),
|
||||
)
|
||||
mchID := firstNonEmpty(
|
||||
utils.GetConfigString(prefix+".pay_mchid"),
|
||||
utils.GetConfigString("wechat.pay_mchid"),
|
||||
@@ -59,6 +64,13 @@ func NewWechatPayConfig(clientCode string) (wxpay.Config, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func clientAppAlias(clientCode string) string {
|
||||
if i := strings.IndexByte(clientCode, '_'); i > 0 {
|
||||
return clientCode[:i]
|
||||
}
|
||||
return clientCode
|
||||
}
|
||||
|
||||
func firstNonEmpty(values ...string) string {
|
||||
for _, v := range values {
|
||||
if v != utils.StringEmpty {
|
||||
|
||||
Reference in New Issue
Block a user