一波更新
This commit is contained in:
Binary file not shown.
@@ -1,48 +0,0 @@
|
||||
2025-01-03 10:17:22---->
|
||||
开始加载DbConfig
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:17:22---->
|
||||
开始加载LogMgr
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:21:53---->
|
||||
开始加载DbConfig
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:21:53---->
|
||||
开始加载LogMgr
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:26:46---->
|
||||
开始加载DbConfig
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:26:46---->
|
||||
开始加载LogMgr
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:18---->
|
||||
开始加载DbConfig
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:18---->
|
||||
开始加载LogMgr
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:57---->
|
||||
开始加载DbConfig
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:57---->
|
||||
开始加载LogMgr
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:28:06---->
|
||||
开始加载DbConfig
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:28:06---->
|
||||
开始加载LogMgr
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:30:37---->
|
||||
开始加载DbConfig
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:30:37---->
|
||||
开始加载LogMgr
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:31:16---->
|
||||
开始加载DbConfig
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:31:16---->
|
||||
开始加载LogMgr
|
||||
------------------------------------------------------
|
||||
@@ -1,165 +0,0 @@
|
||||
2025-01-03 10:17:22---->
|
||||
开始连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:17:22---->
|
||||
连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true成功
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:17:22---->
|
||||
开始连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:17:22---->
|
||||
连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true成功
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:17:22---->
|
||||
ping->redis:192.168.50.110:6379成功,信息为:PONG
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:17:22---->
|
||||
Web服务器开始监听:192.168.50.85:10052
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:17:32---->
|
||||
monitorNewMgr没有初始化参数,请调用SetParam进行初始化
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:21:53---->
|
||||
开始连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:21:53---->
|
||||
连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true成功
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:21:53---->
|
||||
开始连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:21:53---->
|
||||
连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true成功
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:21:53---->
|
||||
ping->redis:192.168.50.110:6379成功,信息为:PONG
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:21:53---->
|
||||
Web服务器开始监听:192.168.50.85:10052
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:22:03---->
|
||||
monitorNewMgr没有初始化参数,请调用SetParam进行初始化
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:26:46---->
|
||||
开始连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:26:46---->
|
||||
连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true成功
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:26:46---->
|
||||
开始连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:26:46---->
|
||||
连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true成功
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:26:46---->
|
||||
ping->redis:192.168.50.110:6379成功,信息为:PONG
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:26:46---->
|
||||
Web服务器开始监听:192.168.50.85:10052
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:26:56---->
|
||||
monitorNewMgr没有初始化参数,请调用SetParam进行初始化
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:18---->
|
||||
开始连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:18---->
|
||||
连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true成功
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:18---->
|
||||
开始连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:18---->
|
||||
连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true成功
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:18---->
|
||||
ping->redis:192.168.50.110:6379成功,信息为:PONG
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:18---->
|
||||
Web服务器开始监听:192.168.50.85:10052
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:28---->
|
||||
monitorNewMgr没有初始化参数,请调用SetParam进行初始化
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:57---->
|
||||
开始连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:57---->
|
||||
连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true成功
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:57---->
|
||||
开始连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:57---->
|
||||
连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true成功
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:57---->
|
||||
ping->redis:192.168.50.110:6379成功,信息为:PONG
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:27:57---->
|
||||
Web服务器开始监听:192.168.50.85:10052
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:28:06---->
|
||||
开始连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:28:06---->
|
||||
连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true成功
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:28:06---->
|
||||
开始连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:28:06---->
|
||||
连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true成功
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:28:06---->
|
||||
ping->redis:192.168.50.110:6379成功,信息为:PONG
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:28:56---->
|
||||
monitorNewMgr没有初始化参数,请调用SetParam进行初始化
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:30:02---->
|
||||
Web服务器开始监听:192.168.50.85:10052
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:30:37---->
|
||||
开始连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:30:37---->
|
||||
连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true成功
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:30:42---->
|
||||
开始连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:30:42---->
|
||||
连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true成功
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:31:04---->
|
||||
monitorNewMgr没有初始化参数,请调用SetParam进行初始化
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:31:04---->
|
||||
ping->redis:192.168.50.110:6379成功,信息为:PONG
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:31:04---->
|
||||
Web服务器开始监听:192.168.50.85:10052
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:31:16---->
|
||||
开始连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:31:16---->
|
||||
连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/admin?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true成功
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:31:19---->
|
||||
开始连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/user?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:31:19---->
|
||||
连接mysql:root:Qq5201530300@tcp(192.168.50.110:3306)/user?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true成功
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:31:19---->
|
||||
ping->redis:192.168.50.110:6379成功,信息为:PONG
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:31:21---->
|
||||
Web服务器开始监听:192.168.50.85:10052
|
||||
------------------------------------------------------
|
||||
2025-01-03 10:31:26---->
|
||||
monitorNewMgr没有初始化参数,请调用SetParam进行初始化
|
||||
------------------------------------------------------
|
||||
@@ -4,13 +4,15 @@ root:
|
||||
debug: true
|
||||
|
||||
# Web服务监听地址和端口
|
||||
web_server_address: "192.168.50.85:10052"
|
||||
web_server_address: "192.168.50.169:10052"
|
||||
|
||||
# Elasticsearch 地址
|
||||
es_urls: "http://10.252.0.70:18099"
|
||||
|
||||
|
||||
# 数据库配置
|
||||
db_config:
|
||||
|
||||
admin_db:
|
||||
# 最大处于开启状态的连接数
|
||||
max_open_conns: 0
|
||||
@@ -29,7 +31,7 @@ root:
|
||||
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"
|
||||
connection_string: "root:Qq5201530300@tcp(192.168.50.110:3306)/user?charset=utf8&parseTime=true&loc=Local&timeout=30s&multiStatements=true"
|
||||
|
||||
redis_config:
|
||||
# 数据库连接字符串
|
||||
@@ -51,4 +53,12 @@ root:
|
||||
idle_timeout: 300
|
||||
|
||||
# 连接超时时间, 单位:秒
|
||||
dial_connect_timeout: 10
|
||||
dial_connect_timeout: 10
|
||||
|
||||
# 微信相关配置
|
||||
wx_config:
|
||||
|
||||
# 微信移动应用appId
|
||||
appId: "45678"
|
||||
# 微信移动应用appSecret
|
||||
appSecret: "954821"
|
||||
|
||||
@@ -29,10 +29,11 @@ require (
|
||||
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
|
||||
github.com/streadway/amqp v1.1.0 // 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
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
gorm.io/driver/mysql v1.5.7 // indirect
|
||||
gorm.io/gorm v1.25.12 // indirect
|
||||
)
|
||||
|
||||
@@ -53,6 +53,8 @@ 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/streadway/amqp v1.1.0 h1:py12iX8XSyI7aN/3dUT8DFIDJazNJsVJdxNVEpnQTZM=
|
||||
github.com/streadway/amqp v1.1.0/go.mod h1:WYSrTEYHOXHd0nwFeUXAe2G2hRnQT+deZJJf88uS9Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||
@@ -80,8 +82,9 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep
|
||||
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 h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
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=
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"common/remark"
|
||||
"common/resultStatus"
|
||||
"common/webServer"
|
||||
"logincenter/internal/user"
|
||||
"usercenter/internal/user"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"common/cache"
|
||||
"common/connection"
|
||||
"goutil/logUtilPlus"
|
||||
. "logincenter/internal/user"
|
||||
"sync"
|
||||
. "usercenter/internal/user"
|
||||
)
|
||||
|
||||
// 包名称(功能名称)
|
||||
@@ -32,7 +32,7 @@ func AddGame(user *User, game *Game) (int64, error) {
|
||||
}()
|
||||
|
||||
//写入缓存
|
||||
cache.SetData[*Game](user.Cache, packageName, gameMap)
|
||||
cache.SetData(user.Cache, packageName, gameMap)
|
||||
|
||||
// 写入到数据库
|
||||
result := connection.GetUserDB().Create(&game) // 通过数据的指针来创建
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
_ "logincenter/internal/game"
|
||||
_ "logincenter/internal/user"
|
||||
_ "usercenter/internal/game"
|
||||
_ "usercenter/internal/user"
|
||||
_ "usercenter/internal/wxuser"
|
||||
)
|
||||
|
||||
@@ -32,5 +32,5 @@ type User struct {
|
||||
}
|
||||
|
||||
func (User) TableName() string {
|
||||
return "pay"
|
||||
return "user"
|
||||
}
|
||||
|
||||
164
trunk/center/usercenter/internal/wxuser/api.go
Normal file
164
trunk/center/usercenter/internal/wxuser/api.go
Normal file
@@ -0,0 +1,164 @@
|
||||
package wxuser
|
||||
|
||||
import (
|
||||
"common/remark"
|
||||
"common/resultStatus"
|
||||
"common/webServer"
|
||||
"goutil/logUtilPlus"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
//注册接口
|
||||
webServer.RegisterFunction(new(WxuserApi))
|
||||
}
|
||||
|
||||
func init() {
|
||||
moduleName := "WxuserApi"
|
||||
desc := "用户接口"
|
||||
author := "youjinlan"
|
||||
mendor := ""
|
||||
date := "2025-12-21 09:40:00"
|
||||
remark.RegisterModuleRemark(moduleName, desc, author, mendor, date)
|
||||
}
|
||||
|
||||
// UserApi 用户接口
|
||||
type WxuserApi struct {
|
||||
}
|
||||
|
||||
// ---------------------------------------- 接口 --------------------------------------------------
|
||||
func init() {
|
||||
moduleName := "WxuserApi"
|
||||
methodName := "LoginByWechat"
|
||||
skipVerifyTokenPage := true
|
||||
methodDesc := "微信登录"
|
||||
methodAuthor := "youjinlan"
|
||||
methodMendor := ""
|
||||
methodDate := "2025-01-21 09:40:00"
|
||||
methodInParam := []string{"string code int32 severId"}
|
||||
methodOutParam := `
|
||||
{
|
||||
"Code '类型:int'": "响应结果的状态值",
|
||||
"Message '类型:string'": "响应结果的状态值所对应的描述信息",
|
||||
"Data '类型:interface{}'": "响应结果的数据"
|
||||
{
|
||||
"Uid '类型:int64'": "用户对应区服的唯一Id",
|
||||
}
|
||||
}`
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
|
||||
}
|
||||
func (a *WxuserApi) LoginByWechat(code string, severId int32) (responseObj *webServer.ResponseObject) {
|
||||
responseObj = webServer.GetInitResponseObj()
|
||||
if code == "" {
|
||||
logUtilPlus.ErrorLog("Wrongcode,code为空")
|
||||
responseObj.SetResultStatus(resultStatus.APIDataError)
|
||||
return
|
||||
}
|
||||
res, uid := GetWechatsdkService().GetAccessToken(code)
|
||||
if res != resultStatus.Success {
|
||||
responseObj.SetResultStatus(res)
|
||||
}
|
||||
if uid != 0 {
|
||||
resultMap := make(map[string]any)
|
||||
resultMap["Uid"] = uid
|
||||
responseObj.SetData(resultMap)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func init() {
|
||||
moduleName := "WxuserApi"
|
||||
methodName := "LoginOut"
|
||||
skipVerifyTokenPage := true
|
||||
methodDesc := "下线通知"
|
||||
methodAuthor := "youjinlan"
|
||||
methodMendor := ""
|
||||
methodDate := "2025-01-21 11:00:00"
|
||||
methodInParam := []string{"string openid,int32 severId"}
|
||||
methodOutParam := `
|
||||
{
|
||||
"Code '类型:int'": "响应结果的状态值",
|
||||
"Message '类型:string'": "响应结果的状态值所对应的描述信息",
|
||||
"Data '类型:interface{}'": "响应结果的数据"
|
||||
{
|
||||
|
||||
}
|
||||
}`
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
|
||||
}
|
||||
|
||||
func (a *WxuserApi) LoginOut(uid int64) (responseObj *webServer.ResponseObject) {
|
||||
responseObj = webServer.GetInitResponseObj()
|
||||
if uid == 0 {
|
||||
logUtilPlus.ErrorLog("uid=0")
|
||||
responseObj.SetResultStatus(resultStatus.APIDataError)
|
||||
return
|
||||
}
|
||||
RecordLoginOut(uid)
|
||||
return
|
||||
}
|
||||
|
||||
func init() {
|
||||
moduleName := "WxuserApi"
|
||||
methodName := "SwitchSever"
|
||||
skipVerifyTokenPage := true
|
||||
methodDesc := "切服通知"
|
||||
methodAuthor := "youjinlan"
|
||||
methodMendor := ""
|
||||
methodDate := "2025-01-21 14:40:00"
|
||||
methodInParam := []string{"string openid,int32 oldseverId,int32 newseverId"}
|
||||
methodOutParam := `
|
||||
{
|
||||
"Code '类型:int'": "响应结果的状态值",
|
||||
"Message '类型:string'": "响应结果的状态值所对应的描述信息",
|
||||
"Data '类型:interface{}'": "响应结果的数据"
|
||||
{
|
||||
|
||||
}
|
||||
}`
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
|
||||
}
|
||||
|
||||
func (a *WxuserApi) SwitchSever(uid int64, oldseverId, newseverId int32) (responseObj *webServer.ResponseObject) {
|
||||
responseObj = webServer.GetInitResponseObj()
|
||||
if uid == 0 {
|
||||
logUtilPlus.ErrorLog("uid=0")
|
||||
responseObj.SetResultStatus(resultStatus.APIDataError)
|
||||
return
|
||||
}
|
||||
// RecordLoginOut(openid, oldseverId)
|
||||
// RecordLoginIn(openid, newseverId)
|
||||
return
|
||||
}
|
||||
|
||||
func init() {
|
||||
moduleName := "WxuserApi"
|
||||
methodName := "WatchAD"
|
||||
skipVerifyTokenPage := true
|
||||
methodDesc := "看广告通知"
|
||||
methodAuthor := "youjinlan"
|
||||
methodMendor := ""
|
||||
methodDate := "2025-01-22 10:40:00"
|
||||
methodInParam := []string{"string openid,int32 severId"}
|
||||
methodOutParam := `
|
||||
{
|
||||
"Code '类型:int'": "响应结果的状态值",
|
||||
"Message '类型:string'": "响应结果的状态值所对应的描述信息",
|
||||
"Data '类型:interface{}'": "响应结果的数据"
|
||||
{
|
||||
|
||||
}
|
||||
}`
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
|
||||
}
|
||||
|
||||
func (a *WxuserApi) WatchAD(uid int64) (responseObj *webServer.ResponseObject) {
|
||||
responseObj = webServer.GetInitResponseObj()
|
||||
if uid == 0 {
|
||||
logUtilPlus.ErrorLog("openid,openid为空")
|
||||
responseObj.SetResultStatus(resultStatus.APIDataError)
|
||||
return
|
||||
}
|
||||
RecordWatchAD(uid)
|
||||
return
|
||||
}
|
||||
217
trunk/center/usercenter/internal/wxuser/logic.go
Normal file
217
trunk/center/usercenter/internal/wxuser/logic.go
Normal file
@@ -0,0 +1,217 @@
|
||||
package wxuser
|
||||
|
||||
import (
|
||||
"common/connection"
|
||||
"goutil/logUtilPlus"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
// 用户缓存对象
|
||||
userInfoMap = make(map[string]*WxUserInfo)
|
||||
rwmu sync.RWMutex
|
||||
userRecordMap = make(map[int64]*RecordLoginOfWxUser)
|
||||
rwmu2 sync.RWMutex
|
||||
userADRecordMap = make(map[int64]*RecordWatchADOfWxUser)
|
||||
rwmu3 sync.RWMutex
|
||||
)
|
||||
|
||||
func GetUserByOpenId(openId string) (*WxUserInfo, error) {
|
||||
var userInfo *WxUserInfo
|
||||
func() *WxUserInfo {
|
||||
rwmu.RLock()
|
||||
defer rwmu.RUnlock()
|
||||
ok := true
|
||||
if userInfo, ok = userInfoMap[openId]; ok {
|
||||
return userInfo
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
if userInfo != nil {
|
||||
return userInfo, nil
|
||||
}
|
||||
result := connection.GetUserDB().Where("openId = ?", openId).First(&userInfo)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
return userInfo, nil
|
||||
}
|
||||
|
||||
// AddUser 添加用户
|
||||
// AddUser 添加新的用户到数据库中。
|
||||
// 参数 User: 包含用户信息的对象。
|
||||
func AddUser(user *WxUserInfo) {
|
||||
|
||||
//处理一些验证
|
||||
|
||||
// 写入到数据库
|
||||
result := connection.GetUserDB().Create(&user) // 通过数据的指针来创建
|
||||
if result.Error != nil {
|
||||
logUtilPlus.ErrorLog("添加用户失败 错误信息:", result.Error.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func AddUserCache(user *WxUserInfo) {
|
||||
rwmu.Lock()
|
||||
defer rwmu.Unlock()
|
||||
userInfoMap[user.OpenId] = user
|
||||
}
|
||||
|
||||
// 登录登出相关
|
||||
func AddUserRecordCache(userrecord *RecordLoginOfWxUser) {
|
||||
rwmu2.Lock()
|
||||
defer rwmu2.Unlock()
|
||||
userRecordMap[userrecord.Uid] = userrecord
|
||||
}
|
||||
|
||||
func GetUserRecord(uid int64) (*RecordLoginOfWxUser, error) {
|
||||
var userRecord *RecordLoginOfWxUser
|
||||
func() *RecordLoginOfWxUser {
|
||||
rwmu2.RLock()
|
||||
defer rwmu2.RUnlock()
|
||||
ok := true
|
||||
if userRecord, ok = userRecordMap[uid]; ok {
|
||||
return userRecord
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
if userRecord != nil {
|
||||
return userRecord, nil
|
||||
}
|
||||
result := connection.GetUserDB().Where("uid = ?", uid).Last(&userRecord)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
//添加缓存
|
||||
func() {
|
||||
rwmu2.Lock()
|
||||
defer rwmu2.Unlock()
|
||||
userRecordMap[userRecord.Uid] = userRecord
|
||||
}()
|
||||
return userRecord, nil
|
||||
}
|
||||
|
||||
func AddUserRecord(userrecord *RecordLoginOfWxUser) (int64, error) {
|
||||
|
||||
//处理一些验证
|
||||
|
||||
// 写入到数据库
|
||||
result := connection.GetUserDB().Create(&userrecord) // 通过数据的指针来创建
|
||||
if result.Error != nil {
|
||||
logUtilPlus.ErrorLog("添加用户记录失败 错误信息:", result.Error.Error())
|
||||
}
|
||||
return userrecord.ID, nil
|
||||
}
|
||||
|
||||
func SaveUserRecord(userrecord *RecordLoginOfWxUser) (int64, error) {
|
||||
|
||||
//处理一些验证
|
||||
|
||||
// 写入到数据库
|
||||
result := connection.GetUserDB().Save(&userrecord) // 通过数据的指针来创建
|
||||
if result.Error != nil {
|
||||
logUtilPlus.ErrorLog("保存用户记录失败 错误信息:", result.Error.Error())
|
||||
}
|
||||
return userrecord.ID, nil
|
||||
}
|
||||
|
||||
// 看广告相关
|
||||
func AddUserADRecordCache(userADrecord *RecordWatchADOfWxUser) {
|
||||
rwmu3.Lock()
|
||||
defer rwmu3.Unlock()
|
||||
userADRecordMap[userADrecord.Uid] = userADrecord
|
||||
}
|
||||
|
||||
func GetUserADRecord(uid int64) (*RecordWatchADOfWxUser, error) {
|
||||
var userADRecord *RecordWatchADOfWxUser
|
||||
func() *RecordWatchADOfWxUser {
|
||||
rwmu3.RLock()
|
||||
defer rwmu3.RUnlock()
|
||||
ok := true
|
||||
if userADRecord, ok = userADRecordMap[uid]; ok {
|
||||
return userADRecord
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
if userADRecord != nil {
|
||||
return userADRecord, nil
|
||||
}
|
||||
result := connection.GetUserDB().Where("uid = ?", uid).Last(&userADRecord)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
//添加缓存
|
||||
func() {
|
||||
rwmu3.Lock()
|
||||
defer rwmu3.Unlock()
|
||||
userADRecordMap[userADRecord.Uid] = userADRecord
|
||||
}()
|
||||
return userADRecord, nil
|
||||
}
|
||||
|
||||
func AddUserADRecord(userADrecord *RecordWatchADOfWxUser) (int64, error) {
|
||||
|
||||
//处理一些验证
|
||||
|
||||
// 写入到数据库
|
||||
result := connection.GetUserDB().Create(&userADrecord) // 通过数据的指针来创建
|
||||
if result.Error != nil {
|
||||
logUtilPlus.ErrorLog("添加用户看广告记录失败 错误信息:", result.Error.Error())
|
||||
}
|
||||
return userADrecord.ID, nil
|
||||
}
|
||||
|
||||
func SaveUserADRecord(userADrecord *RecordWatchADOfWxUser) (int64, error) {
|
||||
|
||||
//处理一些验证
|
||||
|
||||
// 写入到数据库
|
||||
result := connection.GetUserDB().Save(&userADrecord) // 通过数据的指针来创建
|
||||
if result.Error != nil {
|
||||
logUtilPlus.ErrorLog("保存用户看广告记录失败 错误信息:", result.Error.Error())
|
||||
}
|
||||
return userADrecord.ID, nil
|
||||
}
|
||||
|
||||
// 区服相关
|
||||
func AddUserSeverInfo(userSeverInfo *WxUserSeverInfo) (int64, error) {
|
||||
|
||||
//处理一些验证
|
||||
|
||||
// 写入到数据库
|
||||
result := connection.GetUserDB().Create(&userSeverInfo) // 通过数据的指针来创建
|
||||
if result.Error != nil {
|
||||
logUtilPlus.ErrorLog("添加用户区服记录失败 错误信息:", result.Error.Error())
|
||||
}
|
||||
return userSeverInfo.ID, nil
|
||||
}
|
||||
|
||||
func SaveUserSeverInfo(userSeverInfo *WxUserSeverInfo) (int64, error) {
|
||||
|
||||
//处理一些验证
|
||||
|
||||
// 写入到数据库
|
||||
result := connection.GetUserDB().Save(&userSeverInfo) // 通过数据的指针来创建
|
||||
if result.Error != nil {
|
||||
logUtilPlus.ErrorLog("保存用户区服记录失败 错误信息:", result.Error.Error())
|
||||
}
|
||||
return userSeverInfo.ID, nil
|
||||
}
|
||||
|
||||
func GetUserSeverInfo() (*WxUserSeverInfo, error) {
|
||||
var userSeverInfoRecord *WxUserSeverInfo
|
||||
result := connection.GetUserDB().Last(&userSeverInfoRecord)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
return userSeverInfoRecord, nil
|
||||
}
|
||||
|
||||
func GetUserSeverInfoByIds(openId string, severId int32) (*WxUserSeverInfo, error) {
|
||||
var userSeverInfoRecord *WxUserSeverInfo
|
||||
result := connection.GetUserDB().Where("openId = ? AND severId = ?", openId, severId).First(&userSeverInfoRecord)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
return userSeverInfoRecord, nil
|
||||
}
|
||||
80
trunk/center/usercenter/internal/wxuser/user.go
Normal file
80
trunk/center/usercenter/internal/wxuser/user.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package wxuser
|
||||
|
||||
import (
|
||||
"common/connection"
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
func init() {
|
||||
//注册数据库
|
||||
connection.RegisterDBModel(&WxUserInfo{})
|
||||
connection.RegisterDBModel(&RecordLoginOfWxUser{})
|
||||
connection.RegisterDBModel(&RecordWatchADOfWxUser{})
|
||||
connection.RegisterDBModel(&WxUserSeverInfo{})
|
||||
}
|
||||
|
||||
type WechatTokens struct {
|
||||
Errcode int32 `json:"errcode"`
|
||||
Errmsg string `json:"errmsg"`
|
||||
AccessToken string `json:"access_token"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
ExpiresIn int64 `json:"expires_in"`
|
||||
OpenId string `json:"openid"`
|
||||
UnionId string `json:"unionid"`
|
||||
}
|
||||
|
||||
type WxUserInfo struct {
|
||||
Nickname string `gorm:"column:nickname;comment:昵称" json:"nickname"`
|
||||
Sex string `gorm:"column:sex;comment:性别" json:"sex"`
|
||||
Language int64 `gorm:"column:language;comment:语言" json:"language"`
|
||||
city string `gorm:"column:city;comment:城市" json:"city"`
|
||||
province string `gorm:"column:province;comment:省份" json:"province"`
|
||||
country string `gorm:"column:country;comment:国籍" json:"country"`
|
||||
headimgurl string `gorm:"column:headimgurl;comment:头像" json:"headimgurl"`
|
||||
OpenId string `gorm:"column:openId;comment:openId;primaryKey" json:"openid"`
|
||||
UnionId string `gorm:"column:unionId;comment:unionId" json:"unionid"`
|
||||
}
|
||||
|
||||
// 同一个玩家在不同的区服Uid是不同的
|
||||
type WxUserSeverInfo struct {
|
||||
ID int64 `gorm:"column:id;primary_key;comment:自增索引;autoIncrementIncrement" json:"id"`
|
||||
OpenId string `gorm:"column:openId;comment:openId" json:"openId"`
|
||||
SeverId int32 `gorm:"column:severId;comment:区服Id" json:"severId"`
|
||||
Uid int64 `gorm:"column:uid;comment:用户唯一Id" json:"uid"`
|
||||
}
|
||||
|
||||
// 登录相关的记录
|
||||
type RecordLoginOfWxUser struct {
|
||||
ID int64 `gorm:"column:id;primary_key;comment:自增索引;autoIncrementIncrement" json:"id"`
|
||||
Uid int64 `gorm:"column:uid;comment:用户唯一Id" json:"uid"`
|
||||
LoginInTime int64 `gorm:"column:loginintime;comment:登录时间" json:"loginintime"`
|
||||
LoginOutTime int64 `gorm:"column:loginouttime;comment:登出时间" json:"loginouttime"`
|
||||
PlayTimes int64 `gorm:"column:playtimes;comment:游玩时长" json:"playtimes"`
|
||||
}
|
||||
|
||||
// 看广告相关记录
|
||||
// 记录日期便于按天统计
|
||||
type RecordWatchADOfWxUser struct {
|
||||
ID int64 `gorm:"column:id;primary_key;comment:自增索引;autoIncrementIncrement" json:"id"`
|
||||
RecordDate time.Time `gorm:"column:recorddate;type:date;comment:记录日期" json:"recorddate"`
|
||||
Uid int64 `gorm:"column:uid;comment:用户唯一Id" json:"uid"`
|
||||
WatchADNum int32 `gorm:"column:watchadnum;comment:看广告次数" json:"watchadnum"`
|
||||
}
|
||||
|
||||
func (WxUserInfo) TableName() string {
|
||||
return "wxuserinfo"
|
||||
}
|
||||
|
||||
func (r RecordLoginOfWxUser) TableName(db *gorm.DB) string {
|
||||
return "recordloginofwxuser"
|
||||
}
|
||||
|
||||
func (RecordWatchADOfWxUser) TableName() string {
|
||||
return "recordwatchadofwxuser"
|
||||
}
|
||||
|
||||
func (WxUserSeverInfo) TableName() string {
|
||||
return "wxuserseverinfo"
|
||||
}
|
||||
80
trunk/center/usercenter/internal/wxuser/userrecord.go
Normal file
80
trunk/center/usercenter/internal/wxuser/userrecord.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package wxuser
|
||||
|
||||
import (
|
||||
"common/resultStatus"
|
||||
"goutil/logUtilPlus"
|
||||
"time"
|
||||
)
|
||||
|
||||
func RecordLoginIn(uid int64) {
|
||||
nowTime := time.Now().Unix()
|
||||
// if userLastRecord, _ := GetUserRecord(uid); userLastRecord != nil {
|
||||
// if userLastRecord.LoginOutTime == 0 {
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
userRecord := &RecordLoginOfWxUser{}
|
||||
userRecord.LoginInTime = nowTime
|
||||
AddUserRecord(userRecord)
|
||||
AddUserRecordCache(userRecord)
|
||||
}
|
||||
|
||||
func RecordLoginOut(uid int64) resultStatus.ResultStatus {
|
||||
var userRecord *RecordLoginOfWxUser
|
||||
if userRecord, _ = GetUserRecord(uid); userRecord == nil {
|
||||
return resultStatus.PlayerNotExist
|
||||
}
|
||||
if userRecord.LoginOutTime != 0 {
|
||||
logUtilPlus.ErrorLog("PlayerIsLoginOut,uid=%d", uid)
|
||||
return resultStatus.PlayerIsLoginOut
|
||||
}
|
||||
go func() {
|
||||
nowTime := time.Now().Unix()
|
||||
userRecord.LoginOutTime = nowTime
|
||||
playTime := nowTime - userRecord.LoginInTime
|
||||
userRecord.PlayTimes += playTime
|
||||
SaveUserRecord(userRecord)
|
||||
}()
|
||||
return resultStatus.Success
|
||||
}
|
||||
|
||||
func RecordWatchAD(uid int64) resultStatus.ResultStatus {
|
||||
nowTime := time.Now()
|
||||
userADRecord := &RecordWatchADOfWxUser{}
|
||||
if userLastADRecord, _ := GetUserADRecord(uid); userLastADRecord != nil {
|
||||
if nowTime.Format("2006-01-02") == userLastADRecord.RecordDate.Format("2006-01-02") {
|
||||
userLastADRecord.WatchADNum++
|
||||
SaveUserADRecord(userLastADRecord)
|
||||
return resultStatus.Success
|
||||
}
|
||||
}
|
||||
userADRecord.RecordDate = nowTime
|
||||
userADRecord.WatchADNum += 1
|
||||
AddUserADRecord(userADRecord)
|
||||
AddUserADRecordCache(userADRecord)
|
||||
return resultStatus.Success
|
||||
}
|
||||
|
||||
func CreatUid(openId string, severId int32) int64 {
|
||||
var lastId int64
|
||||
if userRecord, _ := GetUserSeverInfoByIds(openId, severId); userRecord != nil {
|
||||
return userRecord.Uid
|
||||
}
|
||||
if userLastRecord, _ := GetUserSeverInfo(); userLastRecord != nil {
|
||||
lastId = userLastRecord.ID
|
||||
}
|
||||
userSeverInfo := &WxUserSeverInfo{}
|
||||
userSeverInfo.OpenId = openId
|
||||
userSeverInfo.SeverId = severId
|
||||
userSeverInfo.Uid = lastId + 1 + 100000000
|
||||
AddUserSeverInfo(userSeverInfo)
|
||||
return userSeverInfo.Uid
|
||||
}
|
||||
|
||||
// func init() {
|
||||
// testRecordWatchAD()
|
||||
// }
|
||||
|
||||
func testRecordWatchAD() {
|
||||
//RecordWatchAD("hell)
|
||||
}
|
||||
82
trunk/center/usercenter/internal/wxuser/wechatsdkservice.go
Normal file
82
trunk/center/usercenter/internal/wxuser/wechatsdkservice.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package wxuser
|
||||
|
||||
import (
|
||||
configYaml "common/configsYaml"
|
||||
"common/resultStatus"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"goutil/logUtilPlus"
|
||||
"goutil/webUtil"
|
||||
)
|
||||
|
||||
const (
|
||||
Url = "https://api.weixin.qq.com/sns/"
|
||||
)
|
||||
|
||||
type WechatsdkService struct {
|
||||
}
|
||||
|
||||
// 通过code来换取assesstoken
|
||||
func (w *WechatsdkService) GetAccessToken(code string) (resultStatus.ResultStatus, int64) {
|
||||
weburl := fmt.Sprintf("%s%s", Url, "oauth2/access_token") //"https://api.weixin.qq.com/sns/oauth2/access_token"
|
||||
data := make(map[string]string)
|
||||
data["appid"] = configYaml.GetWxconfig().AppId
|
||||
data["secret"] = configYaml.GetWxconfig().AppSecret
|
||||
data["code"] = code
|
||||
data["grant_type"] = "authorization_code"
|
||||
status, resp, err := webUtil.GetWebData2(weburl, data, nil, nil)
|
||||
if status != 200 || err != nil {
|
||||
return resultStatus.RequestError, 0
|
||||
}
|
||||
|
||||
if len(resp) == 0 {
|
||||
logUtilPlus.ErrorLog("The result is empty, but we expect not empty")
|
||||
return resultStatus.EmptyResp, 0
|
||||
}
|
||||
logUtilPlus.ErrorLog("resp=%s", string(resp))
|
||||
tokens := &WechatTokens{}
|
||||
if err := json.Unmarshal(resp, tokens); err != nil {
|
||||
logUtilPlus.ErrorLog("Unmarshal is error, err:%s", err)
|
||||
return resultStatus.UnmarshalError, 0
|
||||
}
|
||||
if tokens.Errcode != 0 || tokens.Errmsg != "" {
|
||||
logUtilPlus.ErrorLog("errcode:%d, msg:%s,", tokens.Errcode, tokens.Errmsg)
|
||||
return resultStatus.RequestError, 0
|
||||
}
|
||||
Uid := CreatUid(tokens.OpenId, 1)
|
||||
go func() {
|
||||
if userInfo, _ := GetUserByOpenId(tokens.OpenId); userInfo == nil {
|
||||
w.GetUserInfo(tokens.AccessToken, tokens.OpenId)
|
||||
}
|
||||
}()
|
||||
go RecordLoginIn(Uid)
|
||||
return resultStatus.Success, Uid
|
||||
}
|
||||
|
||||
// 换取用户信息
|
||||
func (w *WechatsdkService) GetUserInfo(accessToken, openid string) {
|
||||
weburl := fmt.Sprintf("%s%s", Url, "userinfo") //"https://api.weixin.qq.com/sns/userinfo"
|
||||
data := make(map[string]string)
|
||||
data["appid"] = configYaml.GetWxconfig().AppId
|
||||
data["access_token"] = accessToken
|
||||
data["openid"] = openid
|
||||
status, resp, err := webUtil.GetWebData2(weburl, data, nil, nil)
|
||||
if status != 200 || err != nil {
|
||||
logUtilPlus.ErrorLog("Wrongstatus. status:%d, err:%s", status, err)
|
||||
}
|
||||
if len(resp) == 0 {
|
||||
logUtilPlus.ErrorLog("The result is empty, but we expect not empty")
|
||||
}
|
||||
var userInfo *WxUserInfo
|
||||
if err := json.Unmarshal(resp, userInfo); err != nil {
|
||||
logUtilPlus.ErrorLog("Unmarshal is error, err:%s", err)
|
||||
return
|
||||
}
|
||||
AddUser(userInfo)
|
||||
}
|
||||
|
||||
var wechatsdkservice *WechatsdkService
|
||||
|
||||
func GetWechatsdkService() *WechatsdkService {
|
||||
return wechatsdkservice
|
||||
}
|
||||
36
trunk/center/usercenter/internal/wxuser2/user.go
Normal file
36
trunk/center/usercenter/internal/wxuser2/user.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package wxuser2
|
||||
|
||||
import (
|
||||
"common/cache"
|
||||
"common/connection"
|
||||
)
|
||||
|
||||
func init() {
|
||||
//注册数据库
|
||||
connection.RegisterDBModel(&WXUserInfo{})
|
||||
}
|
||||
|
||||
type WXUserInfo struct {
|
||||
Openid string `gorm:"column:openid;comment:用户微信标识;autoIncrementIncrement" json:"openid"`
|
||||
//账号
|
||||
Account string `gorm:"column:account;comment:账号" json:"account"`
|
||||
Name string `gorm:"column:name;comment:用户名称" json:"name"`
|
||||
Password string `gorm:"column:password;comment:用户密码" json:"password"`
|
||||
//性别
|
||||
Sex int32 `gorm:"column:sex;comment:性别" json:"sex"`
|
||||
//生日
|
||||
Birthday string `gorm:"column:birthday;comment:生日" json:"birthday"`
|
||||
//手机
|
||||
Phone int64 `gorm:"column:phone;comment:手机" json:"phone"`
|
||||
//邮箱
|
||||
Email string `gorm:"column:email;comment:邮箱" json:"email"`
|
||||
//备注
|
||||
Describe string `gorm:"column:describe;comment:备注" json:"describe"`
|
||||
|
||||
//玩家的缓存对象
|
||||
Cache *cache.Cache `gorm:"-"`
|
||||
}
|
||||
|
||||
func (WXUserInfo) TableName() string {
|
||||
return "user"
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
_ "common/resultStatus"
|
||||
"common/webServer"
|
||||
_ "usercenter/internal/user"
|
||||
_ "usercenter/internal"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
Reference in New Issue
Block a user