修改 aliyun,短信,oss,验证码
This commit is contained in:
@ -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)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user