支付配置

This commit is contained in:
陈俊宏 2024-08-06 10:22:03 +08:00
parent 50382f2c0a
commit 9f052435cc
7 changed files with 45 additions and 32 deletions

View File

@ -4,7 +4,7 @@ const (
TOKEN_PRE = "player_token_"
TOKEN_Admin = "Admin_token_"
ADMIN_V1 = "/pay/admin/api/v1"
FRONT_V1 = "/api/v1"
FRONT_V1 = "/pay/front/api/v1"
// 支付渠道枚举,1微信JSAPI2微信H53微信app4微信Native5微信小程序6支付宝网页&移动应用7支付宝小程序8支付宝JSAPI
PAY_CHANNEL_UNKNOWN = 0

View File

@ -4,6 +4,7 @@ package routes
* 配置路由
*/
import (
"PaymentCenter/app/constants/common"
"PaymentCenter/app/http/controllers"
"PaymentCenter/app/http/controllers/backend"
"PaymentCenter/app/http/controllers/front"
@ -47,7 +48,7 @@ func RegisterRoute(router *gin.Engine) {
//router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
v1 := router.Group("/v1")
v1 := router.Group(common.FRONT_V1)
{
//回调处理
notify := v1.Group("/notify")

View File

@ -2,6 +2,7 @@ package paymentService
import (
"PaymentCenter/app/third/paymentService/payCommon"
"PaymentCenter/config"
"context"
"errors"
"fmt"
@ -20,12 +21,13 @@ var (
// AliInitClient 使用提供的支付请求参数初始化支付宝客户端
func AliInitClient(aliConfig AliPay) {
envConfig := config.GetConf()
aliOnce.Do(func() {
// 初始化支付宝客户端
// appid应用ID
// privateKey应用私钥支持PKCS1和PKCS8
// isProd是否是正式环境沙箱环境请选择新版沙箱应用。
aliClient, aliClientErr = alipay.NewClient(aliConfig.AppId, aliConfig.PrivateKey, true)
aliClient, aliClientErr = alipay.NewClient(aliConfig.AppId, aliConfig.PrivateKey, envConfig.PayService.IsProd)
})
// 自定义配置http请求接收返回结果body大小默认 10MB
aliClient.SetBodySize(10) // 没有特殊需求,可忽略此配置
@ -72,12 +74,13 @@ func ALiH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, e
// 初始化 BodyMap
amount := float64(payOrderRequest.Amount) / 100.0
envConfig := config.GetConf()
bm := make(gopay.BodyMap)
bm.Set("out_trade_no", payOrderRequest.OrderId).
Set("total_amount", amount).
Set("subject", payOrderRequest.Description).
//Set("notify_url", fmt.Sprintf(payCommon.ALI_NOTIFY_URL_TEST+"%d", payOrderRequest.PayChannelId)).
Set("notify_url", fmt.Sprintf(payCommon.ALI_NOTIFY_URL_PROD+"%d", payOrderRequest.PayChannelId))
Set("notify_url", fmt.Sprintf(envConfig.PayService.TestHost+payCommon.ALI_NOTIFY_URL_TEST+"%d", payOrderRequest.PayChannelId))
//Set("notify_url", fmt.Sprintf(envConfig.PayService.ProdHost+payCommon.ALI_NOTIFY_URL_PROD+"%d", payOrderRequest.PayChannelId))
aliRsp, err := aliClient.TradeWapPay(c, bm)
if err != nil {

View File

@ -1,8 +1,8 @@
package payCommon
import "PaymentCenter/app/constants/common"
const (
TEST_URL = ""
PROD_URL = ""
// 支付渠道枚举,1微信JSAPI2微信H53微信app4微信Native5微信小程序6支付宝网页&移动应用7支付宝小程序8支付宝JSAPI
PAY_CHANNEL_UNKNOWN = 0
@ -21,10 +21,10 @@ const (
WX_SUCCESS_CODE = 200 // 微信状态码返回成功
WX_NOTIFY_URL_TEST = TEST_URL + "/v1/notify/wx/" // 微信支付回调地址
WX_NOTIFY_URL_PROD = PROD_URL + "/v1/notify/wx/" // 微信支付回调地址
ALI_NOTIFY_URL_TEST = TEST_URL + "/v1/notify/ali/" // 支付宝支付回调地址
ALI_NOTIFY_URL_PROD = PROD_URL + "/v1/notify/ali/" // 支付宝支付回调地址
WX_NOTIFY_URL_TEST = common.FRONT_V1 + "/notify/wx/" // 微信支付回调地址
WX_NOTIFY_URL_PROD = common.FRONT_V1 + "/notify/wx/" // 微信支付回调地址
ALI_NOTIFY_URL_TEST = common.FRONT_V1 + "/notify/ali/" // 支付宝支付回调地址
ALI_NOTIFY_URL_PROD = common.FRONT_V1 + "/notify/ali/" // 支付宝支付回调地址
ORDER_NO_TYPE_ORDER_NO = 2

File diff suppressed because one or more lines are too long

View File

@ -2,6 +2,7 @@ package paymentService
import (
"PaymentCenter/app/third/paymentService/payCommon"
"PaymentCenter/config"
"context"
"errors"
"fmt"
@ -67,14 +68,15 @@ func WxH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, er
}
expire := time.Now().Add(10 * time.Minute).Format(time.RFC3339)
// 初始化 BodyMap
envConfig := config.GetConf()
bm := make(gopay.BodyMap)
bm.Set("appid", payOrderRequest.Wx.AppId).
Set("mchid", payOrderRequest.Wx.MchId).
Set("description", payOrderRequest.Description).
Set("out_trade_no", payOrderRequest.OrderId).
Set("time_expire", expire).
//Set("notify_url", fmt.Sprintf(payCommon.WX_NOTIFY_URL_TEST+"%d", payOrderRequest.PayChannelId)).
Set("notify_url", fmt.Sprintf(payCommon.WX_NOTIFY_URL_PROD+"%d", payOrderRequest.PayChannelId)).
Set("notify_url", fmt.Sprintf(envConfig.PayService.TestHost+payCommon.WX_NOTIFY_URL_TEST+"%d", payOrderRequest.PayChannelId)).
//Set("notify_url", fmt.Sprintf(envConfig.PayService.ProdHost+payCommon.WX_NOTIFY_URL_PROD+"%d", payOrderRequest.PayChannelId)).
SetBodyMap("amount", func(bm gopay.BodyMap) {
bm.Set("total", payOrderRequest.Amount).
Set("currency", "CNY")

View File

@ -39,6 +39,7 @@ type Config struct {
AliOss AliOss `toml:"AliOss"`
AdminGate []string `toml:"AdminGate"`
CronConfig CronConfig `toml:"CronConfig"`
PayService PayService `toml:"PayService"`
}
type AliOss struct {
@ -91,6 +92,12 @@ type CronConfig struct {
ConcurrentNumber int `toml:"ConcurrentNumber"`
}
type PayService struct {
TestHost string `toml:"TestHost"`
ProdHost string `toml:"ProdHost"`
IsProd bool `toml:"IsProd"`
}
func newConfig() *Config {
return new(Config)
}