Browse Source

login

master
linquan 1 month ago
parent
commit
a8f31b1dbc
  1. 9
      api/v1/game/manage.go
  2. 8
      api/v1/game/pub.go
  3. 2
      go.mod
  4. 4
      go.sum
  5. 2
      internal/controller/sys_login.go
  6. 93
      internal/service/tencentSms.go
  7. 19
      internal/serviceGame/loginUrl.go

9
api/v1/game/manage.go

@ -472,3 +472,12 @@ type GetLoginOutGmRes struct {
Logs []entity.LoginLogoutInfoGm `json:"logs"`
common.ListRes
}
type ReConfigServerReq struct {
g.Meta `path:"/reloadServer" tags:"外部接口" method:"get" summary:"重置服务器列表"`
SType int32 `p:"sType"`
}
type ReConfigServerRes struct {
g.Meta `mime:"application/json"`
}

8
api/v1/game/pub.go

@ -172,14 +172,6 @@ type ShopRecordRes struct {
g.Meta `mime:"application/json"`
}
type ReConfigServerReq struct {
g.Meta `path:"/reloadServer" tags:"外部接口" method:"get" summary:"重置服务器列表"`
}
type ReConfigServerRes struct {
g.Meta `mime:"application/json"`
}
type GetPostsReq struct {
g.Meta `path:"/getPosts" tags:"外部接口" method:"get" summary:"重置服务器列表"`
}

2
go.mod

@ -86,6 +86,8 @@ require (
github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.18
github.com/alibabacloud-go/tea-utils v1.4.5
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1183
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.0.1183
)
require (

4
go.sum

@ -256,7 +256,11 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.194/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1183 h1:V4P+qvMsCtP65LVr5XAi2Jxa1d7X+U/PWHkNakiQnQQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1183/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.194/go.mod h1:yrBKWhChnDqNz1xuXdSbWXG56XawEq0G5j1lg4VwBD4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.0.1183 h1:KJziHetzUJMFkr6/LSAoiBJThMN5O0E/sSSC2ISfzFQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.0.1183/go.mod h1:vS5X15o3s2nn0n4gGAAT1p2hrIwrf+yY8UNQeUZ83L8=
github.com/tencentyun/cos-go-sdk-v5 v0.7.40 h1:W6vDGKCHe4wBACI1d2UgE6+50sJFhRWU4O8IB2ozzxM=
github.com/tencentyun/cos-go-sdk-v5 v0.7.40/go.mod h1:4dCEtLHGh8QPxHEkgq+nFaky7yZxQuYwgSJM87icDaw=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=

2
internal/controller/sys_login.go

@ -237,7 +237,7 @@ func (c *loginController) MobileCode(ctx context.Context, req *system.MobileCode
})
return
}
err = service.AliYunSms().Main([]string{req.Phone, code})
err = service.TencentSms().Main([]string{req.Phone, code})
if err != nil {
// 保存登录失败的日志信息
service.SysLoginLog().Invoke(ctx, &model.LoginLogParams{

93
internal/service/tencentSms.go

@ -0,0 +1,93 @@
package service
import (
"fmt"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
sms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms/v20210111"
)
type ITencentSms interface {
ConfigInit()
Main(args []string) (_err error)
}
type tencentSmsServiceTmpl struct {
}
var tencentSmsService = tencentSmsServiceTmpl{}
func TencentSms() ITencentSms {
return &tencentSmsService
}
type TencentSmsData struct {
AccessKeyId string
AccessSecret string
AppId string
CodeSignName string
TemplateCode string
}
var (
tencnetSmsConfig TencentSmsData
)
func init() {
tencentSmsService.ConfigInit()
}
func (a *tencentSmsServiceTmpl) ConfigInit() {
//加载游戏相关配置
ctx := gctx.New()
tencnetSmsConfig.AccessKeyId = g.Cfg().MustGet(ctx, "game.tencentSms.accessKeyId").String() // 替换为你的 SecretId
tencnetSmsConfig.AccessSecret = g.Cfg().MustGet(ctx, "game.tencentSms.accessSecret").String() // 替换为你的 SecretKey
tencnetSmsConfig.AppId = g.Cfg().MustGet(ctx, "game.tencentSms.appId").String() // 短信应用ID (SdkAppId)
tencnetSmsConfig.CodeSignName = g.Cfg().MustGet(ctx, "game.tencentSms.codeSignName").String() // 已审核通过的短信签名内容
tencnetSmsConfig.TemplateCode = g.Cfg().MustGet(ctx, "game.tencentSms.templateCodePass").String() // 已审核通过的模板ID
}
func (a *tencentSmsServiceTmpl) Main(args []string) (_err error) {
// 初始化认证对象
credential := common.NewCredential(tencnetSmsConfig.AccessKeyId, tencnetSmsConfig.AccessSecret)
// 初始化客户端配置
cpf := profile.NewClientProfile()
cpf.HttpProfile.Endpoint = "sms.tencentcloudapi.com" // 接口域名
// 创建 SMS 客户端
client, _ := sms.NewClient(credential, "ap-guangzhou", cpf) // 地域根据实际情况选择
// 构建请求
request := sms.NewSendSmsRequest()
request.SmsSdkAppId = common.StringPtr(tencnetSmsConfig.AppId)
request.SignName = common.StringPtr(tencnetSmsConfig.CodeSignName)
request.TemplateId = common.StringPtr(tencnetSmsConfig.TemplateCode)
request.PhoneNumberSet = common.StringPtrs([]string{"+86" + args[0]})
// 模板参数(根据模板要求填写,若无参数则留空)
templateParams := []string{args[1], "10"} // 示例验证码
request.TemplateParamSet = common.StringPtrs(templateParams)
// 发送请求
response, err := client.SendSms(request)
// 错误处理
if _, ok := err.(*errors.TencentCloudSDKError); ok {
fmt.Printf("API error: %v\n", err)
return
}
if err != nil {
fmt.Printf("Failed: %v\n", err)
return
}
// 打印结果
fmt.Printf("Response: %s\n", response.ToJsonString())
return
}

19
internal/serviceGame/loginUrl.go

@ -229,13 +229,18 @@ func (c *gameLoginUrlImpl) GetGameLoginUrl(ctx context.Context, req *game.GetGam
}
func (c *gameLoginUrlImpl) ReConfigServer(ctx context.Context, req *game.ReConfigServerReq) (res *game.ReConfigServerRes, err error) {
internal.InitServer(ctx)
internal.InitRechargeServer(ctx)
internal.InitChannel(ctx)
internal.InitRouterServer(ctx)
internal.MongoInit(ctx)
service.AliYunSms().ConfigInit()
service.Email().ConfigInit()
if req.SType == 1 {
service.AliYunSms().ConfigInit()
service.Email().ConfigInit()
service.TencentSms().ConfigInit()
} else if req.SType == 2 {
internal.InitChannel(ctx)
} else {
internal.InitServer(ctx)
internal.InitRechargeServer(ctx)
internal.InitRouterServer(ctx)
internal.MongoInit(ctx)
}
return
}

Loading…
Cancel
Save