修改 aliyun,短信,oss,验证码

This commit is contained in:
chy
2025-06-24 16:22:18 +08:00
parent b02ad91118
commit 8342c92247
21 changed files with 219 additions and 128 deletions

View 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
}

View 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
}