This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
util "github.com/alibabacloud-go/tea-utils/v2/service"
|
util "github.com/alibabacloud-go/tea-utils/v2/service"
|
||||||
"github.com/alibabacloud-go/tea/tea"
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
credential "github.com/aliyun/credentials-go/credentials"
|
credential "github.com/aliyun/credentials-go/credentials"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ type SMSNotifyClient struct {
|
|||||||
|
|
||||||
func NewSMSNotifyClient(cfg *Config) (*SMSNotifyClient, error) {
|
func NewSMSNotifyClient(cfg *Config) (*SMSNotifyClient, error) {
|
||||||
credential, err := credential.NewCredential(&credential.Config{
|
credential, err := credential.NewCredential(&credential.Config{
|
||||||
|
Type: lo.ToPtr("access_key"),
|
||||||
AccessKeyId: lo.ToPtr(cfg.AccessKeyId),
|
AccessKeyId: lo.ToPtr(cfg.AccessKeyId),
|
||||||
AccessKeySecret: lo.ToPtr(cfg.AccessKeySecret),
|
AccessKeySecret: lo.ToPtr(cfg.AccessKeySecret),
|
||||||
})
|
})
|
||||||
@@ -56,6 +58,14 @@ func (c *SMSNotifyClient) SendTo(phone string) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
if resp.Body.Success != nil && !*resp.Body.Success {
|
||||||
|
if resp.Body.Message != nil {
|
||||||
|
return "", errors.New(*resp.Body.Message)
|
||||||
|
}
|
||||||
|
if resp.Body.Code != nil {
|
||||||
|
return "", errors.New(*resp.Body.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return tea.StringValue(resp.Body.Model.VerifyCode), nil
|
return tea.StringValue(resp.Body.Model.VerifyCode), nil
|
||||||
}
|
}
|
||||||
|
|||||||
22
backend_v1/providers/ali/sms_notify_client_test.go
Normal file
22
backend_v1/providers/ali/sms_notify_client_test.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package ali
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewSMSNotifyClient(t *testing.T) {
|
||||||
|
client, err := NewSMSNotifyClient(&Config{
|
||||||
|
AccessKeyId: "LTAI5t86SjiP9zRd3q2w7jQN",
|
||||||
|
AccessKeySecret: "hV7spvJuWh8w0EEIXj8NFi2uBlF4aS",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
code, err := client.SendTo("11101013734")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("Code: %s", code)
|
||||||
|
}
|
||||||
8
backend_v1/utils/json.go
Normal file
8
backend_v1/utils/json.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
func JsonString(v any) string {
|
||||||
|
b, _ := json.Marshal(v)
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user