diff --git a/api/v1/game/manage.go b/api/v1/game/manage.go index 4cd94f8..ff49351 100644 --- a/api/v1/game/manage.go +++ b/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"` +} diff --git a/api/v1/game/pub.go b/api/v1/game/pub.go index 064bdcb..6bd433f 100644 --- a/api/v1/game/pub.go +++ b/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:"重置服务器列表"` } diff --git a/go.mod b/go.mod index b2065d1..dee6b0d 100644 --- a/go.mod +++ b/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 ( diff --git a/go.sum b/go.sum index db4f76e..79a52ed 100644 --- a/go.sum +++ b/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= diff --git a/internal/controller/sys_login.go b/internal/controller/sys_login.go index 72a22a8..e3e6f76 100644 --- a/internal/controller/sys_login.go +++ b/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{ diff --git a/internal/service/tencentSms.go b/internal/service/tencentSms.go new file mode 100644 index 0000000..54beb6a --- /dev/null +++ b/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 +} diff --git a/internal/serviceGame/loginUrl.go b/internal/serviceGame/loginUrl.go index 1221004..83cad41 100644 --- a/internal/serviceGame/loginUrl.go +++ b/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 }