33 lines
634 B
Go
33 lines
634 B
Go
package globals
|
|
|
|
import (
|
|
"fmt"
|
|
"platform/pkg/env"
|
|
"platform/pkg/u"
|
|
|
|
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
|
sms "github.com/alibabacloud-go/dysmsapi-20170525/v4/client"
|
|
)
|
|
|
|
var Aliyun *aliyunClient
|
|
|
|
type aliyunClient struct {
|
|
Sms *sms.Client
|
|
}
|
|
|
|
func initAliyun() error {
|
|
client, err := sms.NewClient(&openapi.Config{
|
|
AccessKeyId: &env.AliyunAccessKey,
|
|
AccessKeySecret: &env.AliyunAccessKeySecret,
|
|
Endpoint: u.P("dysmsapi.aliyuncs.com"),
|
|
})
|
|
if err != nil {
|
|
return fmt.Errorf("初始化阿里云客户端失败: %w", err)
|
|
}
|
|
|
|
Aliyun = &aliyunClient{
|
|
Sms: client,
|
|
}
|
|
return nil
|
|
}
|