2024-08-20 13:08:00 +00:00
|
|
|
package usecase
|
|
|
|
|
|
|
|
import (
|
|
|
|
"app-cloudep-notification-service/internal/config"
|
|
|
|
"app-cloudep-notification-service/internal/domain/usecase"
|
|
|
|
"context"
|
2024-08-20 15:53:20 +00:00
|
|
|
|
2024-08-20 13:08:00 +00:00
|
|
|
"github.com/minchao/go-mitake"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SMSUseCaseParam struct {
|
|
|
|
Conf config.Config
|
|
|
|
}
|
|
|
|
|
|
|
|
type SMSUseCase struct {
|
|
|
|
Client *mitake.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SMSUseCase) SendSMS(_ context.Context, req usecase.SMSReq) error {
|
|
|
|
message := mitake.Message{
|
|
|
|
Dstaddr: req.RecipientAddress,
|
|
|
|
Destname: req.RecipientName,
|
|
|
|
Smbody: req.Body,
|
|
|
|
}
|
|
|
|
_, err := s.Client.Send(message)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func MustMitakeUseCase(param SMSUseCaseParam) usecase.SMSClientUseCase {
|
|
|
|
return &SMSUseCase{
|
|
|
|
Client: mitake.NewClient(param.Conf.SMSSender.User, param.Conf.SMSSender.Password, nil),
|
|
|
|
}
|
|
|
|
}
|