支付配置
This commit is contained in:
parent
50382f2c0a
commit
9f052435cc
|
@ -4,7 +4,7 @@ const (
|
||||||
TOKEN_PRE = "player_token_"
|
TOKEN_PRE = "player_token_"
|
||||||
TOKEN_Admin = "Admin_token_"
|
TOKEN_Admin = "Admin_token_"
|
||||||
ADMIN_V1 = "/pay/admin/api/v1"
|
ADMIN_V1 = "/pay/admin/api/v1"
|
||||||
FRONT_V1 = "/api/v1"
|
FRONT_V1 = "/pay/front/api/v1"
|
||||||
|
|
||||||
// 支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
// 支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
||||||
PAY_CHANNEL_UNKNOWN = 0
|
PAY_CHANNEL_UNKNOWN = 0
|
||||||
|
|
|
@ -4,6 +4,7 @@ package routes
|
||||||
* 配置路由
|
* 配置路由
|
||||||
*/
|
*/
|
||||||
import (
|
import (
|
||||||
|
"PaymentCenter/app/constants/common"
|
||||||
"PaymentCenter/app/http/controllers"
|
"PaymentCenter/app/http/controllers"
|
||||||
"PaymentCenter/app/http/controllers/backend"
|
"PaymentCenter/app/http/controllers/backend"
|
||||||
"PaymentCenter/app/http/controllers/front"
|
"PaymentCenter/app/http/controllers/front"
|
||||||
|
@ -47,7 +48,7 @@ func RegisterRoute(router *gin.Engine) {
|
||||||
|
|
||||||
//router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
//router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||||
|
|
||||||
v1 := router.Group("/v1")
|
v1 := router.Group(common.FRONT_V1)
|
||||||
{
|
{
|
||||||
//回调处理
|
//回调处理
|
||||||
notify := v1.Group("/notify")
|
notify := v1.Group("/notify")
|
||||||
|
|
|
@ -2,6 +2,7 @@ package paymentService
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"PaymentCenter/app/third/paymentService/payCommon"
|
"PaymentCenter/app/third/paymentService/payCommon"
|
||||||
|
"PaymentCenter/config"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -20,12 +21,13 @@ var (
|
||||||
|
|
||||||
// AliInitClient 使用提供的支付请求参数初始化支付宝客户端
|
// AliInitClient 使用提供的支付请求参数初始化支付宝客户端
|
||||||
func AliInitClient(aliConfig AliPay) {
|
func AliInitClient(aliConfig AliPay) {
|
||||||
|
envConfig := config.GetConf()
|
||||||
aliOnce.Do(func() {
|
aliOnce.Do(func() {
|
||||||
// 初始化支付宝客户端
|
// 初始化支付宝客户端
|
||||||
// appid:应用ID
|
// appid:应用ID
|
||||||
// privateKey:应用私钥,支持PKCS1和PKCS8
|
// privateKey:应用私钥,支持PKCS1和PKCS8
|
||||||
// isProd:是否是正式环境,沙箱环境请选择新版沙箱应用。
|
// isProd:是否是正式环境,沙箱环境请选择新版沙箱应用。
|
||||||
aliClient, aliClientErr = alipay.NewClient(aliConfig.AppId, aliConfig.PrivateKey, true)
|
aliClient, aliClientErr = alipay.NewClient(aliConfig.AppId, aliConfig.PrivateKey, envConfig.PayService.IsProd)
|
||||||
})
|
})
|
||||||
// 自定义配置http请求接收返回结果body大小,默认 10MB
|
// 自定义配置http请求接收返回结果body大小,默认 10MB
|
||||||
aliClient.SetBodySize(10) // 没有特殊需求,可忽略此配置
|
aliClient.SetBodySize(10) // 没有特殊需求,可忽略此配置
|
||||||
|
@ -72,12 +74,13 @@ func ALiH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, e
|
||||||
// 初始化 BodyMap
|
// 初始化 BodyMap
|
||||||
amount := float64(payOrderRequest.Amount) / 100.0
|
amount := float64(payOrderRequest.Amount) / 100.0
|
||||||
|
|
||||||
|
envConfig := config.GetConf()
|
||||||
bm := make(gopay.BodyMap)
|
bm := make(gopay.BodyMap)
|
||||||
bm.Set("out_trade_no", payOrderRequest.OrderId).
|
bm.Set("out_trade_no", payOrderRequest.OrderId).
|
||||||
Set("total_amount", amount).
|
Set("total_amount", amount).
|
||||||
Set("subject", payOrderRequest.Description).
|
Set("subject", payOrderRequest.Description).
|
||||||
//Set("notify_url", fmt.Sprintf(payCommon.ALI_NOTIFY_URL_TEST+"%d", payOrderRequest.PayChannelId)).
|
Set("notify_url", fmt.Sprintf(envConfig.PayService.TestHost+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.ProdHost+payCommon.ALI_NOTIFY_URL_PROD+"%d", payOrderRequest.PayChannelId))
|
||||||
|
|
||||||
aliRsp, err := aliClient.TradeWapPay(c, bm)
|
aliRsp, err := aliClient.TradeWapPay(c, bm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package payCommon
|
package payCommon
|
||||||
|
|
||||||
|
import "PaymentCenter/app/constants/common"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TEST_URL = ""
|
|
||||||
PROD_URL = ""
|
|
||||||
|
|
||||||
// 支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
// 支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
||||||
PAY_CHANNEL_UNKNOWN = 0
|
PAY_CHANNEL_UNKNOWN = 0
|
||||||
|
@ -21,10 +21,10 @@ const (
|
||||||
|
|
||||||
WX_SUCCESS_CODE = 200 // 微信状态码返回成功
|
WX_SUCCESS_CODE = 200 // 微信状态码返回成功
|
||||||
|
|
||||||
WX_NOTIFY_URL_TEST = TEST_URL + "/v1/notify/wx/" // 微信支付回调地址
|
WX_NOTIFY_URL_TEST = common.FRONT_V1 + "/notify/wx/" // 微信支付回调地址
|
||||||
WX_NOTIFY_URL_PROD = PROD_URL + "/v1/notify/wx/" // 微信支付回调地址
|
WX_NOTIFY_URL_PROD = common.FRONT_V1 + "/notify/wx/" // 微信支付回调地址
|
||||||
ALI_NOTIFY_URL_TEST = TEST_URL + "/v1/notify/ali/" // 支付宝支付回调地址
|
ALI_NOTIFY_URL_TEST = common.FRONT_V1 + "/notify/ali/" // 支付宝支付回调地址
|
||||||
ALI_NOTIFY_URL_PROD = PROD_URL + "/v1/notify/ali/" // 支付宝支付回调地址
|
ALI_NOTIFY_URL_PROD = common.FRONT_V1 + "/notify/ali/" // 支付宝支付回调地址
|
||||||
|
|
||||||
ORDER_NO_TYPE_ORDER_NO = 2
|
ORDER_NO_TYPE_ORDER_NO = 2
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2,6 +2,7 @@ package paymentService
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"PaymentCenter/app/third/paymentService/payCommon"
|
"PaymentCenter/app/third/paymentService/payCommon"
|
||||||
|
"PaymentCenter/config"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -67,14 +68,15 @@ func WxH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, er
|
||||||
}
|
}
|
||||||
expire := time.Now().Add(10 * time.Minute).Format(time.RFC3339)
|
expire := time.Now().Add(10 * time.Minute).Format(time.RFC3339)
|
||||||
// 初始化 BodyMap
|
// 初始化 BodyMap
|
||||||
|
envConfig := config.GetConf()
|
||||||
bm := make(gopay.BodyMap)
|
bm := make(gopay.BodyMap)
|
||||||
bm.Set("appid", payOrderRequest.Wx.AppId).
|
bm.Set("appid", payOrderRequest.Wx.AppId).
|
||||||
Set("mchid", payOrderRequest.Wx.MchId).
|
Set("mchid", payOrderRequest.Wx.MchId).
|
||||||
Set("description", payOrderRequest.Description).
|
Set("description", payOrderRequest.Description).
|
||||||
Set("out_trade_no", payOrderRequest.OrderId).
|
Set("out_trade_no", payOrderRequest.OrderId).
|
||||||
Set("time_expire", expire).
|
Set("time_expire", expire).
|
||||||
//Set("notify_url", fmt.Sprintf(payCommon.WX_NOTIFY_URL_TEST+"%d", payOrderRequest.PayChannelId)).
|
Set("notify_url", fmt.Sprintf(envConfig.PayService.TestHost+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.ProdHost+payCommon.WX_NOTIFY_URL_PROD+"%d", payOrderRequest.PayChannelId)).
|
||||||
SetBodyMap("amount", func(bm gopay.BodyMap) {
|
SetBodyMap("amount", func(bm gopay.BodyMap) {
|
||||||
bm.Set("total", payOrderRequest.Amount).
|
bm.Set("total", payOrderRequest.Amount).
|
||||||
Set("currency", "CNY")
|
Set("currency", "CNY")
|
||||||
|
|
|
@ -39,6 +39,7 @@ type Config struct {
|
||||||
AliOss AliOss `toml:"AliOss"`
|
AliOss AliOss `toml:"AliOss"`
|
||||||
AdminGate []string `toml:"AdminGate"`
|
AdminGate []string `toml:"AdminGate"`
|
||||||
CronConfig CronConfig `toml:"CronConfig"`
|
CronConfig CronConfig `toml:"CronConfig"`
|
||||||
|
PayService PayService `toml:"PayService"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AliOss struct {
|
type AliOss struct {
|
||||||
|
@ -91,6 +92,12 @@ type CronConfig struct {
|
||||||
ConcurrentNumber int `toml:"ConcurrentNumber"`
|
ConcurrentNumber int `toml:"ConcurrentNumber"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PayService struct {
|
||||||
|
TestHost string `toml:"TestHost"`
|
||||||
|
ProdHost string `toml:"ProdHost"`
|
||||||
|
IsProd bool `toml:"IsProd"`
|
||||||
|
}
|
||||||
|
|
||||||
func newConfig() *Config {
|
func newConfig() *Config {
|
||||||
return new(Config)
|
return new(Config)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue