支付宝 接入一系列修改
This commit is contained in:
@@ -54,7 +54,7 @@ func (a *WxuserApi) LoginByWechat(code string, severId int32) (responseObj *webS
|
||||
responseObj.SetResultStatus(resultStatus.APIDataError)
|
||||
return
|
||||
}
|
||||
res, uid := GetWechatsdkService().GetAccessToken(code)
|
||||
res, uid := GetWechatsdkService().GetAccessToken(code, severId)
|
||||
if res != resultStatus.Success {
|
||||
responseObj.SetResultStatus(res)
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func init() {
|
||||
"Message '类型:string'": "响应结果的状态值所对应的描述信息",
|
||||
"Data '类型:interface{}'": "响应结果的数据"
|
||||
{
|
||||
|
||||
"Uid '类型:int64'": "切服后的区服的唯一Id",
|
||||
}
|
||||
}`
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
|
||||
@@ -121,13 +121,17 @@ func init() {
|
||||
|
||||
func (a *WxuserApi) SwitchSever(uid int64, oldseverId, newseverId int32) (responseObj *webServer.ResponseObject) {
|
||||
responseObj = webServer.GetInitResponseObj()
|
||||
if uid == 0 {
|
||||
logUtilPlus.ErrorLog("uid=0")
|
||||
if uid == 0 || oldseverId == 0 || newseverId == 0 {
|
||||
logUtilPlus.ErrorLog("WxuserApi.SwitchSever参数不正确")
|
||||
responseObj.SetResultStatus(resultStatus.APIDataError)
|
||||
return
|
||||
}
|
||||
// RecordLoginOut(openid, oldseverId)
|
||||
// RecordLoginIn(openid, newseverId)
|
||||
if oldseverId == newseverId {
|
||||
logUtilPlus.ErrorLog("WxuserApi.SwitchSever参数不正确")
|
||||
responseObj.SetResultStatus(resultStatus.APIDataError)
|
||||
return
|
||||
}
|
||||
SwitchSever(uid, oldseverId, newseverId)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -139,7 +143,7 @@ func init() {
|
||||
methodAuthor := "youjinlan"
|
||||
methodMendor := ""
|
||||
methodDate := "2025-01-22 10:40:00"
|
||||
methodInParam := []string{"string openid,int32 severId"}
|
||||
methodInParam := []string{"int64 uid"}
|
||||
methodOutParam := `
|
||||
{
|
||||
"Code '类型:int'": "响应结果的状态值",
|
||||
@@ -155,7 +159,7 @@ func init() {
|
||||
func (a *WxuserApi) WatchAD(uid int64) (responseObj *webServer.ResponseObject) {
|
||||
responseObj = webServer.GetInitResponseObj()
|
||||
if uid == 0 {
|
||||
logUtilPlus.ErrorLog("openid,openid为空")
|
||||
logUtilPlus.ErrorLog("uid=0")
|
||||
responseObj.SetResultStatus(resultStatus.APIDataError)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ import (
|
||||
|
||||
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
|
||||
userInfoMap = make(map[string]*WxUserInfo)
|
||||
rwmu sync.RWMutex
|
||||
userRecordMap = make(map[int64]*RecordLoginOfWxUser)
|
||||
rwmu2 sync.RWMutex
|
||||
userADRecordMap = make(map[int64]*RecordWatchADOfWxUser)
|
||||
rwmu3 sync.RWMutex
|
||||
userSeverInfoMap = make(map[string]map[int32]int64)
|
||||
rwmu4 sync.RWMutex
|
||||
userUidMap = make(map[int64]*WxUserSeverInfo)
|
||||
rwmu5 sync.RWMutex
|
||||
)
|
||||
|
||||
func GetUserByOpenId(openId string) (*WxUserInfo, error) {
|
||||
@@ -58,12 +62,17 @@ func AddUserCache(user *WxUserInfo) {
|
||||
}
|
||||
|
||||
// 登录登出相关
|
||||
|
||||
|
||||
|
||||
// 添加用户登录登出表到缓存
|
||||
func AddUserRecordCache(userrecord *RecordLoginOfWxUser) {
|
||||
rwmu2.Lock()
|
||||
defer rwmu2.Unlock()
|
||||
userRecordMap[userrecord.Uid] = userrecord
|
||||
}
|
||||
|
||||
// 获取最新一条登录记录
|
||||
func GetUserRecord(uid int64) (*RecordLoginOfWxUser, error) {
|
||||
var userRecord *RecordLoginOfWxUser
|
||||
func() *RecordLoginOfWxUser {
|
||||
@@ -91,6 +100,7 @@ func GetUserRecord(uid int64) (*RecordLoginOfWxUser, error) {
|
||||
return userRecord, nil
|
||||
}
|
||||
|
||||
// 添加用户登录登出记录
|
||||
func AddUserRecord(userrecord *RecordLoginOfWxUser) (int64, error) {
|
||||
|
||||
//处理一些验证
|
||||
@@ -103,6 +113,7 @@ func AddUserRecord(userrecord *RecordLoginOfWxUser) (int64, error) {
|
||||
return userrecord.ID, nil
|
||||
}
|
||||
|
||||
// 保存添加用户登录登出记录
|
||||
func SaveUserRecord(userrecord *RecordLoginOfWxUser) (int64, error) {
|
||||
|
||||
//处理一些验证
|
||||
@@ -116,12 +127,17 @@ func SaveUserRecord(userrecord *RecordLoginOfWxUser) (int64, error) {
|
||||
}
|
||||
|
||||
// 看广告相关
|
||||
|
||||
|
||||
|
||||
// 添加用户看广告记录到缓存
|
||||
func AddUserADRecordCache(userADrecord *RecordWatchADOfWxUser) {
|
||||
rwmu3.Lock()
|
||||
defer rwmu3.Unlock()
|
||||
userADRecordMap[userADrecord.Uid] = userADrecord
|
||||
}
|
||||
|
||||
// 获取最新一条看广告记录
|
||||
func GetUserADRecord(uid int64) (*RecordWatchADOfWxUser, error) {
|
||||
var userADRecord *RecordWatchADOfWxUser
|
||||
func() *RecordWatchADOfWxUser {
|
||||
@@ -149,6 +165,7 @@ func GetUserADRecord(uid int64) (*RecordWatchADOfWxUser, error) {
|
||||
return userADRecord, nil
|
||||
}
|
||||
|
||||
// 添加用户看广告记录到数据库
|
||||
func AddUserADRecord(userADrecord *RecordWatchADOfWxUser) (int64, error) {
|
||||
|
||||
//处理一些验证
|
||||
@@ -161,6 +178,7 @@ func AddUserADRecord(userADrecord *RecordWatchADOfWxUser) (int64, error) {
|
||||
return userADrecord.ID, nil
|
||||
}
|
||||
|
||||
// 保存用户看广告记录到数据库
|
||||
func SaveUserADRecord(userADrecord *RecordWatchADOfWxUser) (int64, error) {
|
||||
|
||||
//处理一些验证
|
||||
@@ -174,6 +192,88 @@ func SaveUserADRecord(userADrecord *RecordWatchADOfWxUser) (int64, error) {
|
||||
}
|
||||
|
||||
// 区服相关
|
||||
|
||||
|
||||
|
||||
// 添加用户的区服信息到缓存 以openid为key的map
|
||||
func AddUserSeverInfoCache(openid string, severid int32, uid int64) {
|
||||
rwmu4.Lock()
|
||||
defer rwmu4.Unlock()
|
||||
newMap := make(map[int32]int64)
|
||||
newMap[severid] = uid
|
||||
if _, ok := userSeverInfoMap[openid]; !ok {
|
||||
userSeverInfoMap[openid] = newMap
|
||||
return
|
||||
}
|
||||
if _, ok := userSeverInfoMap[openid][severid]; !ok {
|
||||
userSeverInfoMap[openid][severid] = uid
|
||||
}
|
||||
}
|
||||
|
||||
// 添加用户的区服信息到缓存 以uid为key
|
||||
func AddUserUidCache(wxUserSeverInfo *WxUserSeverInfo) {
|
||||
rwmu5.Lock()
|
||||
defer rwmu5.Unlock()
|
||||
userUidMap[wxUserSeverInfo.Uid] = wxUserSeverInfo
|
||||
}
|
||||
|
||||
// 通过uid来获取用户的区服信息
|
||||
func GetUserSeverInfoByUid(uid int64) (*WxUserSeverInfo, error) {
|
||||
var userSeverInfoRecord *WxUserSeverInfo
|
||||
func() *WxUserSeverInfo {
|
||||
rwmu5.RLock()
|
||||
defer rwmu5.RUnlock()
|
||||
ok := true
|
||||
if userSeverInfoRecord, ok = userUidMap[uid]; ok {
|
||||
return userSeverInfoRecord
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
if userSeverInfoRecord == nil {
|
||||
result := connection.GetUserDB().Where("uid = ?", uid).First(&userSeverInfoRecord)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
}
|
||||
func() {
|
||||
rwmu5.Lock()
|
||||
defer rwmu5.Unlock()
|
||||
userUidMap[uid] = userSeverInfoRecord
|
||||
}()
|
||||
return userSeverInfoRecord, nil
|
||||
}
|
||||
|
||||
// 通过openid和severid来获取uid
|
||||
func GetUserUid(openId string, severId int32) (int64, error) {
|
||||
var uid int64
|
||||
func() int64 {
|
||||
rwmu4.RLock()
|
||||
defer rwmu4.RUnlock()
|
||||
ok := true
|
||||
if _, ok = userSeverInfoMap[openId]; !ok {
|
||||
return 0
|
||||
}
|
||||
if uid, ok = userSeverInfoMap[openId][severId]; ok {
|
||||
return uid
|
||||
}
|
||||
return 0
|
||||
}()
|
||||
if uid == 0 {
|
||||
var userSeverInfoRecord *WxUserSeverInfo
|
||||
result := connection.GetUserDB().Where("openId = ? AND severId = ?", openId, severId).First(&userSeverInfoRecord)
|
||||
if result.Error != nil {
|
||||
return 0, result.Error
|
||||
}
|
||||
if userSeverInfoRecord.Uid == 0 {
|
||||
userSeverInfoRecord.Uid = userSeverInfoRecord.ID + 100000000
|
||||
SaveUserSeverInfo(userSeverInfoRecord)
|
||||
}
|
||||
return userSeverInfoRecord.Uid, nil
|
||||
}
|
||||
return uid, nil
|
||||
}
|
||||
|
||||
// 添加用户区服信息到数据库
|
||||
func AddUserSeverInfo(userSeverInfo *WxUserSeverInfo) (int64, error) {
|
||||
|
||||
//处理一些验证
|
||||
@@ -186,6 +286,7 @@ func AddUserSeverInfo(userSeverInfo *WxUserSeverInfo) (int64, error) {
|
||||
return userSeverInfo.ID, nil
|
||||
}
|
||||
|
||||
// 保存用户区服信息到数据库
|
||||
func SaveUserSeverInfo(userSeverInfo *WxUserSeverInfo) (int64, error) {
|
||||
|
||||
//处理一些验证
|
||||
@@ -198,20 +299,25 @@ func SaveUserSeverInfo(userSeverInfo *WxUserSeverInfo) (int64, error) {
|
||||
return userSeverInfo.ID, nil
|
||||
}
|
||||
|
||||
func GetUserSeverInfo() (*WxUserSeverInfo, error) {
|
||||
var userSeverInfoRecord *WxUserSeverInfo
|
||||
result := connection.GetUserDB().Last(&userSeverInfoRecord)
|
||||
// 查询severid是否存在,即是否为新服
|
||||
func CheckSeverID(severid int32) bool {
|
||||
var userSeverList *WxUserSeverList
|
||||
result := connection.GetUserDB().Where("severId = ?", severid).First(&userSeverList)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
return false
|
||||
}
|
||||
return userSeverInfoRecord, nil
|
||||
return true
|
||||
}
|
||||
|
||||
func GetUserSeverInfoByIds(openId string, severId int32) (*WxUserSeverInfo, error) {
|
||||
var userSeverInfoRecord *WxUserSeverInfo
|
||||
result := connection.GetUserDB().Where("openId = ? AND severId = ?", openId, severId).First(&userSeverInfoRecord)
|
||||
// 添加新的severid到服务器列表
|
||||
func AddUserSeverList(userSeverList *WxUserSeverList) (int64, error) {
|
||||
|
||||
//处理一些验证
|
||||
|
||||
// 写入到数据库
|
||||
result := connection.GetUserDB().Create(&userSeverList) // 通过数据的指针来创建
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
logUtilPlus.ErrorLog("添加用户区服列表失败 错误信息:", result.Error.Error())
|
||||
}
|
||||
return userSeverInfoRecord, nil
|
||||
return userSeverList.ID, nil
|
||||
}
|
||||
|
||||
@@ -2,9 +2,6 @@ package wxuser
|
||||
|
||||
import (
|
||||
"common/connection"
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -13,6 +10,7 @@ func init() {
|
||||
connection.RegisterDBModel(&RecordLoginOfWxUser{})
|
||||
connection.RegisterDBModel(&RecordWatchADOfWxUser{})
|
||||
connection.RegisterDBModel(&WxUserSeverInfo{})
|
||||
connection.RegisterDBModel(&WxUserSeverList{})
|
||||
}
|
||||
|
||||
type WechatTokens struct {
|
||||
@@ -45,29 +43,40 @@ type WxUserSeverInfo struct {
|
||||
Uid int64 `gorm:"column:uid;comment:用户唯一Id" json:"uid"`
|
||||
}
|
||||
|
||||
// 记录当前为止的开服数
|
||||
type WxUserSeverList struct {
|
||||
ID int64 `gorm:"column:id;primary_key;comment:自增索引;autoIncrementIncrement" json:"id"`
|
||||
SeverId int32 `gorm:"column:severId;comment:区服Id" json:"severId"`
|
||||
}
|
||||
|
||||
// 登录相关的记录
|
||||
type RecordLoginOfWxUser struct {
|
||||
ID int64 `gorm:"column:id;primary_key;comment:自增索引;autoIncrementIncrement" json:"id"`
|
||||
Uid int64 `gorm:"column:uid;comment:用户唯一Id" json:"uid"`
|
||||
SeverId int32 `gorm:"column:severId;comment:区服Id" json:"severId"`
|
||||
RecordDate int64 `gorm:"column:recorddate;comment:记录日期" json:"recorddate"` //只记录当天0点的时间戳,方便查询某一日的数据
|
||||
LoginInTime int64 `gorm:"column:loginintime;comment:登录时间" json:"loginintime"`
|
||||
LoginOutTime int64 `gorm:"column:loginouttime;comment:登出时间" json:"loginouttime"`
|
||||
PlayTimes int64 `gorm:"column:playtimes;comment:游玩时长" json:"playtimes"`
|
||||
//用于统计当日的总上线人数 0=否,1=是
|
||||
IsFirstLogin int32 `gorm:"column:isfirstlogin;comment:是否首次登录" json:"isfirstlogin"`
|
||||
}
|
||||
|
||||
// 看广告相关记录
|
||||
// 记录日期便于按天统计
|
||||
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"`
|
||||
ID int64 `gorm:"column:id;primary_key;comment:自增索引;autoIncrementIncrement" json:"id"`
|
||||
RecordDate int64 `gorm:"column:recorddate;comment:记录日期" json:"recorddate"` //只记录当天0点的时间戳,方便查询某一日的数据
|
||||
Uid int64 `gorm:"column:uid;comment:用户唯一Id" json:"uid"`
|
||||
SeverId int32 `gorm:"column:severId;comment:区服Id" json:"severId"`
|
||||
WatchADNum int32 `gorm:"column:watchadnum;comment:看广告次数" json:"watchadnum"`
|
||||
}
|
||||
|
||||
func (WxUserInfo) TableName() string {
|
||||
return "wxuserinfo"
|
||||
}
|
||||
|
||||
func (r RecordLoginOfWxUser) TableName(db *gorm.DB) string {
|
||||
func (RecordLoginOfWxUser) TableName() string {
|
||||
return "recordloginofwxuser"
|
||||
}
|
||||
|
||||
@@ -78,3 +87,7 @@ func (RecordWatchADOfWxUser) TableName() string {
|
||||
func (WxUserSeverInfo) TableName() string {
|
||||
return "wxuserseverinfo"
|
||||
}
|
||||
|
||||
func (WxUserSeverList) TableName() string {
|
||||
return "wxuserseverlist"
|
||||
}
|
||||
|
||||
@@ -1,24 +1,38 @@
|
||||
package wxuser
|
||||
|
||||
import (
|
||||
"common/mytime"
|
||||
"common/resultStatus"
|
||||
"goutil/logUtilPlus"
|
||||
"time"
|
||||
)
|
||||
|
||||
func RecordLoginIn(uid int64) {
|
||||
// 记录登录数据
|
||||
func RecordLoginIn(uid int64, severId int32) {
|
||||
nowTime := time.Now().Unix()
|
||||
// if userLastRecord, _ := GetUserRecord(uid); userLastRecord != nil {
|
||||
// if userLastRecord.LoginOutTime == 0 {
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
userRecord := &RecordLoginOfWxUser{}
|
||||
userRecord.IsFirstLogin = 1
|
||||
if userLastRecord, _ := GetUserRecord(uid); userLastRecord != nil {
|
||||
if userLastRecord.RecordDate == mytime.ZeroTime(nowTime, 0) {
|
||||
userRecord.IsFirstLogin = 0
|
||||
}
|
||||
}
|
||||
userRecord.LoginInTime = nowTime
|
||||
userRecord.Uid = uid
|
||||
userRecord.RecordDate = mytime.ZeroTime(nowTime, 0)
|
||||
userRecord.SeverId = severId
|
||||
AddUserRecord(userRecord)
|
||||
AddUserRecordCache(userRecord)
|
||||
//检测该服是否是新服
|
||||
if !CheckSeverID(severId) {
|
||||
//若是新服,添加服务器id到服务器列表,方便统计的时候知道有多少个服
|
||||
newUserSeverList := &WxUserSeverList{}
|
||||
newUserSeverList.SeverId = severId
|
||||
AddUserSeverList(newUserSeverList)
|
||||
}
|
||||
}
|
||||
|
||||
// 统计登出数据
|
||||
func RecordLoginOut(uid int64) resultStatus.ResultStatus {
|
||||
var userRecord *RecordLoginOfWxUser
|
||||
if userRecord, _ = GetUserRecord(uid); userRecord == nil {
|
||||
@@ -30,51 +44,90 @@ func RecordLoginOut(uid int64) resultStatus.ResultStatus {
|
||||
}
|
||||
go func() {
|
||||
nowTime := time.Now().Unix()
|
||||
userRecord.LoginOutTime = nowTime
|
||||
playTime := nowTime - userRecord.LoginInTime
|
||||
userRecord.PlayTimes += playTime
|
||||
SaveUserRecord(userRecord)
|
||||
if userRecord.RecordDate == mytime.ZeroTime(nowTime, 0) {
|
||||
userRecord.LoginOutTime = nowTime
|
||||
playTime := nowTime - userRecord.LoginInTime
|
||||
userRecord.PlayTimes += playTime
|
||||
SaveUserRecord(userRecord)
|
||||
} else {
|
||||
//如果跨天,要拆分成两条数据记录
|
||||
zeroTime := mytime.ZeroTime(nowTime, 0)
|
||||
userRecord.LoginOutTime = zeroTime
|
||||
playTime := zeroTime - userRecord.LoginInTime
|
||||
userRecord.PlayTimes += playTime
|
||||
SaveUserRecord(userRecord)
|
||||
newUserRecord := &RecordLoginOfWxUser{}
|
||||
newUserRecord.LoginInTime = zeroTime
|
||||
newUserRecord.LoginOutTime = nowTime
|
||||
playTime = nowTime - userRecord.LoginInTime
|
||||
newUserRecord.PlayTimes += playTime
|
||||
newUserRecord.RecordDate = mytime.ZeroTime(nowTime, 0)
|
||||
newUserRecord.Uid = uid
|
||||
newUserRecord.SeverId = userRecord.SeverId
|
||||
newUserRecord.IsFirstLogin = 1
|
||||
AddUserRecord(newUserRecord)
|
||||
}
|
||||
}()
|
||||
return resultStatus.Success
|
||||
}
|
||||
|
||||
// 记录看广告数据
|
||||
func RecordWatchAD(uid int64) resultStatus.ResultStatus {
|
||||
nowTime := time.Now()
|
||||
todayZeroTime := mytime.ZeroTime(time.Now().Unix(), 0)
|
||||
userADRecord := &RecordWatchADOfWxUser{}
|
||||
var userSeverInfoRecord *WxUserSeverInfo
|
||||
if userSeverInfoRecord, _ = GetUserSeverInfoByUid(uid); userSeverInfoRecord == nil {
|
||||
return resultStatus.PlayerNotExist
|
||||
}
|
||||
severId := userSeverInfoRecord.SeverId
|
||||
if userLastADRecord, _ := GetUserADRecord(uid); userLastADRecord != nil {
|
||||
if nowTime.Format("2006-01-02") == userLastADRecord.RecordDate.Format("2006-01-02") {
|
||||
if userLastADRecord.RecordDate == mytime.ZeroTime(todayZeroTime, 0) {
|
||||
//数据按天记录,如果为同一天,就在原来的数据上加
|
||||
userLastADRecord.WatchADNum++
|
||||
SaveUserADRecord(userLastADRecord)
|
||||
return resultStatus.Success
|
||||
}
|
||||
}
|
||||
userADRecord.RecordDate = nowTime
|
||||
userADRecord.RecordDate = todayZeroTime
|
||||
userADRecord.WatchADNum += 1
|
||||
userADRecord.Uid = uid
|
||||
userADRecord.SeverId = severId
|
||||
AddUserADRecord(userADRecord)
|
||||
AddUserADRecordCache(userADRecord)
|
||||
return resultStatus.Success
|
||||
}
|
||||
|
||||
// 根据openid和severid来创建uid
|
||||
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
|
||||
if uid, _ := GetUserUid(openId, severId); uid != 0 {
|
||||
return uid
|
||||
}
|
||||
userSeverInfo := &WxUserSeverInfo{}
|
||||
userSeverInfo.OpenId = openId
|
||||
userSeverInfo.SeverId = severId
|
||||
userSeverInfo.Uid = lastId + 1 + 100000000
|
||||
AddUserSeverInfo(userSeverInfo)
|
||||
return userSeverInfo.Uid
|
||||
ID, _ := AddUserSeverInfo(userSeverInfo)
|
||||
//uid=数据库索引+1亿,先取索引再相加,避免重复
|
||||
Uid := ID + 100000000
|
||||
AddUserSeverInfoCache(openId, severId, Uid)
|
||||
AddUserUidCache(userSeverInfo)
|
||||
go func() {
|
||||
userSeverInfo.Uid = Uid
|
||||
SaveUserSeverInfo(userSeverInfo)
|
||||
}()
|
||||
return Uid
|
||||
}
|
||||
|
||||
// func init() {
|
||||
// testRecordWatchAD()
|
||||
// }
|
||||
|
||||
func testRecordWatchAD() {
|
||||
//RecordWatchAD("hell)
|
||||
// 切服时记录数据
|
||||
func SwitchSever(uid int64, oldseverId, newseverId int32) (int64, resultStatus.ResultStatus) {
|
||||
var userSeverInfoRecord *WxUserSeverInfo
|
||||
if userSeverInfoRecord, _ = GetUserSeverInfoByUid(uid); userSeverInfoRecord == nil {
|
||||
return 0, resultStatus.PlayerNotExist
|
||||
}
|
||||
if userSeverInfoRecord.SeverId != oldseverId {
|
||||
return 0, resultStatus.PlayerNotMatchSever
|
||||
}
|
||||
RecordLoginOut(uid)
|
||||
uidOfNewSever := CreatUid(userSeverInfoRecord.OpenId, newseverId)
|
||||
go RecordLoginIn(uidOfNewSever, newseverId)
|
||||
return uidOfNewSever, resultStatus.Success
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ type WechatsdkService struct {
|
||||
}
|
||||
|
||||
// 通过code来换取assesstoken
|
||||
func (w *WechatsdkService) GetAccessToken(code string) (resultStatus.ResultStatus, int64) {
|
||||
func (w *WechatsdkService) GetAccessToken(code string, severId int32) (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
|
||||
@@ -49,7 +49,7 @@ func (w *WechatsdkService) GetAccessToken(code string) (resultStatus.ResultStatu
|
||||
w.GetUserInfo(tokens.AccessToken, tokens.OpenId)
|
||||
}
|
||||
}()
|
||||
go RecordLoginIn(Uid)
|
||||
go RecordLoginIn(Uid, severId)
|
||||
return resultStatus.Success, Uid
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user