package utils
import (
"context"
"errors"
"shop-api/global"
"shop-api/initialize/api"
)
func SendSms(phone, code string, types int) error {
var (
reply *api.SendSmsReply
err error
)
reply, err = global.SMS_CLIENT.SendMessage(context.Background(), &api.SendSmsRequest{
Phone: phone,
SmsType: int32(types),
AreaCode: code,
})
if err != nil {
return err
}
if reply.Code != 0 {
return errors.New(reply.Message)
}
return nil
}
func SendEmail(email, types string) (string, error) {
var (
reply *api.SendEmailReply
err error
)
code := GetInvitation()
str := `To authorise your Login request , please use this One Time Password (OTP): ` + code
if types == "2" {
str = `To authorise your forgot password , please use this One Time Password (OTP): ` + code
}
body := `
|
Ouction NFT
` + str + `
Thank you.
Ouction Team
|
|
|
|
`
reply, err = global.EMAIL_CLIENT.SendEmail(context.Background(), &api.SendRequest{
To: []string{email},
Subject: "验证码",
Body: body,
})
if err != nil {
return "", err
}
if reply.Code != 0 {
return "", errors.New(reply.Message)
}
return code, nil
}