102 lines
2.3 KiB
Go
102 lines
2.3 KiB
Go
package logic
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"fusenapi/utils/wevent"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"net/smtp"
|
|
"testing"
|
|
|
|
"github.com/474420502/requests"
|
|
"github.com/google/uuid"
|
|
"github.com/gorilla/mux"
|
|
"github.com/rs/cors"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
func TestEmailSend(t *testing.T) {
|
|
|
|
// 设置发件人和收件人信息
|
|
from := "support@fusenpack.com"
|
|
to := []string{"474420502@qq.com"}
|
|
|
|
// 设置smtp服务器地址,端口和认证信息
|
|
smtpServer := "smtp.gmail.com"
|
|
|
|
auth := smtp.PlainAuth("", "support@fusenpack.com", "wfbjpdgvaozjvwah", smtpServer)
|
|
|
|
subject := "Subject: Test email from Go!\n"
|
|
mime := "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n"
|
|
body := "<html><body><h1>Hello World!</h1></body></html>"
|
|
msg := []byte(subject + mime + body)
|
|
|
|
// 发送邮件
|
|
err := smtp.SendMail(smtpServer+":587", auth, from, to, msg)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestPost(t *testing.T) {
|
|
r := mux.NewRouter()
|
|
|
|
r.HandleFunc("/aaa", func(w http.ResponseWriter, r *http.Request) {
|
|
d, _ := io.ReadAll(r.Body)
|
|
log.Println(string(d))
|
|
}).Methods("POST")
|
|
|
|
handler := cors.Default().Handler(r)
|
|
|
|
log.Println("Server listening on :2223")
|
|
log.Fatal(http.ListenAndServe(":2223", handler))
|
|
}
|
|
|
|
func TestEmailTpl(t *testing.T) {
|
|
data := map[string]string{
|
|
"CompanyName": "companyName",
|
|
"ConfirmationLink": "confirmationLink",
|
|
"SenderName": "senderName",
|
|
"SenderTitle": "senderTitle",
|
|
}
|
|
|
|
var result bytes.Buffer
|
|
err := tpls.ExecuteTemplate(&result, "email_register.tpl", data)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
log.Println(string(result.String()))
|
|
|
|
}
|
|
|
|
func TestSender(t *testing.T) {
|
|
traceId := uuid.NewString()
|
|
event := wevent.NewWebsocketEventSuccess(wevent.UserEmailRegister, traceId)
|
|
event.Data = wevent.DataEmailRegister{
|
|
JwtToken: traceId,
|
|
}
|
|
|
|
tp := requests.Post(fmt.Sprintf("%s/api/websocket/common_notify", "https://server.fusen.3718.cn:9900"))
|
|
tp.SetBodyJson(requests.M{
|
|
"wid": "tGyMYX9EldtsPLZTyT6PxrRgEV615CQGEiu9Sb1XrjZ4kpTjI46sQyh7kYfVlgN9uR5Uw4KDF+S62IknmaRgSMdee1QHVtCv+VEKrMF76snR04zS1ZbWZCgX5Lv2xgHz/bZBWwJF/9u6YTy2/FetGg==",
|
|
"data": event,
|
|
})
|
|
|
|
wresp, err := tp.Execute()
|
|
if err != nil {
|
|
logx.Error(err, "traceId")
|
|
return
|
|
}
|
|
|
|
result := wresp.Json()
|
|
if result.Get("code").Int() != 200 {
|
|
logx.Error(result.Get("message"))
|
|
return
|
|
}
|
|
log.Println(result)
|
|
|
|
}
|