code
This commit is contained in:
@ -11,10 +11,12 @@ import (
|
|||||||
"go-admin/common/const/rediskey"
|
"go-admin/common/const/rediskey"
|
||||||
"go-admin/common/global"
|
"go-admin/common/global"
|
||||||
"go-admin/common/helper"
|
"go-admin/common/helper"
|
||||||
|
"go-admin/pkg/emailhelper"
|
||||||
"go-admin/pkg/utility"
|
"go-admin/pkg/utility"
|
||||||
"go-admin/pkg/utility/snowflakehelper"
|
"go-admin/pkg/utility/snowflakehelper"
|
||||||
"go-admin/services/binanceservice"
|
"go-admin/services/binanceservice"
|
||||||
"go-admin/services/fileservice"
|
"go-admin/services/fileservice"
|
||||||
|
"gorm.io/driver/mysql"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -339,15 +341,33 @@ func (l ListenSymbol) Exec(arg interface{}) error {
|
|||||||
db = item
|
db = item
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
set, err := helper.DefaultRedis.GetAllSortSet(rediskey.ListenAveLastSymbol)
|
if db == nil {
|
||||||
|
dsn := "root:root@tcp(192.168.1.12:3306)/go_exchange_single?charset=utf8mb4&parseTime=True&loc=Local&timeout=1000ms"
|
||||||
|
db, _ = gorm.Open(mysql.Open(dsn), &gorm.Config{})
|
||||||
|
}
|
||||||
|
var req = new(dto.SysConfigByKeyReq)
|
||||||
|
var configResp = new(dto.GetSysConfigByKEYForServiceResp)
|
||||||
|
req.ConfigKey = "EmailAddress"
|
||||||
|
serviceConfig := service.SysConfig{}
|
||||||
|
serviceConfig.Orm = db
|
||||||
|
serviceConfig.GetWithKey(req, configResp)
|
||||||
|
if configResp.ConfigValue == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
symbols := make([]models.SpiderListenSymbol, 0)
|
||||||
|
err := db.Model(&models.SpiderListenSymbol{}).Find(&symbols).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("获取监听交易对失败")
|
logger.Error("获取监听交易对失败")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println(set)
|
var set []string
|
||||||
//if len(set) == 0 {
|
for _, symbol := range symbols {
|
||||||
// return nil
|
set = append(set, symbol.Coin+symbol.Currency)
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
if len(set) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
aveToken, _ := helper.DefaultRedis.GetString(rediskey.AveRequestToken)
|
aveToken, _ := helper.DefaultRedis.GetString(rediskey.AveRequestToken)
|
||||||
if aveToken == "" {
|
if aveToken == "" {
|
||||||
@ -366,12 +386,13 @@ func (l ListenSymbol) Exec(arg interface{}) error {
|
|||||||
}
|
}
|
||||||
for _, symbol := range symbols.Data.Data {
|
for _, symbol := range symbols.Data.Data {
|
||||||
if slices.Contains(set, symbol.Token0Symbol+symbol.Token1Symbol) {
|
if slices.Contains(set, symbol.Token0Symbol+symbol.Token1Symbol) {
|
||||||
|
|
||||||
// 清除数据
|
|
||||||
|
|
||||||
//发送邮箱
|
//发送邮箱
|
||||||
l.SendEmailNotice(db, symbol.Pair, symbol.Token0Symbol+symbol.Token1Symbol, chain)
|
emails := strings.Split(configResp.ConfigValue, ",")
|
||||||
|
for _, email := range emails {
|
||||||
|
emailhelper.SendNoticeEmail(email, chain, symbol.Token0Symbol+"/"+symbol.Token1Symbol, symbol.Pair)
|
||||||
|
}
|
||||||
|
// 清除数据
|
||||||
|
db.Model(&models.SpiderListenSymbol{}).Where("coin = ? AND currency = ?", symbol.Token0Symbol, symbol.Token1Symbol).Delete(&models.SpiderListenSymbol{})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -484,11 +505,3 @@ func (l ListenSymbol) GetAveLastSymbol(chain, token string) (aveLastSymbolResp A
|
|||||||
return res, nil
|
return res, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendEmailNotice 发送邮箱通知
|
|
||||||
// pair 合约地址
|
|
||||||
// symbol 完整交易对
|
|
||||||
// chain 链
|
|
||||||
func (l ListenSymbol) SendEmailNotice(db *gorm.DB, pair string, symbol string, chain string) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@ -75,6 +75,41 @@ func SendFrontedEmail(toEmail string, code string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendNoticeEmail 发送通知邮件
|
||||||
|
func SendNoticeEmail(toEmail string, chain string, symbol string, pair string) error {
|
||||||
|
// 邮箱配置
|
||||||
|
from := config.ExtConfig.EmailConfig.MailFrom // 发送者邮箱
|
||||||
|
password := config.ExtConfig.EmailConfig.MailSmtpPass // Gmail 密码或应用专用密码
|
||||||
|
to := toEmail // 收件人邮箱
|
||||||
|
smtpHost := config.ExtConfig.EmailConfig.MailSmtpHost // Gmail SMTP 服务器
|
||||||
|
smtpPort := config.ExtConfig.EmailConfig.MailSmtpPort // SMTP 端口
|
||||||
|
|
||||||
|
//from = "daichaodsy@163.com"
|
||||||
|
//password = "QCKTZWTREARMGDZN"
|
||||||
|
//smtpPort = "465"
|
||||||
|
//smtpHost = "smtp.163.com"
|
||||||
|
//link := fmt.Sprintf("%s/verify?email=%s&verify_code=%s&type=register", config.ExtConfig.Domain, toEmail, code)
|
||||||
|
// 创建邮件消息
|
||||||
|
subject := "新币发布通知"
|
||||||
|
body := fmt.Sprintf("<h1>代币发布</h1><p> 区块链信息: %s <p> 交易对: %s </p> <p> 合约地址: %s </p> </p>", chain, symbol, pair)
|
||||||
|
|
||||||
|
m := gomail.NewMessage()
|
||||||
|
m.SetHeader("From", from) // 发件人
|
||||||
|
m.SetHeader("To", to) // 收件人
|
||||||
|
m.SetHeader("Subject", subject) // 邮件主题
|
||||||
|
m.SetBody("text/html", body) // 邮件内容(纯文本)
|
||||||
|
|
||||||
|
// 设置 SMTP 服务器信息
|
||||||
|
d := gomail.NewDialer(smtpHost, utility.StringToInt(smtpPort), from, password)
|
||||||
|
|
||||||
|
// 发送邮件
|
||||||
|
if err := d.DialAndSend(m); err != nil {
|
||||||
|
log.Error("发送邮件失败: %v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// SendEmail 发送邮件
|
// SendEmail 发送邮件
|
||||||
//func SendEmail(send config.EmailSend) (string, bool) {
|
//func SendEmail(send config.EmailSend) (string, bool) {
|
||||||
// m := gomail.NewMessage()
|
// m := gomail.NewMessage()
|
||||||
|
|||||||
Reference in New Issue
Block a user