Compare commits
2 Commits
cb53a94c75
...
a39ab003f4
| Author | SHA1 | Date | |
|---|---|---|---|
| a39ab003f4 | |||
| 36d12affd4 |
@@ -36,10 +36,10 @@ func (c *Channel) Prepay(ctx context.Context, client string, req *pkgpay.PrepayR
|
||||
}
|
||||
|
||||
switch client {
|
||||
case pkgpay.ClientMiniProgram:
|
||||
return c.miniProgramPrepay(ctx, req)
|
||||
default:
|
||||
case pkgpay.ClientApp, pkgpay.ClientH5:
|
||||
return nil, pkgpay.ErrUnsupportedClient
|
||||
default:
|
||||
return c.miniProgramPrepay(ctx, req)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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