Register Alipay and WxPay option keys and sync option updates into runtime payment settings.
97 lines
3.3 KiB
Go
97 lines
3.3 KiB
Go
package setting
|
|
|
|
import "strconv"
|
|
|
|
type WxpaySetting struct {
|
|
Enabled bool `json:"enabled"`
|
|
AppID string `json:"app_id"`
|
|
MchID string `json:"mch_id"`
|
|
PrivateKey string `json:"private_key"`
|
|
MerchantSerialNo string `json:"merchant_serial_no"`
|
|
APIv3Key string `json:"api_v3_key"`
|
|
PlatformPublicKey string `json:"platform_public_key"`
|
|
PlatformCertificate string `json:"platform_certificate"`
|
|
PlatformSerialNo string `json:"platform_serial_no"`
|
|
GatewayURL string `json:"gateway_url"`
|
|
NotifyURL string `json:"notify_url"`
|
|
ReturnURL string `json:"return_url"`
|
|
H5AppName string `json:"h5_app_name"`
|
|
H5AppURL string `json:"h5_app_url"`
|
|
}
|
|
|
|
var Wxpay = WxpaySetting{
|
|
GatewayURL: "https://api.mch.weixin.qq.com",
|
|
}
|
|
|
|
const (
|
|
WxpayEnabledOption = "WxpayEnabled"
|
|
WxpayAppIDOption = "WxpayAppID"
|
|
WxpayMchIDOption = "WxpayMchID"
|
|
WxpayPrivateKeyOption = "WxpayPrivateKey"
|
|
WxpayMerchantSerialNoOption = "WxpayMerchantSerialNo"
|
|
WxpayAPIv3KeyOption = "WxpayAPIv3Key"
|
|
WxpayPlatformPublicKeyOption = "WxpayPlatformPublicKey"
|
|
WxpayPlatformCertificateOption = "WxpayPlatformCertificate"
|
|
WxpayPlatformSerialNoOption = "WxpayPlatformSerialNo"
|
|
WxpayGatewayURLOption = "WxpayGatewayURL"
|
|
WxpayNotifyURLOption = "WxpayNotifyURL"
|
|
WxpayReturnURLOption = "WxpayReturnURL"
|
|
WxpayH5AppNameOption = "WxpayH5AppName"
|
|
WxpayH5AppURLOption = "WxpayH5AppURL"
|
|
)
|
|
|
|
func WxpayOptionValues() map[string]string {
|
|
return map[string]string{
|
|
WxpayEnabledOption: strconv.FormatBool(Wxpay.Enabled),
|
|
WxpayAppIDOption: Wxpay.AppID,
|
|
WxpayMchIDOption: Wxpay.MchID,
|
|
WxpayPrivateKeyOption: Wxpay.PrivateKey,
|
|
WxpayMerchantSerialNoOption: Wxpay.MerchantSerialNo,
|
|
WxpayAPIv3KeyOption: Wxpay.APIv3Key,
|
|
WxpayPlatformPublicKeyOption: Wxpay.PlatformPublicKey,
|
|
WxpayPlatformCertificateOption: Wxpay.PlatformCertificate,
|
|
WxpayPlatformSerialNoOption: Wxpay.PlatformSerialNo,
|
|
WxpayGatewayURLOption: Wxpay.GatewayURL,
|
|
WxpayNotifyURLOption: Wxpay.NotifyURL,
|
|
WxpayReturnURLOption: Wxpay.ReturnURL,
|
|
WxpayH5AppNameOption: Wxpay.H5AppName,
|
|
WxpayH5AppURLOption: Wxpay.H5AppURL,
|
|
}
|
|
}
|
|
|
|
func UpdateWxpayOption(key string, value string) bool {
|
|
switch key {
|
|
case WxpayEnabledOption:
|
|
Wxpay.Enabled = value == "true"
|
|
case WxpayAppIDOption:
|
|
Wxpay.AppID = value
|
|
case WxpayMchIDOption:
|
|
Wxpay.MchID = value
|
|
case WxpayPrivateKeyOption:
|
|
Wxpay.PrivateKey = value
|
|
case WxpayMerchantSerialNoOption:
|
|
Wxpay.MerchantSerialNo = value
|
|
case WxpayAPIv3KeyOption:
|
|
Wxpay.APIv3Key = value
|
|
case WxpayPlatformPublicKeyOption:
|
|
Wxpay.PlatformPublicKey = value
|
|
case WxpayPlatformCertificateOption:
|
|
Wxpay.PlatformCertificate = value
|
|
case WxpayPlatformSerialNoOption:
|
|
Wxpay.PlatformSerialNo = value
|
|
case WxpayGatewayURLOption:
|
|
Wxpay.GatewayURL = value
|
|
case WxpayNotifyURLOption:
|
|
Wxpay.NotifyURL = value
|
|
case WxpayReturnURLOption:
|
|
Wxpay.ReturnURL = value
|
|
case WxpayH5AppNameOption:
|
|
Wxpay.H5AppName = value
|
|
case WxpayH5AppURLOption:
|
|
Wxpay.H5AppURL = value
|
|
default:
|
|
return false
|
|
}
|
|
return true
|
|
}
|