修改 aliyun,短信,oss,验证码
This commit is contained in:
12
api/verify/v1/verify.go
Normal file
12
api/verify/v1/verify.go
Normal file
@ -0,0 +1,12 @@
|
||||
package v1
|
||||
|
||||
import "github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
type VerifyReq struct {
|
||||
g.Meta `path:"/verify" method:"post" tags:"Verify" summary:"验证"`
|
||||
VerifySign string `json:"verifySign" v:"required#验签不能为空" dc:"验签"`
|
||||
}
|
||||
|
||||
type VerifyRes struct {
|
||||
Response interface{} `json:"response" dc:"返回结果"`
|
||||
}
|
||||
15
api/verify/verify.go
Normal file
15
api/verify/verify.go
Normal file
@ -0,0 +1,15 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package verify
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"server/api/verify/v1"
|
||||
)
|
||||
|
||||
type IVerifyV1 interface {
|
||||
Verify(ctx context.Context, req *v1.VerifyReq) (res *v1.VerifyRes, err error)
|
||||
}
|
||||
4
go.mod
4
go.mod
@ -3,9 +3,11 @@ module server
|
||||
go 1.24.2
|
||||
|
||||
require (
|
||||
github.com/alibabacloud-go/afs-20180112 v0.1.0
|
||||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.11
|
||||
github.com/alibabacloud-go/dysmsapi-20170525/v4 v4.1.3
|
||||
github.com/alibabacloud-go/tea v1.2.2
|
||||
github.com/alibabacloud-go/tea-rpc v1.3.3
|
||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.6
|
||||
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
|
||||
github.com/aliyun/credentials-go v1.4.6
|
||||
@ -28,6 +30,8 @@ require (
|
||||
github.com/alibabacloud-go/debug v1.0.1 // indirect
|
||||
github.com/alibabacloud-go/endpoint-util v1.1.0 // indirect
|
||||
github.com/alibabacloud-go/openapi-util v0.1.1 // indirect
|
||||
github.com/alibabacloud-go/tea-rpc-utils v1.1.2 // indirect
|
||||
github.com/alibabacloud-go/tea-utils v1.3.6 // indirect
|
||||
github.com/alibabacloud-go/tea-xml v1.1.3 // indirect
|
||||
github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect
|
||||
github.com/casbin/govaluate v1.3.0 // indirect
|
||||
|
||||
11
go.sum
11
go.sum
@ -2,6 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
|
||||
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||
github.com/alibabacloud-go/afs-20180112 v0.1.0 h1:KeaFt9Rn04/qdCBODYJ87sZpgV56PNFDGxklblXIGVM=
|
||||
github.com/alibabacloud-go/afs-20180112 v0.1.0/go.mod h1:KmHBl9OtFtm4/iaGmY+r70VJvj3uTDmSr7H7e8VUPjU=
|
||||
github.com/alibabacloud-go/alibabacloud-gateway-pop v0.0.6 h1:eIf+iGJxdU4U9ypaUfbtOWCsZSbTb8AUHvyPrxu6mAA=
|
||||
github.com/alibabacloud-go/alibabacloud-gateway-pop v0.0.6/go.mod h1:4EUIoxs/do24zMOGGqYVWgw0s9NtiylnJglOeEB5UJo=
|
||||
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4/go.mod h1:sCavSAvdzOjul4cEqeVtvlSaSScfNsTQ+46HwlTL1hc=
|
||||
@ -33,12 +35,21 @@ github.com/alibabacloud-go/openapi-util v0.1.1/go.mod h1:/UehBSE2cf1gYT43GV4E+Rx
|
||||
github.com/alibabacloud-go/tea v1.1.0/go.mod h1:IkGyUSX4Ba1V+k4pCtJUc6jDpZLFph9QMy2VUPTwukg=
|
||||
github.com/alibabacloud-go/tea v1.1.7/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
|
||||
github.com/alibabacloud-go/tea v1.1.8/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
|
||||
github.com/alibabacloud-go/tea v1.1.10/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
|
||||
github.com/alibabacloud-go/tea v1.1.11/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
|
||||
github.com/alibabacloud-go/tea v1.1.17/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A=
|
||||
github.com/alibabacloud-go/tea v1.1.20/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A=
|
||||
github.com/alibabacloud-go/tea v1.2.2 h1:aTsR6Rl3ANWPfqeQugPglfurloyBJY85eFy7Gc1+8oU=
|
||||
github.com/alibabacloud-go/tea v1.2.2/go.mod h1:CF3vOzEMAG+bR4WOql8gc2G9H3EkH3ZLAQdpmpXMgwk=
|
||||
github.com/alibabacloud-go/tea-rpc v1.1.8/go.mod h1:C1nOCvQ/WjIn3bVcBCcZY34s+1TqUowR44ovROFvwfw=
|
||||
github.com/alibabacloud-go/tea-rpc v1.3.3 h1:NZJtukZouR0jpN0dWeBB5bMZdVvTyRPyISxc/hfOALo=
|
||||
github.com/alibabacloud-go/tea-rpc v1.3.3/go.mod h1:zwKwxuf92liNsPcLOxPdrkvR5Dq6jtX2du6qx8FT094=
|
||||
github.com/alibabacloud-go/tea-rpc-utils v1.1.2 h1:ZTfFREnP2q9D49T2J/1jYYOndepGdrUOgm/JR8/bIQ0=
|
||||
github.com/alibabacloud-go/tea-rpc-utils v1.1.2/go.mod h1:V5HdNi6Xdn0JMpgVhQ19vsFAS51tydr7BqcJtuXH1Yw=
|
||||
github.com/alibabacloud-go/tea-utils v1.3.1/go.mod h1:EI/o33aBfj3hETm4RLiAxF/ThQdSngxrpF8rKUDJjPE=
|
||||
github.com/alibabacloud-go/tea-utils v1.3.5/go.mod h1:EI/o33aBfj3hETm4RLiAxF/ThQdSngxrpF8rKUDJjPE=
|
||||
github.com/alibabacloud-go/tea-utils v1.3.6 h1:bVjrxHztM8hAs6nOfLWCgxQfAtKb9RgFFMV6J3rdvB4=
|
||||
github.com/alibabacloud-go/tea-utils v1.3.6/go.mod h1:EI/o33aBfj3hETm4RLiAxF/ThQdSngxrpF8rKUDJjPE=
|
||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.5/go.mod h1:dL6vbUT35E4F4bFTHL845eUloqaerYBYPsdWR2/jhe4=
|
||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.6 h1:ZkmUlhlQbaDC+Eba/GARMPy6hKdCLiSke5RsN5LcyQ0=
|
||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.6/go.mod h1:qxn986l+q33J5VkialKMqT/TTs3E+U9MJpd001iWQ9I=
|
||||
|
||||
@ -2,7 +2,7 @@ package consts
|
||||
|
||||
// 用户
|
||||
const (
|
||||
UserBindPhoneKey = "user:bindPhone:%d"
|
||||
UserBindPhoneKey = "user:bindPhone:%s"
|
||||
UserCodeExpire = 5 * 60
|
||||
)
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func (c *ControllerV1) UploadGameImg(ctx context.Context, req *v1.UploadGameImgReq) (res *v1.UploadGameImgRes, err error) {
|
||||
upload, err := service.Upload().UploadGameImg(ctx, &model.UploadIn{File: req.File})
|
||||
upload, err := service.Upload().Upload(ctx, &model.UploadIn{File: req.File, Type: "game"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -3,12 +3,14 @@ package upload
|
||||
import (
|
||||
"context"
|
||||
"server/api/upload/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) UploadUserImg(ctx context.Context, req *v1.UploadUserImgReq) (res *v1.UploadUserImgRes, err error) {
|
||||
//upload, err := service.Upload().UploadGameImg(ctx, &model.UploadIn{File: req.File})
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
return &v1.UploadUserImgRes{Url: "这是头像图片"}, nil
|
||||
upload, err := service.Upload().Upload(ctx, &model.UploadIn{File: req.File, Type: "user"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.UploadUserImgRes{Url: upload.Url}, nil
|
||||
}
|
||||
|
||||
5
internal/controller/verify/verify.go
Normal file
5
internal/controller/verify/verify.go
Normal file
@ -0,0 +1,5 @@
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package verify
|
||||
15
internal/controller/verify/verify_new.go
Normal file
15
internal/controller/verify/verify_new.go
Normal file
@ -0,0 +1,15 @@
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package verify
|
||||
|
||||
import (
|
||||
"server/api/verify"
|
||||
)
|
||||
|
||||
type ControllerV1 struct{}
|
||||
|
||||
func NewV1() verify.IVerifyV1 {
|
||||
return &ControllerV1{}
|
||||
}
|
||||
16
internal/controller/verify/verify_v1_verify.go
Normal file
16
internal/controller/verify/verify_v1_verify.go
Normal file
@ -0,0 +1,16 @@
|
||||
package verify
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
|
||||
"server/api/verify/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) Verify(ctx context.Context, req *v1.VerifyReq) (res *v1.VerifyRes, err error) {
|
||||
|
||||
// 校验
|
||||
return nil, gerror.NewCode(gcode.CodeNotImplemented)
|
||||
}
|
||||
@ -2,6 +2,7 @@ package upload
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"server/utility/ecode"
|
||||
"server/utility/oss"
|
||||
"strings"
|
||||
@ -38,69 +39,7 @@ func (s *sUpload) Upload(ctx context.Context, in *model.UploadIn) (res *model.Up
|
||||
// 获取图片后缀
|
||||
exit := strings.Split(fileType, "/")[1]
|
||||
// 文件名称
|
||||
fileName := strings.ToLower("image/" + grand.Letters(32) + "." + exit)
|
||||
// 开始上传图片
|
||||
client, ok := oss.GetClient("aliyun")
|
||||
if !ok {
|
||||
return nil, ecode.Fail.Sub("未配置OSS")
|
||||
}
|
||||
uploadRes, err := client.UploadFile(ctx, &model.OssUploadFileInput{
|
||||
Filename: fileName,
|
||||
File: in.File,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &model.UploadOut{
|
||||
Url: uploadRes.Url,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *sUpload) UploadGameImg(ctx context.Context, in *model.UploadIn) (res *model.UploadOut, err error) {
|
||||
// 判断文件格式
|
||||
fileType := in.File.Header.Get("Content-Type")
|
||||
if !strings.HasPrefix(fileType, "image/") {
|
||||
return nil, gerror.New("图片格式错误")
|
||||
}
|
||||
//判断图片大小
|
||||
if in.File.Size > 10*1024*1024 {
|
||||
return nil, gerror.New("图片大小最多10M")
|
||||
}
|
||||
// 获取图片后缀
|
||||
exit := strings.Split(fileType, "/")[1]
|
||||
// 文件名称
|
||||
fileName := strings.ToLower("gameImg/" + grand.Letters(32) + "." + exit)
|
||||
// 开始上传图片
|
||||
client, ok := oss.GetClient("aliyun")
|
||||
if !ok {
|
||||
return nil, ecode.Fail.Sub("未配置OSS")
|
||||
}
|
||||
uploadRes, err := client.UploadFile(ctx, &model.OssUploadFileInput{
|
||||
Filename: fileName,
|
||||
File: in.File,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &model.UploadOut{
|
||||
Url: uploadRes.Url,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *sUpload) UploadUserImg(ctx context.Context, in *model.UploadIn) (res *model.UploadOut, err error) {
|
||||
// 判断文件格式
|
||||
fileType := in.File.Header.Get("Content-Type")
|
||||
if !strings.HasPrefix(fileType, "image/") {
|
||||
return nil, gerror.New("图片格式错误")
|
||||
}
|
||||
//判断图片大小
|
||||
if in.File.Size > 10*1024*1024 {
|
||||
return nil, gerror.New("图片大小最多10M")
|
||||
}
|
||||
// 获取图片后缀
|
||||
exit := strings.Split(fileType, "/")[1]
|
||||
// 文件名称
|
||||
fileName := strings.ToLower("userImg/" + grand.Letters(32) + "." + exit)
|
||||
fileName := strings.ToLower(fmt.Sprintf("%s/%s.%s", in.Type, grand.Letters(32), exit))
|
||||
// 开始上传图片
|
||||
client, ok := oss.GetClient("aliyun")
|
||||
if !ok {
|
||||
|
||||
@ -17,6 +17,7 @@ import (
|
||||
"server/utility/encrypt"
|
||||
"server/utility/gamelife"
|
||||
"server/utility/jwt"
|
||||
"server/utility/sms"
|
||||
)
|
||||
|
||||
type sUser struct{}
|
||||
@ -163,16 +164,29 @@ func (s *sUser) Info(ctx context.Context, in *model.UserInfoIn) (out *model.User
|
||||
}
|
||||
|
||||
func (s *sUser) Code(ctx context.Context, in *model.GetPhoneCodeIn) (out *model.GetPhoneCodeOut, err error) {
|
||||
// TODO 短信平台获取验证码
|
||||
code := "123456"
|
||||
code := grand.Digits(6)
|
||||
|
||||
// 存入 redis
|
||||
err = g.Redis().SetEX(ctx, fmt.Sprintf(consts.UserBindPhoneKey, in.Id), code, consts.UserCodeExpire)
|
||||
err = g.Redis().SetEX(ctx, fmt.Sprintf(consts.UserBindPhoneKey, in.Phone), code, consts.UserCodeExpire)
|
||||
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("设置验证码失败")
|
||||
}
|
||||
|
||||
client, ok := sms.GetClient("aliyunsms")
|
||||
|
||||
if !ok {
|
||||
return nil, ecode.Fail.Sub("未配置短信平台")
|
||||
}
|
||||
_, err = client.SendCode(ctx, &model.SMSCodeIn{
|
||||
Code: code,
|
||||
Phone: in.Phone,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("发送验证码失败")
|
||||
}
|
||||
|
||||
return &model.GetPhoneCodeOut{
|
||||
Success: true,
|
||||
}, nil
|
||||
@ -203,7 +217,7 @@ func (s *sUser) Update(ctx context.Context, in *model.UserUpdateIn) (out *model.
|
||||
|
||||
func (s *sUser) BindPhone(ctx context.Context, in *model.UserBindPhoneIn) (out *model.UserBindPhoneOut, err error) {
|
||||
// 绑定手机号,需要验证入参和缓存中的验证码时候相同
|
||||
value, err := g.Redis().Get(ctx, fmt.Sprintf(consts.UserBindPhoneKey, in.Id))
|
||||
value, err := g.Redis().Get(ctx, fmt.Sprintf(consts.UserBindPhoneKey, in.Phone))
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("获取失败")
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import "github.com/gogf/gf/v2/net/ghttp"
|
||||
|
||||
type UploadIn struct {
|
||||
File *ghttp.UploadFile
|
||||
Type string
|
||||
}
|
||||
|
||||
type UploadOut struct {
|
||||
@ -30,8 +31,17 @@ type OssUploadFileInput struct {
|
||||
|
||||
type SMSCodeIn struct {
|
||||
Phone string
|
||||
Code string
|
||||
}
|
||||
|
||||
type SMSCodeOut struct {
|
||||
Success bool
|
||||
}
|
||||
|
||||
type CaptchaIn struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type CaptchaOut struct {
|
||||
Success bool
|
||||
}
|
||||
|
||||
@ -3,12 +3,12 @@ package packed
|
||||
import (
|
||||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
||||
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
|
||||
//_ "server/utility/gamelife"
|
||||
_ "server/utility/gamelife"
|
||||
//_ "server/utility/mqtt/emqx"
|
||||
_ "server/utility/myCasbin"
|
||||
//_ "server/utility/oss/aliyun"
|
||||
//_ "server/utility/rsa"
|
||||
//_ "server/utility/sms/aliyun"
|
||||
_ "server/utility/oss/aliyun"
|
||||
_ "server/utility/rsa"
|
||||
_ "server/utility/sms/aliyun"
|
||||
_ "server/utility/snowid"
|
||||
_ "server/utility/wechat"
|
||||
)
|
||||
|
||||
@ -18,7 +18,6 @@ type (
|
||||
Update(ctx context.Context, in *model.RewardUpdateIn) (out *model.RewardUpdateOut, err error)
|
||||
// Delete 删除奖励
|
||||
Delete(ctx context.Context, in *model.RewardDeleteIn) (out *model.RewardDeleteOut, err error)
|
||||
// List 奖励列表
|
||||
List(ctx context.Context, in *model.RewardListIn) (out *model.RewardListOut, err error)
|
||||
// GetLift 领取奖励
|
||||
GetLift(ctx context.Context, in *model.GetRewardIn) (out *model.GetRewardOut, err error)
|
||||
|
||||
@ -13,8 +13,6 @@ import (
|
||||
type (
|
||||
IUpload interface {
|
||||
Upload(ctx context.Context, in *model.UploadIn) (res *model.UploadOut, err error)
|
||||
UploadGameImg(ctx context.Context, in *model.UploadIn) (res *model.UploadOut, err error)
|
||||
UploadUserImg(ctx context.Context, in *model.UploadIn) (res *model.UploadOut, err error)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
55
utility/captcha/aliyun/aliyun.go
Normal file
55
utility/captcha/aliyun/aliyun.go
Normal file
@ -0,0 +1,55 @@
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
afs "github.com/alibabacloud-go/afs-20180112/client"
|
||||
rpc "github.com/alibabacloud-go/tea-rpc/client"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"server/internal/model"
|
||||
icaptcha "server/utility/captcha"
|
||||
)
|
||||
|
||||
type aliyunClient struct {
|
||||
accessKeyId string
|
||||
accessKeySecret string
|
||||
}
|
||||
|
||||
// 初始化并注册
|
||||
func init() {
|
||||
ctx := context.Background()
|
||||
client := &aliyunClient{
|
||||
accessKeyId: g.Config().MustGet(ctx, "sms.aliyun.accessKeyId").String(),
|
||||
accessKeySecret: g.Config().MustGet(ctx, "sms.aliyun.accessKeySecret").String(),
|
||||
}
|
||||
icaptcha.Register("aliyuncaptcha", client)
|
||||
}
|
||||
|
||||
func (a *aliyunClient) client(ctx context.Context) (client *afs.Client, _err error) {
|
||||
|
||||
config := new(rpc.Config)
|
||||
config.SetAccessKeyId("*** Provide your AccessKeyId ***").
|
||||
SetAccessKeySecret("*** Provide your AccessKeySecret ***").
|
||||
SetRegionId("cn-hangzhou").
|
||||
SetEndpoint("afs.aliyuncs.com")
|
||||
client, _ = afs.NewClient(config)
|
||||
|
||||
return client, _err
|
||||
}
|
||||
|
||||
func (a *aliyunClient) Vertify(ctx context.Context, client *afs.Client, in *model.CaptchaIn) (out string, err error) {
|
||||
request := new(afs.AuthenticateSigRequest)
|
||||
request.SetSig("xxx")
|
||||
request.SetSessionId("xxx")
|
||||
request.SetToken("xxx")
|
||||
request.SetRemoteIp("xxx")
|
||||
request.SetScene("xxx")
|
||||
request.SetAppKey("xxx")
|
||||
response, _err := client.AuthenticateSig(request)
|
||||
if _err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println(response)
|
||||
|
||||
return response.String(), nil
|
||||
}
|
||||
22
utility/captcha/captcha.go
Normal file
22
utility/captcha/captcha.go
Normal file
@ -0,0 +1,22 @@
|
||||
package captcha
|
||||
|
||||
import (
|
||||
"context"
|
||||
afs "github.com/alibabacloud-go/afs-20180112/client"
|
||||
"server/internal/model"
|
||||
)
|
||||
|
||||
type CaptchaClient interface {
|
||||
Vertify(ctx context.Context, client *afs.Client, in *model.CaptchaIn) (out string, err error)
|
||||
}
|
||||
|
||||
var clients = make(map[string]CaptchaClient)
|
||||
|
||||
func Register(name string, client CaptchaClient) {
|
||||
clients[name] = client
|
||||
}
|
||||
|
||||
func GetClient(name string) (CaptchaClient, bool) {
|
||||
client, ok := clients[name]
|
||||
return client, ok
|
||||
}
|
||||
@ -125,7 +125,7 @@ func init() {
|
||||
enforcer.AddPolicy("store", "/x/desktop", "GET", "获取门店桌面设置")
|
||||
enforcer.AddPolicy("store", "/x/desktop", "POST", "修改门店桌面设置")
|
||||
|
||||
enforcer.AddPolicy("guest", "/x/task/completed/list", "GET", "获取游戏列表")
|
||||
enforcer.AddPolicy("store", "/x/task/completed/list", "GET", "门店获取用户任务完成情况")
|
||||
|
||||
// 获取门店 ip信息
|
||||
enforcer.AddPolicy("store", "/x/store/getIpList", "GET", "获取门店 ip信息列表")
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
"server/internal/model"
|
||||
ioss "server/utility/oss"
|
||||
@ -28,6 +29,7 @@ func init() {
|
||||
bucketName: g.Config().MustGet(ctx, "oss.aliyun.bucket").String(),
|
||||
}
|
||||
ioss.Register("aliyun", client)
|
||||
glog.Infof(ctx, "注册阿里云OSS成功")
|
||||
}
|
||||
|
||||
func (a *aliyunClient) client(ctx context.Context, endpoint, key, sercret string) (*oss.Client, error) {
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"github.com/alibabacloud-go/tea/tea"
|
||||
"github.com/aliyun/credentials-go/credentials"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"server/internal/model"
|
||||
isms "server/utility/sms"
|
||||
)
|
||||
@ -16,6 +17,9 @@ import (
|
||||
type aliyunClient struct {
|
||||
accessKeyId string
|
||||
accessKeySecret string
|
||||
endpoint string
|
||||
templateId string
|
||||
signName string
|
||||
}
|
||||
|
||||
// 初始化并注册
|
||||
@ -24,16 +28,20 @@ func init() {
|
||||
client := &aliyunClient{
|
||||
accessKeyId: g.Config().MustGet(ctx, "sms.aliyun.accessKeyId").String(),
|
||||
accessKeySecret: g.Config().MustGet(ctx, "sms.aliyun.accessKeySecret").String(),
|
||||
endpoint: g.Config().MustGet(ctx, "sms.aliyun.endpoint").String(),
|
||||
templateId: g.Config().MustGet(ctx, "sms.aliyun.templateId").String(),
|
||||
signName: g.Config().MustGet(ctx, "sms.aliyun.signName").String(),
|
||||
}
|
||||
isms.Register("aliyunsms", client)
|
||||
glog.Infof(ctx, "注册阿里云短信服务成功")
|
||||
}
|
||||
|
||||
func (a *aliyunClient) client(ctx context.Context) (_result *dysmsapi20170525.Client, _err error) {
|
||||
|
||||
config := new(credentials.Config).
|
||||
SetType("access_key").
|
||||
SetAccessKeyId(g.Config().MustGet(ctx, "sms.aliyun.accessKeyId").String()).
|
||||
SetAccessKeySecret(g.Config().MustGet(ctx, "sms.aliyun.accessKeySecret").String())
|
||||
SetAccessKeyId(a.accessKeyId).
|
||||
SetAccessKeySecret(a.accessKeySecret)
|
||||
|
||||
akCredential, err := credentials.NewCredential(config)
|
||||
if err != nil {
|
||||
@ -45,7 +53,7 @@ func (a *aliyunClient) client(ctx context.Context) (_result *dysmsapi20170525.Cl
|
||||
}
|
||||
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
|
||||
config1.Endpoint = tea.String("dysmsapi.aliyuncs.com")
|
||||
config1.Endpoint = tea.String(a.endpoint)
|
||||
_result = &dysmsapi20170525.Client{}
|
||||
_result, _err = dysmsapi20170525.NewClient(config1)
|
||||
|
||||
@ -62,61 +70,25 @@ func (a *aliyunClient) SendCode(ctx context.Context, in *model.SMSCodeIn) (out *
|
||||
// 创建请求对象并设置入参
|
||||
sendSmsRequest := &dysmsapi20170525.SendSmsRequest{
|
||||
// 需替换成为您的短信模板code
|
||||
TemplateCode: tea.String("SMS_154950909"),
|
||||
TemplateCode: tea.String(a.templateId),
|
||||
// 需替换成为您的短信模板变量对应的实际值,示例值:{\"code\":\"1234\"}
|
||||
TemplateParam: tea.String("{\"code\":\"1234\"}"),
|
||||
TemplateParam: tea.String(fmt.Sprintf("{\"code\":\"%s\"}", in.Code)),
|
||||
// 需替换成为您的接收手机号码
|
||||
PhoneNumbers: tea.String(in.Phone),
|
||||
// 需替换成为您的短信签名
|
||||
SignName: tea.String("阿里云短信测试"),
|
||||
SignName: tea.String(a.signName),
|
||||
}
|
||||
|
||||
glog.Infof(ctx, "aliyun sms request: phone: %s, code: %s", in.Phone, in.Code)
|
||||
runtime := &util.RuntimeOptions{}
|
||||
result, _err := client.SendSmsWithOptions(sendSmsRequest, runtime)
|
||||
if _err != nil {
|
||||
return nil, _err
|
||||
}
|
||||
|
||||
if result.Body.Code != tea.String("OK") {
|
||||
if *result.Body.Code != `OK` && *result.Body.Code != `isv.BUSINESS_LIMIT_CONTROL` {
|
||||
glog.Errorf(ctx, "阿里云短信发送失败")
|
||||
return nil, fmt.Errorf("发送短信失败")
|
||||
}
|
||||
//tryErr := func() (_e error) {
|
||||
// defer func() {
|
||||
// if r := tea.Recover(recover()); r != nil {
|
||||
// _e = r
|
||||
// }
|
||||
// }()
|
||||
// // 复制代码运行请自行打印 API 的返回值
|
||||
// result, _err := client.SendSmsWithOptions(sendSmsRequest, runtime)
|
||||
// if _err != nil {
|
||||
// return _err
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
//}()
|
||||
|
||||
//if tryErr != nil {
|
||||
// var error = &tea.SDKError{}
|
||||
// var _t *tea.SDKError
|
||||
// if errors.As(tryErr, &_t) {
|
||||
// error = _t
|
||||
// }
|
||||
// // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// // 错误 message
|
||||
// fmt.Println(tea.StringValue(error.Message))
|
||||
// // 诊断地址
|
||||
// var data interface{}
|
||||
// d := json.NewDecoder(strings.NewReader(tea.StringValue(error.Data)))
|
||||
// d.Decode(&data)
|
||||
// if m, ok := data.(map[string]interface{}); ok {
|
||||
// recommend, _ := m["Recommend"]
|
||||
// fmt.Println(recommend)
|
||||
// }
|
||||
// _, _err = util.AssertAsString(error.Message)
|
||||
// if _err != nil {
|
||||
// return nil, _err
|
||||
// }
|
||||
//}
|
||||
|
||||
glog.Infof(ctx, "阿里云短信发送成功")
|
||||
return &model.SMSCodeOut{Success: true}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user