|
@@ -8,7 +8,6 @@ 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"
|
|
"hongze/hongze_yb_en_api/global"
|
|
"hongze/hongze_yb_en_api/global"
|
|
- "hongze/hongze_yb_en_api/services/english_report"
|
|
|
|
"hongze/hongze_yb_en_api/utils"
|
|
"hongze/hongze_yb_en_api/utils"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
@@ -60,91 +59,91 @@ type AliyunEmailResultData struct {
|
|
RequestId string `description:"请求ID"`
|
|
RequestId string `description:"请求ID"`
|
|
StatusCode int `description:"状态码"`
|
|
StatusCode int `description:"状态码"`
|
|
}
|
|
}
|
|
-
|
|
|
|
-// SendEmail 邮件推送
|
|
|
|
-func (em *AliyunEmail) SendEmail(item *english_report.EnglishReportSendEmailRequest) (ok bool, result string, err error) {
|
|
|
|
- if em.Client == nil {
|
|
|
|
- if e := em.NewClient(); e != nil {
|
|
|
|
- err = e
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- singleSendMailRequest := &dm.SingleSendMailRequest{}
|
|
|
|
- singleSendMailRequest.SetAccountName(AliyunEmailAccountName)
|
|
|
|
- singleSendMailRequest.SetAddressType(1)
|
|
|
|
- singleSendMailRequest.SetReplyToAddress(false)
|
|
|
|
- singleSendMailRequest.SetSubject(item.Subject)
|
|
|
|
- singleSendMailRequest.SetToAddress(item.Email)
|
|
|
|
- singleSendMailRequest.SetHtmlBody(item.HtmlBody)
|
|
|
|
- singleSendMailRequest.SetFromAlias(item.FromAlias)
|
|
|
|
-
|
|
|
|
- runtime := &util.RuntimeOptions{}
|
|
|
|
- tryErr := func() error {
|
|
|
|
- res, e := em.Client.SingleSendMailWithOptions(singleSendMailRequest, runtime)
|
|
|
|
- if e != nil {
|
|
|
|
- return e
|
|
|
|
- }
|
|
|
|
- // 请求成功
|
|
|
|
- if tea.Int32Value(res.StatusCode) == 200 {
|
|
|
|
- ok = true
|
|
|
|
- }
|
|
|
|
- resByte, e := json.Marshal(res.Body)
|
|
|
|
- if e != nil {
|
|
|
|
- return e
|
|
|
|
- }
|
|
|
|
- result = string(resByte)
|
|
|
|
- return nil
|
|
|
|
- }()
|
|
|
|
-
|
|
|
|
- if tryErr != nil {
|
|
|
|
- var e = &tea.SDKError{}
|
|
|
|
- if t, ok := tryErr.(*tea.SDKError); ok {
|
|
|
|
- e = t
|
|
|
|
- } else {
|
|
|
|
- e.Message = tea.String(tryErr.Error())
|
|
|
|
- }
|
|
|
|
- err = e
|
|
|
|
- errByte, _ := json.Marshal(err)
|
|
|
|
- result = string(errByte)
|
|
|
|
- }
|
|
|
|
- return
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// BatchSendEmail 批量推送邮件
|
|
|
|
-func (em *AliyunEmail) BatchSendEmail(list []*english_report.EnglishReportSendEmailRequest) (results []*english_report.EnglishReportSendEmailResult, err error) {
|
|
|
|
- results = make([]*english_report.EnglishReportSendEmailResult, 0)
|
|
|
|
- if len(list) == 0 {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- if e := em.NewClient(); e != nil {
|
|
|
|
- err = e
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // sendSingleMail接口有QPS100的限制, 保险起见每秒只请求50次接口
|
|
|
|
- max := 50
|
|
|
|
- c := 0
|
|
|
|
- for i := range list {
|
|
|
|
- if c >= max {
|
|
|
|
- time.Sleep(time.Second)
|
|
|
|
- c = 0
|
|
|
|
- }
|
|
|
|
- c += 1
|
|
|
|
-
|
|
|
|
- dataByte, _ := json.Marshal(list[i])
|
|
|
|
- ok, result, _ := em.SendEmail(list[i])
|
|
|
|
- results = append(results, &english_report.EnglishReportSendEmailResult{
|
|
|
|
- ReportId: list[i].ReportId,
|
|
|
|
- EmailId: list[i].EmailId,
|
|
|
|
- Email: list[i].Email,
|
|
|
|
- Ok: ok,
|
|
|
|
- SendData: string(dataByte),
|
|
|
|
- ResultData: result,
|
|
|
|
- Source: 1,
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- return
|
|
|
|
-}
|
|
|
|
|
|
+//
|
|
|
|
+//// SendEmail 邮件推送
|
|
|
|
+//func (em *AliyunEmail) SendEmail(item *english_report.EnglishReportSendEmailRequest) (ok bool, result string, err error) {
|
|
|
|
+// if em.Client == nil {
|
|
|
|
+// if e := em.NewClient(); e != nil {
|
|
|
|
+// err = e
|
|
|
|
+// return
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// singleSendMailRequest := &dm.SingleSendMailRequest{}
|
|
|
|
+// singleSendMailRequest.SetAccountName(AliyunEmailAccountName)
|
|
|
|
+// singleSendMailRequest.SetAddressType(1)
|
|
|
|
+// singleSendMailRequest.SetReplyToAddress(false)
|
|
|
|
+// singleSendMailRequest.SetSubject(item.Subject)
|
|
|
|
+// singleSendMailRequest.SetToAddress(item.Email)
|
|
|
|
+// singleSendMailRequest.SetHtmlBody(item.HtmlBody)
|
|
|
|
+// singleSendMailRequest.SetFromAlias(item.FromAlias)
|
|
|
|
+//
|
|
|
|
+// runtime := &util.RuntimeOptions{}
|
|
|
|
+// tryErr := func() error {
|
|
|
|
+// res, e := em.Client.SingleSendMailWithOptions(singleSendMailRequest, runtime)
|
|
|
|
+// if e != nil {
|
|
|
|
+// return e
|
|
|
|
+// }
|
|
|
|
+// // 请求成功
|
|
|
|
+// if tea.Int32Value(res.StatusCode) == 200 {
|
|
|
|
+// ok = true
|
|
|
|
+// }
|
|
|
|
+// resByte, e := json.Marshal(res.Body)
|
|
|
|
+// if e != nil {
|
|
|
|
+// return e
|
|
|
|
+// }
|
|
|
|
+// result = string(resByte)
|
|
|
|
+// return nil
|
|
|
|
+// }()
|
|
|
|
+//
|
|
|
|
+// if tryErr != nil {
|
|
|
|
+// var e = &tea.SDKError{}
|
|
|
|
+// if t, ok := tryErr.(*tea.SDKError); ok {
|
|
|
|
+// e = t
|
|
|
|
+// } else {
|
|
|
|
+// e.Message = tea.String(tryErr.Error())
|
|
|
|
+// }
|
|
|
|
+// err = e
|
|
|
|
+// errByte, _ := json.Marshal(err)
|
|
|
|
+// result = string(errByte)
|
|
|
|
+// }
|
|
|
|
+// return
|
|
|
|
+//}
|
|
|
|
+//
|
|
|
|
+//// BatchSendEmail 批量推送邮件
|
|
|
|
+//func (em *AliyunEmail) BatchSendEmail(list []*english_report.EnglishReportSendEmailRequest) (results []*english_report.EnglishReportSendEmailResult, err error) {
|
|
|
|
+// results = make([]*english_report.EnglishReportSendEmailResult, 0)
|
|
|
|
+// if len(list) == 0 {
|
|
|
|
+// return
|
|
|
|
+// }
|
|
|
|
+// if e := em.NewClient(); e != nil {
|
|
|
|
+// err = e
|
|
|
|
+// return
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // sendSingleMail接口有QPS100的限制, 保险起见每秒只请求50次接口
|
|
|
|
+// max := 50
|
|
|
|
+// c := 0
|
|
|
|
+// for i := range list {
|
|
|
|
+// if c >= max {
|
|
|
|
+// time.Sleep(time.Second)
|
|
|
|
+// c = 0
|
|
|
|
+// }
|
|
|
|
+// c += 1
|
|
|
|
+//
|
|
|
|
+// dataByte, _ := json.Marshal(list[i])
|
|
|
|
+// ok, result, _ := em.SendEmail(list[i])
|
|
|
|
+// results = append(results, &english_report.EnglishReportSendEmailResult{
|
|
|
|
+// ReportId: list[i].ReportId,
|
|
|
|
+// EmailId: list[i].EmailId,
|
|
|
|
+// Email: list[i].Email,
|
|
|
|
+// Ok: ok,
|
|
|
|
+// SendData: string(dataByte),
|
|
|
|
+// ResultData: result,
|
|
|
|
+// Source: 1,
|
|
|
|
+// })
|
|
|
|
+// }
|
|
|
|
+// return
|
|
|
|
+//}
|
|
|
|
|
|
// sendEmailVerificationCode 邮件验证码推送
|
|
// sendEmailVerificationCode 邮件验证码推送
|
|
func (em *AliyunEmail) sendEmailVerificationCode(email, content string) (ok bool, result string, err error) {
|
|
func (em *AliyunEmail) sendEmailVerificationCode(email, content string) (ok bool, result string, err error) {
|