添加微信支付下单
This commit is contained in:
parent
187c573942
commit
c4c8bea3c1
@ -29,7 +29,7 @@ root:
|
||||
max_idle_conns: 0
|
||||
|
||||
# 数据库连接字符串
|
||||
connection_string: "root:Qq5201530300@tcp(192.168.50.110:3306)/user?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true"
|
||||
connection_string: "root:Qq5201530300@tcp(192.168.50.110:3306)/pay?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true"
|
||||
|
||||
redis_config:
|
||||
# 数据库连接字符串
|
||||
|
||||
@ -5,7 +5,7 @@ services:
|
||||
container_name: mysql-admin
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: 123456
|
||||
MYSQL_DATABASE: admin,user
|
||||
MYSQL_DATABASE: admin,pay
|
||||
volumes:
|
||||
- /my/own/datadir:/var/lib/mysql
|
||||
ports:
|
||||
|
||||
@ -86,6 +86,9 @@ type DBConfig struct {
|
||||
// 用户数据库配置
|
||||
UserDB DatabaseConfig `yaml:"user_db"`
|
||||
|
||||
// 用户数据库配置
|
||||
PayDB DatabaseConfig `yaml:"pay_db"`
|
||||
|
||||
// 游戏模型数据库配置
|
||||
GameModel DatabaseConfig `yaml:"game_model"`
|
||||
|
||||
|
||||
@ -18,6 +18,9 @@ type DbConfig struct {
|
||||
// 用户数据库链接字符串
|
||||
userConfig *mysqlUtil.DBConfig
|
||||
|
||||
// 充值数据库链接字符串
|
||||
payConfig *mysqlUtil.DBConfig
|
||||
|
||||
// 游戏模型数据库链接字符串
|
||||
gameModelConfig *mysqlUtil.DBConfig
|
||||
|
||||
@ -62,6 +65,19 @@ func (config *DbConfig) GetUserConfig() *mysqlUtil.DBConfig {
|
||||
return config.userConfig
|
||||
}
|
||||
|
||||
// GetPayConfig
|
||||
// @description: 获取pay库配置
|
||||
// parameter:
|
||||
//
|
||||
// @receiver config:config
|
||||
//
|
||||
// return:
|
||||
//
|
||||
// @*mysqlUtil.DBConfig:user库配置
|
||||
func (config *DbConfig) GetPayConfig() *mysqlUtil.DBConfig {
|
||||
return config.payConfig
|
||||
}
|
||||
|
||||
// GetGameModelConfig
|
||||
// @description: 获取model库配置
|
||||
// parameter:
|
||||
@ -128,13 +144,14 @@ func (config *DbConfig) GetRedisConfig() *redisUtil.RedisConfig {
|
||||
// return:
|
||||
//
|
||||
// @*DbConfig:
|
||||
func newMysqlConfig(_adminConfig *mysqlUtil.DBConfig, _userConfig *mysqlUtil.DBConfig, _gameModelConfig *mysqlUtil.DBConfig,
|
||||
func newMysqlConfig(_adminConfig *mysqlUtil.DBConfig, _userConfig *mysqlUtil.DBConfig, _payConfig *mysqlUtil.DBConfig, _gameModelConfig *mysqlUtil.DBConfig,
|
||||
_gameConfig *mysqlUtil.DBConfig,
|
||||
_playerConfig *mysqlUtil.DBConfig,
|
||||
_redisConfig *redisUtil.RedisConfig) *DbConfig {
|
||||
return &DbConfig{
|
||||
adminConfig: _adminConfig,
|
||||
userConfig: _userConfig,
|
||||
payConfig: _payConfig,
|
||||
gameModelConfig: _gameModelConfig,
|
||||
gameConfig: _gameConfig,
|
||||
redisConfig: _redisConfig,
|
||||
@ -158,6 +175,7 @@ func initDbConfig() error {
|
||||
logUtilPlus.DebugLog("开始加载DbConfig")
|
||||
|
||||
redisConfig := ConfigYaml.Root.DbConfig.RedisConfig
|
||||
dbConfig := ConfigYaml.Root.DbConfig
|
||||
|
||||
//if redisConfig == nil {
|
||||
// logUtilPlus.DebugLog("redis配置为空")
|
||||
@ -166,11 +184,12 @@ func initDbConfig() error {
|
||||
|
||||
// 初始化mysql配置对象
|
||||
dbConfigObj = newMysqlConfig(
|
||||
mysqlUtil.NewDBConfig(ConfigYaml.Root.DbConfig.AdminDB.ConnectionString, ConfigYaml.Root.DbConfig.AdminDB.MaxOpenConns, ConfigYaml.Root.DbConfig.AdminDB.MaxIdleConns),
|
||||
mysqlUtil.NewDBConfig(ConfigYaml.Root.DbConfig.UserDB.ConnectionString, ConfigYaml.Root.DbConfig.UserDB.MaxOpenConns, ConfigYaml.Root.DbConfig.UserDB.MaxIdleConns),
|
||||
mysqlUtil.NewDBConfig(ConfigYaml.Root.DbConfig.GameModel.ConnectionString, ConfigYaml.Root.DbConfig.GameModel.MaxOpenConns, ConfigYaml.Root.DbConfig.GameModel.MaxIdleConns),
|
||||
mysqlUtil.NewDBConfig(ConfigYaml.Root.DbConfig.GameDB.ConnectionString, ConfigYaml.Root.DbConfig.GameDB.MaxOpenConns, ConfigYaml.Root.DbConfig.GameDB.MaxIdleConns),
|
||||
mysqlUtil.NewDBConfig(ConfigYaml.Root.DbConfig.PlayerDB.ConnectionString, ConfigYaml.Root.DbConfig.PlayerDB.MaxOpenConns, ConfigYaml.Root.DbConfig.PlayerDB.MaxIdleConns),
|
||||
mysqlUtil.NewDBConfig(dbConfig.AdminDB.ConnectionString, dbConfig.AdminDB.MaxOpenConns, dbConfig.AdminDB.MaxIdleConns),
|
||||
mysqlUtil.NewDBConfig(dbConfig.UserDB.ConnectionString, dbConfig.UserDB.MaxOpenConns, dbConfig.UserDB.MaxIdleConns),
|
||||
mysqlUtil.NewDBConfig(dbConfig.PayDB.ConnectionString, dbConfig.PayDB.MaxOpenConns, dbConfig.PayDB.MaxIdleConns),
|
||||
mysqlUtil.NewDBConfig(dbConfig.GameModel.ConnectionString, dbConfig.GameModel.MaxOpenConns, dbConfig.GameModel.MaxIdleConns),
|
||||
mysqlUtil.NewDBConfig(dbConfig.GameDB.ConnectionString, dbConfig.GameDB.MaxOpenConns, dbConfig.GameDB.MaxIdleConns),
|
||||
mysqlUtil.NewDBConfig(dbConfig.PlayerDB.ConnectionString, dbConfig.PlayerDB.MaxOpenConns, dbConfig.PlayerDB.MaxIdleConns),
|
||||
redisUtil.NewRedisConfig2(redisConfig.ConnectionString, redisConfig.Password, redisConfig.Database, redisConfig.MaxActive, redisConfig.MaxIdle, time.Duration(redisConfig.IdleTimeout)*time.Second, time.Duration(redisConfig.DialConnectTimeout)*time.Second))
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ import (
|
||||
var (
|
||||
adminDB *gorm.DB //管理员数据库对象
|
||||
userDB *gorm.DB //用户数据库对象
|
||||
payDB *gorm.DB //充值数据库对象
|
||||
gameModelDB *gorm.DB // 游戏模型数据库对象
|
||||
gameDB *gorm.DB // 游戏数据库
|
||||
gamePlayerDB *gorm.DB // 玩家库
|
||||
@ -53,6 +54,7 @@ func init() {
|
||||
//管理中心数据库配置
|
||||
adminDB = initMysql(config.GetDbConfig().GetAdminConfig())
|
||||
userDB = initMysql(config.GetDbConfig().GetUserConfig())
|
||||
payDB = initMysql(config.GetDbConfig().GetPayConfig())
|
||||
|
||||
// 初始化游戏模型数据库
|
||||
gameModelDBConfig := config.GetDbConfig().GetGameModelConfig()
|
||||
@ -146,6 +148,15 @@ func GetUserDB() *gorm.DB {
|
||||
return userDB
|
||||
}
|
||||
|
||||
// GetPayDB
|
||||
// @description: 获取pay库db实例
|
||||
// parameter:
|
||||
// return:
|
||||
// @*gorm.DB:pay库db实例
|
||||
func GetPayDB() *gorm.DB {
|
||||
return payDB
|
||||
}
|
||||
|
||||
// GetGameDB
|
||||
// @description: 获取game库db实例
|
||||
// parameter:
|
||||
|
||||
40
trunk/center/paycenter/Dockerfile
Normal file
40
trunk/center/paycenter/Dockerfile
Normal file
@ -0,0 +1,40 @@
|
||||
# 使用官方的 Go 镜像作为构建环境
|
||||
FROM golang:1.22.10-alpine AS builder
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 设置 Go 代理
|
||||
ENV GOPROXY=https://goproxy.cn,direct
|
||||
|
||||
# 禁用 CGO
|
||||
ENV CGO_ENABLED=0
|
||||
|
||||
# 复制所有源代码文件
|
||||
COPY . .
|
||||
|
||||
WORKDIR /app/admincenter
|
||||
|
||||
# 构建应用程序,并确认生成的文件
|
||||
RUN go build -o adminserver -ldflags="-s -w"
|
||||
|
||||
# 使用官方的 Alpine 镜像作为运行环境
|
||||
FROM alpine:latest
|
||||
|
||||
# 设置作者标签
|
||||
LABEL authors="tp"
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 从构建阶段复制编译好的可执行文件
|
||||
COPY --from=builder /app/admincenter/adminserver .
|
||||
|
||||
# 复制配置文件
|
||||
COPY --from=builder /app/admincenter/config.yaml .
|
||||
|
||||
# 暴露端口(假设 adminserver 监听 10051 端口)
|
||||
EXPOSE 10051
|
||||
|
||||
# 设置容器启动时运行 adminserver
|
||||
ENTRYPOINT ["./adminserver"]
|
||||
21
trunk/center/paycenter/buildLiunx.sh
Normal file
21
trunk/center/paycenter/buildLiunx.sh
Normal file
@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 设置 Go 环境变量,确保使用 Linux 架构
|
||||
export GOOS=linux
|
||||
export GOARCH=amd64
|
||||
|
||||
echo "开始编译..."
|
||||
|
||||
# 编译 Go 代码
|
||||
go build -o adminServer
|
||||
|
||||
# 检查编译是否成功
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "编译成功!"
|
||||
else
|
||||
echo "编译失败!"
|
||||
fi
|
||||
|
||||
# 等待用户输入任意键
|
||||
read -p "编译完成,按任意键继续..."
|
||||
exit 1
|
||||
54
trunk/center/paycenter/config.yaml
Normal file
54
trunk/center/paycenter/config.yaml
Normal file
@ -0,0 +1,54 @@
|
||||
# 配置根节点
|
||||
root:
|
||||
# 是否是调试模式
|
||||
debug: true
|
||||
|
||||
# Web服务监听地址和端口
|
||||
web_server_address: "192.168.50.85:10052"
|
||||
|
||||
# Elasticsearch 地址
|
||||
es_urls: "http://10.252.0.70:18099"
|
||||
|
||||
# 数据库配置
|
||||
db_config:
|
||||
admin_db:
|
||||
# 最大处于开启状态的连接数
|
||||
max_open_conns: 0
|
||||
|
||||
# 最大处于空闲状态的连接数
|
||||
max_idle_conns: 0
|
||||
|
||||
# 数据库连接字符串
|
||||
connection_string: "root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true"
|
||||
|
||||
user_db:
|
||||
# 最大处于开启状态的连接数
|
||||
max_open_conns: 0
|
||||
|
||||
# 最大处于空闲状态的连接数
|
||||
max_idle_conns: 0
|
||||
|
||||
# 数据库连接字符串
|
||||
connection_string: "root:Qq5201530300@tcp(192.168.50.110:3306)/pay?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true"
|
||||
|
||||
redis_config:
|
||||
# 数据库连接字符串
|
||||
connection_string: "192.168.50.110:6379"
|
||||
|
||||
# 密码, 如果要设置用户Id,则密码设置为:"UserId:Password"
|
||||
password: ""
|
||||
|
||||
# 数据库序号
|
||||
database: 5
|
||||
|
||||
# 最大活跃连接数
|
||||
max_active: 500
|
||||
|
||||
# 最大空闲的连接数
|
||||
max_idle: 200
|
||||
|
||||
# 连接空闲超时时间,单位:秒
|
||||
idle_timeout: 300
|
||||
|
||||
# 连接超时时间, 单位:秒
|
||||
dial_connect_timeout: 10
|
||||
37
trunk/center/paycenter/docker-compose.yml
Normal file
37
trunk/center/paycenter/docker-compose.yml
Normal file
@ -0,0 +1,37 @@
|
||||
version: '3'
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:8.0
|
||||
container_name: mysql-admin
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: 123456
|
||||
MYSQL_DATABASE: admin,pay
|
||||
volumes:
|
||||
- /my/own/datadir:/var/lib/mysql
|
||||
ports:
|
||||
- "3306:3306"
|
||||
redis:
|
||||
image: redis:7.0
|
||||
container_name: redis-admin
|
||||
ports:
|
||||
- "6379:6379"
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
restart: always
|
||||
command: ["redis-server", "--appendonly", "yes"]
|
||||
|
||||
admin-center:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: admin-center
|
||||
ports:
|
||||
- "10051:10051"
|
||||
volumes:
|
||||
- ./app:/app
|
||||
depends_on:
|
||||
- mysql
|
||||
- redis
|
||||
|
||||
volumes:
|
||||
redis_data:
|
||||
28
trunk/center/paycenter/dockerRun.sh
Normal file
28
trunk/center/paycenter/dockerRun.sh
Normal file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 导航到 Dockerfile 所在目录
|
||||
#cd D:\workspace\e2023\goProject\trunk\center\admincenter
|
||||
|
||||
# 构建 Docker 镜像
|
||||
echo "开始构建 Docker 镜像..."
|
||||
docker build -t adminserver-image .
|
||||
|
||||
# 检查构建是否成功
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "构建失败!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "镜像构建成功!"
|
||||
|
||||
# 运行 Docker 容器
|
||||
echo "开始运行 Docker 容器..."
|
||||
docker run -d -p 10051:10051 --name adminserver-container adminserver-image
|
||||
|
||||
# 检查容器是否成功运行
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "容器启动失败!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "容器启动成功!"
|
||||
@ -1,5 +1,39 @@
|
||||
module main.go
|
||||
module paycenter
|
||||
|
||||
go 1.22.10
|
||||
|
||||
require github.com/wechatpay-apiv3/wechatpay-go v0.2.20
|
||||
replace (
|
||||
common => ../common
|
||||
framework => ../../framework
|
||||
goutil => ../../goutil
|
||||
)
|
||||
|
||||
require (
|
||||
common v0.0.0-00010101000000-000000000000
|
||||
github.com/wechatpay-apiv3/wechatpay-go v0.2.20
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
goutil v0.0.0-20230425160006-b2d0b0a0b0b0
|
||||
)
|
||||
|
||||
require (
|
||||
filippo.io/edwards25519 v1.1.0 // indirect
|
||||
framework v0.0.0-20230425160006-b2d0b0a0b0b0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/elastic/go-elasticsearch/v8 v8.0.0-20210916085751-c2fb55d91ba4 // indirect
|
||||
github.com/fatih/color v1.15.0 // indirect
|
||||
github.com/go-redis/redis/v8 v8.11.5 // indirect
|
||||
github.com/go-sql-driver/mysql v1.8.1 // indirect
|
||||
github.com/gomodule/redigo v1.8.9 // indirect
|
||||
github.com/gorilla/websocket v1.4.2 // indirect
|
||||
github.com/jinzhu/gorm v1.9.12 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8 // indirect
|
||||
golang.org/x/sys v0.6.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
gorm.io/driver/mysql v1.5.7 // indirect
|
||||
gorm.io/gorm v1.25.12 // indirect
|
||||
)
|
||||
|
||||
@ -1,20 +1,99 @@
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
|
||||
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM=
|
||||
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/elastic/go-elasticsearch/v8 v8.0.0-20210916085751-c2fb55d91ba4 h1:OoL469zqSNrTLSz5zeVF/I6VOO7fiw2bzSzQe4J557c=
|
||||
github.com/elastic/go-elasticsearch/v8 v8.0.0-20210916085751-c2fb55d91ba4/go.mod h1:xe9a/L2aeOgFKKgrO3ibQTnMdpAeL0GC+5/HpGScSa4=
|
||||
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y=
|
||||
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
|
||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/gomodule/redigo v1.8.9 h1:Sl3u+2BI/kk+VEatbj0scLdrFhjPmbxOc1myhDP41ws=
|
||||
github.com/gomodule/redigo v1.8.9/go.mod h1:7ArFNvsTjH8GMMzB4uy1snslv2BwmginuMs06a1uzZE=
|
||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/jinzhu/gorm v1.9.12 h1:Drgk1clyWT9t9ERbzHza6Mj/8FY/CqMyVzOiHviMo6Q=
|
||||
github.com/jinzhu/gorm v1.9.12/go.mod h1:vhTjlKSJUTWNtcbQtrMBFCxy7eXTzeCAzfL5fBZT/Qs=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4=
|
||||
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
|
||||
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-sqlite3 v2.0.1+incompatible h1:xQ15muvnzGBHpIpdrNi1DA5x0+TcBZzsIDwmw9uTHzw=
|
||||
github.com/mattn/go-sqlite3 v2.0.1+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
|
||||
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/wechatpay-apiv3/wechatpay-go v0.2.20 h1:gS8oFn1bHGnyapR2Zb4aqTV6l4kJWgbtqjCq6k1L9DQ=
|
||||
github.com/wechatpay-apiv3/wechatpay-go v0.2.20/go.mod h1:A254AUBVB6R+EqQFo3yTgeh7HtyqRRtN2w9hQSOrd4Q=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd h1:GGJVjV8waZKRHrgwvtH66z9ZGVurTD1MT0n1Bb+q4aM=
|
||||
golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8 h1:/6y1LfuqNuQdHAm0jjtPtgRcxIxjVZgm5OTu8/QhZvk=
|
||||
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
|
||||
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
|
||||
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
|
||||
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
|
||||
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
|
||||
|
||||
216
trunk/center/paycenter/internal/pay.go
Normal file
216
trunk/center/paycenter/internal/pay.go
Normal file
@ -0,0 +1,216 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/app"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/utils"
|
||||
"goutil/logUtilPlus"
|
||||
"log"
|
||||
_ "paycenter/internal/pay"
|
||||
"paycenter/internal/wxpaycofnig"
|
||||
_ "paycenter/internal/wxpaycofnig"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
mchID string = wxpaycofnig.GetWxPayConfig().MchID // 商户号
|
||||
mchCertificateSerialNumber string = wxpaycofnig.GetWxPayConfig().MchCertificateSerialNumber // 商户证书序列号
|
||||
mchAPIv3Key string = wxpaycofnig.GetWxPayConfig().MchAPIv3Key // 商户APIv3密钥
|
||||
|
||||
)
|
||||
|
||||
// Prepay 预支付
|
||||
func Prepay(outTradeNo int64, description string) (string, error) {
|
||||
|
||||
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
|
||||
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
|
||||
if err != nil {
|
||||
logUtilPlus.ErrorLog("load merchant private key error")
|
||||
return "", err
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
|
||||
opts := []core.ClientOption{
|
||||
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
|
||||
}
|
||||
client, err := core.NewClient(ctx, opts...)
|
||||
if err != nil {
|
||||
logUtilPlus.ErrorLog("new wechat pay client err:%s", err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
svc := app.AppApiService{Client: client}
|
||||
resp, result, err := svc.Prepay(ctx,
|
||||
app.PrepayRequest{
|
||||
Appid: core.String("wxd678efh567hg6787"),
|
||||
Mchid: core.String("1230000109"),
|
||||
Description: core.String(description),
|
||||
OutTradeNo: core.String(strconv.FormatInt(outTradeNo, 10)),
|
||||
TimeExpire: core.Time(time.Now()),
|
||||
Attach: core.String("自定义数据说明"),
|
||||
NotifyUrl: core.String("https://www.weixin.qq.com/wxpay/pay.php"),
|
||||
GoodsTag: core.String("WXG"),
|
||||
LimitPay: []string{"LimitPay_example"},
|
||||
SupportFapiao: core.Bool(false),
|
||||
Amount: &app.Amount{
|
||||
Currency: core.String("CNY"),
|
||||
Total: core.Int64(100),
|
||||
},
|
||||
Detail: &app.Detail{
|
||||
CostPrice: core.Int64(608800),
|
||||
GoodsDetail: []app.GoodsDetail{app.GoodsDetail{
|
||||
GoodsName: core.String("iPhoneX 256G"),
|
||||
MerchantGoodsId: core.String("ABC"),
|
||||
Quantity: core.Int64(1),
|
||||
UnitPrice: core.Int64(828800),
|
||||
WechatpayGoodsId: core.String("1001"),
|
||||
}},
|
||||
InvoiceId: core.String("wx123"),
|
||||
},
|
||||
SceneInfo: &app.SceneInfo{
|
||||
DeviceId: core.String("013467007045764"),
|
||||
PayerClientIp: core.String("14.23.150.211"),
|
||||
StoreInfo: &app.StoreInfo{
|
||||
Address: core.String("广东省深圳市南山区科技中一道10000号"),
|
||||
AreaCode: core.String("440305"),
|
||||
Id: core.String("0001"),
|
||||
Name: core.String("腾讯大厦分店"),
|
||||
},
|
||||
},
|
||||
SettleInfo: &app.SettleInfo{
|
||||
ProfitSharing: core.Bool(false),
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
// 处理错误
|
||||
logUtilPlus.ErrorLog("call Prepay err:%s", err.Error())
|
||||
return "", err
|
||||
}
|
||||
|
||||
if result.Response.StatusCode != 200 {
|
||||
errStr := fmt.Sprintf("status=%d resp=%s", result.Response.StatusCode, resp)
|
||||
logUtilPlus.ErrorLog(errStr)
|
||||
return "", errors.New(errStr)
|
||||
}
|
||||
|
||||
return *resp.PrepayId, nil
|
||||
}
|
||||
|
||||
// CloseOrder 关闭订单
|
||||
func CloseOrder() {
|
||||
|
||||
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
|
||||
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
|
||||
if err != nil {
|
||||
log.Print("加载商家私钥错误")
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
|
||||
opts := []core.ClientOption{
|
||||
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
|
||||
}
|
||||
client, err := core.NewClient(ctx, opts...)
|
||||
if err != nil {
|
||||
log.Printf("新的 WeChat Pay 客户端 Err:%s", err)
|
||||
}
|
||||
|
||||
svc := app.AppApiService{Client: client}
|
||||
result, err := svc.CloseOrder(ctx,
|
||||
app.CloseOrderRequest{
|
||||
|
||||
//商户系统内部订单号,只能是数字、大小写字母_-*且在同一个商户号下唯
|
||||
OutTradeNo: core.String("OutTradeNo_example"),
|
||||
|
||||
//直连商户的商户号,由微信支付生成并下发。
|
||||
Mchid: core.String("1230000109"),
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
// 处理错误
|
||||
log.Printf("call CloseOrder err:%s", err)
|
||||
} else {
|
||||
// 处理返回结果
|
||||
log.Printf("status=%d", result.Response.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
// QueryOrderById 根据商户订单号查询订单
|
||||
func QueryOrderById() {
|
||||
|
||||
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
|
||||
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
|
||||
if err != nil {
|
||||
log.Print("load merchant private key error")
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
|
||||
opts := []core.ClientOption{
|
||||
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
|
||||
}
|
||||
client, err := core.NewClient(ctx, opts...)
|
||||
if err != nil {
|
||||
log.Printf("new wechat pay client err:%s", err)
|
||||
}
|
||||
|
||||
svc := app.AppApiService{Client: client}
|
||||
resp, result, err := svc.QueryOrderById(ctx,
|
||||
app.QueryOrderByIdRequest{
|
||||
TransactionId: core.String("TransactionId_example"),
|
||||
Mchid: core.String("Mchid_example"),
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
// 处理错误
|
||||
log.Printf("call QueryOrderById err:%s", err)
|
||||
} else {
|
||||
// 处理返回结果
|
||||
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
|
||||
}
|
||||
}
|
||||
|
||||
// QueryOrderByOutTradeNo 根据商户订单号查询订单
|
||||
func QueryOrderByOutTradeNo() {
|
||||
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
|
||||
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
|
||||
if err != nil {
|
||||
log.Print("load merchant private key error")
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
|
||||
opts := []core.ClientOption{
|
||||
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
|
||||
}
|
||||
client, err := core.NewClient(ctx, opts...)
|
||||
if err != nil {
|
||||
log.Printf("new wechat pay client err:%s", err)
|
||||
}
|
||||
|
||||
svc := app.AppApiService{Client: client}
|
||||
resp, result, err := svc.QueryOrderByOutTradeNo(ctx,
|
||||
app.QueryOrderByOutTradeNoRequest{
|
||||
OutTradeNo: core.String("OutTradeNo_example"),
|
||||
Mchid: core.String("Mchid_example"),
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
// 处理错误
|
||||
log.Printf("call QueryOrderByOutTradeNo err:%s", err)
|
||||
} else {
|
||||
// 处理返回结果
|
||||
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
|
||||
}
|
||||
}
|
||||
96
trunk/center/paycenter/internal/pay/api.go
Normal file
96
trunk/center/paycenter/internal/pay/api.go
Normal file
@ -0,0 +1,96 @@
|
||||
package pay
|
||||
|
||||
import (
|
||||
"common/remark"
|
||||
"common/resultStatus"
|
||||
"common/webServer"
|
||||
"goutil/intUtil"
|
||||
"paycenter/internal"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
//注册接口
|
||||
webServer.RegisterFunction(new(PayApi))
|
||||
}
|
||||
|
||||
func init() {
|
||||
moduleName := "PayApi"
|
||||
desc := "用户接口"
|
||||
author := "tangping"
|
||||
mendor := ""
|
||||
date := "2025年1月8日15:49:03"
|
||||
remark.RegisterModuleRemark(moduleName, desc, author, mendor, date)
|
||||
}
|
||||
|
||||
// PayApi 用户接口
|
||||
type PayApi struct {
|
||||
}
|
||||
|
||||
// ---------------------------------------- 接口 --------------------------------------------------
|
||||
func init() {
|
||||
moduleName := "PayApi"
|
||||
methodName := "PlaceAnOrder"
|
||||
skipVerifyTokenPage := true
|
||||
methodDesc := "下单"
|
||||
methodAuthor := "tangping"
|
||||
methodMendor := ""
|
||||
methodDate := "2025年1月8日15:51:34"
|
||||
methodInParam := []string{"int32:充值模版id,string:玩家id,int32:区服id"}
|
||||
methodOutParam := `
|
||||
{
|
||||
"Code '类型:int'": "响应结果的状态值",
|
||||
"Message '类型:string'": "响应结果的状态值所对应的描述信息",
|
||||
"Data '类型:interface{}'": "响应结果的数据"
|
||||
{
|
||||
"OrderID '类型:int64'": "订单id",
|
||||
"prepayId '类型:int64'": "预支付会话id",
|
||||
}
|
||||
}`
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
|
||||
}
|
||||
func (a *PayApi) PlaceAnOrder(modelID int32, playerID string, serverID int64) (responseObj *webServer.ResponseObject) {
|
||||
responseObj = webServer.GetInitResponseObj()
|
||||
|
||||
//校验参数
|
||||
if modelID == 0 || playerID == "" || serverID == 0 {
|
||||
responseObj.SetResultStatus(resultStatus.APIDataError)
|
||||
return
|
||||
}
|
||||
|
||||
//获取对应充值配置
|
||||
|
||||
orderId, err := intUtil.ShuffleIntDigits(time.Now().UnixNano())
|
||||
if err != nil {
|
||||
responseObj.SetResultStatus(resultStatus.DataError)
|
||||
return
|
||||
}
|
||||
|
||||
//下微信订单
|
||||
prepayId, err := internal.Prepay(orderId, "描述!!!!!!!!!!")
|
||||
if err != nil {
|
||||
responseObj.SetResultStatus(resultStatus.APIDataError)
|
||||
return
|
||||
}
|
||||
//处理数据
|
||||
order := &Order{
|
||||
OrderID: orderId,
|
||||
PrepayId: prepayId,
|
||||
OrderMoney: 100,
|
||||
OrderStatus: 1,
|
||||
PlayerID: playerID,
|
||||
ServerID: serverID,
|
||||
UserID: playerID,
|
||||
OrderDate: time.Now(),
|
||||
}
|
||||
|
||||
//添加到数据库
|
||||
AddOrder(order)
|
||||
|
||||
resultMap := make(map[string]any)
|
||||
resultMap["orderID"] = order.OrderID
|
||||
resultMap["prepayId"] = order.PrepayId
|
||||
responseObj.SetData(resultMap)
|
||||
return
|
||||
}
|
||||
69
trunk/center/paycenter/internal/pay/logic.go
Normal file
69
trunk/center/paycenter/internal/pay/logic.go
Normal file
@ -0,0 +1,69 @@
|
||||
package pay
|
||||
|
||||
import (
|
||||
"common/connection"
|
||||
"goutil/logUtilPlus"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
// 用户缓存对象
|
||||
orderMap = make(map[int64]*Order)
|
||||
rwmu sync.RWMutex
|
||||
)
|
||||
|
||||
// GetUserByID 根据用户id获取用户信息
|
||||
func GetUserByID(orderID int64) (*Order, error) {
|
||||
|
||||
//判断缓存是否存在
|
||||
var order *Order
|
||||
|
||||
func() *Order {
|
||||
rwmu.RLock()
|
||||
defer rwmu.RUnlock()
|
||||
ok := true
|
||||
if order, ok = orderMap[orderID]; ok {
|
||||
return order
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
|
||||
if order != nil {
|
||||
return order, nil
|
||||
}
|
||||
|
||||
result := connection.GetPayDB().First(&order, orderID)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
|
||||
//添加缓存
|
||||
func() {
|
||||
rwmu.Lock()
|
||||
defer rwmu.Unlock()
|
||||
orderMap[order.OrderID] = order
|
||||
}()
|
||||
|
||||
return order, nil
|
||||
}
|
||||
|
||||
// AddUserCache 添加用户缓存
|
||||
func AddUserCache(order *Order) {
|
||||
rwmu.Lock()
|
||||
defer rwmu.Unlock()
|
||||
orderMap[order.OrderID] = order
|
||||
}
|
||||
|
||||
// AddOrder 添加订单
|
||||
func AddOrder(order *Order) (int64, error) {
|
||||
|
||||
//处理一些验证
|
||||
|
||||
// 写入到数据库
|
||||
result := connection.GetPayDB().Create(&order) // 通过数据的指针来创建
|
||||
if result.Error != nil {
|
||||
logUtilPlus.ErrorLog("添加支付订单失败 错误信息:", result.Error.Error())
|
||||
}
|
||||
|
||||
return order.OrderID, nil
|
||||
}
|
||||
34
trunk/center/paycenter/internal/pay/order.go
Normal file
34
trunk/center/paycenter/internal/pay/order.go
Normal file
@ -0,0 +1,34 @@
|
||||
package pay
|
||||
|
||||
import (
|
||||
"common/connection"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
//注册数据库
|
||||
connection.RegisterDBModel(&Order{})
|
||||
}
|
||||
|
||||
type Order struct {
|
||||
//订单id
|
||||
OrderID int64 `gorm:"column:order_id;primary_key;comment:订单id" json:"order_id"`
|
||||
//订单日期
|
||||
OrderDate time.Time `gorm:"column:order_date;comment:订单日期" json:"order_date"`
|
||||
//订单号
|
||||
PrepayId string `gorm:"column:prepay_id;comment:预支付交易会话标识" json:"prepay_id"`
|
||||
//订单金额
|
||||
OrderMoney int64 `gorm:"column:order_money;comment:订单金额" json:"order_money"`
|
||||
//订单状态
|
||||
OrderStatus int32 `gorm:"column:order_status;comment:订单状态" json:"order_status"`
|
||||
//用户id
|
||||
UserID string `gorm:"column:user_id;comment:用户id" json:"user_id"`
|
||||
//区服id
|
||||
ServerID int64 `gorm:"column:server_id;comment:区服id" json:"server_id"`
|
||||
//玩家标识
|
||||
PlayerID string `gorm:"column:player_id;comment:玩家标识" json:"player_id"`
|
||||
}
|
||||
|
||||
func (order *Order) TableName() string {
|
||||
return "order"
|
||||
}
|
||||
62
trunk/center/paycenter/internal/wxpaycofnig/payconfig.go
Normal file
62
trunk/center/paycenter/internal/wxpaycofnig/payconfig.go
Normal file
@ -0,0 +1,62 @@
|
||||
package wxpaycofnig
|
||||
|
||||
import (
|
||||
"gopkg.in/yaml.v3"
|
||||
"goutil/yamlUtil"
|
||||
"log"
|
||||
)
|
||||
|
||||
type WxPayConfig struct {
|
||||
MchID string
|
||||
MchCertificateSerialNumber string
|
||||
MchAPIv3Key string
|
||||
}
|
||||
|
||||
var (
|
||||
wxPayConfig = &WxPayConfig{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
//加载配置
|
||||
reloadConfig()
|
||||
|
||||
//校验配置
|
||||
CheckConfig()
|
||||
}
|
||||
|
||||
// reloadConfig
|
||||
//
|
||||
// @description: reloadConfig
|
||||
//
|
||||
// parameter:
|
||||
// return:
|
||||
//
|
||||
// @error: 错误信息
|
||||
func reloadConfig() error {
|
||||
|
||||
yamlFile, err := yamlUtil.LoadFromFile("payconfig/wxpayconfig.yaml.yaml")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 解析 YAML 文件
|
||||
err = yaml.Unmarshal(yamlFile, wxPayConfig)
|
||||
if err != nil {
|
||||
log.Fatalf("Error unmarshalling config file: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckConfig 校验配置
|
||||
func CheckConfig() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetWxPayConfig 获取配置
|
||||
func GetWxPayConfig() *WxPayConfig {
|
||||
return wxPayConfig
|
||||
}
|
||||
@ -49,6 +49,7 @@ func main() {
|
||||
|
||||
// 使用微信扫描 resp.code_url 对应的二维码,即可体验Native支付
|
||||
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
|
||||
|
||||
svc1 := jsapi.JsapiApiService{Client: client}
|
||||
// 得到prepay_id,以及调起支付所需的参数和签名
|
||||
resp1, result, err := svc1.PrepayWithRequestPayment(ctx,
|
||||
|
||||
9
trunk/center/paycenter/payconfig/wxpayconfig.yaml
Normal file
9
trunk/center/paycenter/payconfig/wxpayconfig.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
#微信支付相关配置
|
||||
#商户id
|
||||
MchID: '1900000109'
|
||||
|
||||
#商户证书序列号
|
||||
MchCertificateSerialNumber: '3775D15B3B9A7F6D'
|
||||
|
||||
#商户APIv3密钥
|
||||
MchAPIv3Key: 'X5g0l1vL9kRvP0VB2WlhtyVwqEG9zvGf'
|
||||
20
trunk/center/paycenter/run.sh
Normal file
20
trunk/center/paycenter/run.sh
Normal file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 赋予可执行权限
|
||||
chmod +x adminServer
|
||||
|
||||
echo "启动中..."
|
||||
|
||||
# 接受命令行传入一个参数
|
||||
case "$1" in
|
||||
d)
|
||||
# 使用 nohup 将进程放到后台运行,并将输出重定向到 nohup.out 文件
|
||||
nohup ./adminServer > nohup.out 2>&1 &
|
||||
echo "启动完成"
|
||||
;;
|
||||
*)
|
||||
./adminServer
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "启动完成"
|
||||
16
trunk/center/paycenter/stop.sh
Normal file
16
trunk/center/paycenter/stop.sh
Normal file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 查找 adminServer 的 PID
|
||||
PID=$(pgrep adminServer)
|
||||
|
||||
if [ -z "$PID" ]; then
|
||||
echo "adminServer 进程未找到"
|
||||
else
|
||||
echo "停止中... (PID: $PID)"
|
||||
kill $PID
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "adminServer 进程已终止 (PID: $PID)"
|
||||
else
|
||||
echo "无法终止 adminServer 进程 (PID: $PID)"
|
||||
fi
|
||||
fi
|
||||
@ -29,7 +29,7 @@ root:
|
||||
max_idle_conns: 0
|
||||
|
||||
# 数据库连接字符串
|
||||
connection_string: "root:Qq5201530300@tcp(192.168.50.110:3306)/user?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true"
|
||||
connection_string: "root:Qq5201530300@tcp(192.168.50.110:3306)/pay?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true"
|
||||
|
||||
redis_config:
|
||||
# 数据库连接字符串
|
||||
|
||||
@ -5,7 +5,7 @@ services:
|
||||
container_name: mysql-admin
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: 123456
|
||||
MYSQL_DATABASE: admin,user
|
||||
MYSQL_DATABASE: admin,pay
|
||||
volumes:
|
||||
- /my/own/datadir:/var/lib/mysql
|
||||
ports:
|
||||
|
||||
@ -17,5 +17,5 @@ type Game struct {
|
||||
}
|
||||
|
||||
func (Game) TableName() string {
|
||||
return "user"
|
||||
return "pay"
|
||||
}
|
||||
|
||||
@ -32,5 +32,5 @@ type User struct {
|
||||
}
|
||||
|
||||
func (User) TableName() string {
|
||||
return "user"
|
||||
return "pay"
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user