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