You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
203 lines
5.3 KiB
203 lines
5.3 KiB
package call |
|
|
|
import ( |
|
"crypto/tls" |
|
"encoding/json" |
|
"errors" |
|
"fmt" |
|
"math/rand" |
|
"net/smtp" |
|
"server/common" |
|
"server/config" |
|
"server/db" |
|
"strings" |
|
"time" |
|
|
|
"github.com/liangdas/mqant/log" |
|
) |
|
|
|
const ( |
|
RealMailSuccessTitle = "Withdrawal succeeded! [%v]" |
|
RealMailSuccessContext = "Deal %v:\n" + |
|
"\n" + |
|
"Congratulations! Your latest withdrawal has been successfully transferred to your bank account. Please check your account." + |
|
"If there is any question about this order, please feel free to contact our customer service below.\n" + |
|
"\n" + |
|
"Email:%v\n" + |
|
"\n" + |
|
"Whatsapp:%v\n" + |
|
"\n" + |
|
"Thanks for your playing!\n" + |
|
"\n" + |
|
"\n" + |
|
"Best wishes\n" + |
|
"\n" + |
|
"%v" |
|
RealMailFailTitle = "Withdrawal failure! [%v]" |
|
RealMailFailContext = "Deal %v:\n" + |
|
"\n" + |
|
"Important information about your withdrawal order:\n" + |
|
"\n" + |
|
"AccountName:%v\n" + |
|
"\n" + |
|
"Mobile:%v\n" + |
|
"\n" + |
|
"%v\n" + |
|
"\n" + |
|
"Your latest withdrawal order has failed for the following reasons:\n" + |
|
"\n" + |
|
"\t1.Wrong UPI/BANK information you submitted. Please CAREFULLY check your UPI/BANK information and try to withdraw again:\n" + |
|
"\n" + |
|
"\t\t(1) The UPI/BANK account shall not have any space;\n" + |
|
"\t\t(2) The bank IFSC Code shall be 11 digital letters formatted as 'AAAA0XXXXXX;\n" + |
|
"\n" + |
|
"\t2.Bank refused. The bank refused this order because of your bank account problems.\n" + |
|
"\n" + |
|
"If withdrawal still fails after all your information was checked, please get in touch with customer service:\n" + |
|
"\n" + |
|
"\t1.Email:%v\n" + |
|
"\t2.Whatsapp:%v\n" + |
|
"\n" + |
|
"Do not worry! The refunds of the withdrawal order that failed will be returned to your game account.\n" + |
|
"\n" + |
|
"\n" + |
|
"Kind regards\n" + |
|
"\n" + |
|
"%v" |
|
) |
|
|
|
type realMail struct { |
|
user string |
|
passwd string |
|
} |
|
|
|
// 初始化用户名和密码 |
|
func NewMail(u string, p string) *realMail { |
|
temp := &realMail{user: u, passwd: p} |
|
return temp |
|
} |
|
|
|
// 标题 文本 目标邮箱 |
|
func (m *realMail) Send(title string, text string, toId string) error { |
|
auth := smtp.PlainAuth("", m.user, m.passwd, "smtp.gmail.com") |
|
|
|
tlsconfig := &tls.Config{ |
|
InsecureSkipVerify: true, |
|
ServerName: "smtp.gmail.com", |
|
} |
|
|
|
conn, err := tls.Dial("tcp", "smtp.gmail.com:465", tlsconfig) |
|
if err != nil { |
|
log.Error("real:%+v,err:%v", *m, err) |
|
return err |
|
} |
|
|
|
client, err := smtp.NewClient(conn, "smtp.gmail.com") |
|
if err != nil { |
|
log.Error("real:%+v,err:%v", *m, err) |
|
return err |
|
} |
|
|
|
if err = client.Auth(auth); err != nil { |
|
log.Error("real:%+v,err:%v", *m, err) |
|
return err |
|
} |
|
|
|
if err = client.Mail(m.user); err != nil { |
|
log.Error("real:%+v,err:%v", *m, err) |
|
return err |
|
} |
|
|
|
if err = client.Rcpt(toId); err != nil { |
|
log.Error("real:%+v,toId:%v,err:%v", *m, toId, err) |
|
return err |
|
} |
|
|
|
w, err := client.Data() |
|
if err != nil { |
|
log.Error("real:%+v,err:%v", *m, err) |
|
return err |
|
} |
|
|
|
msg := fmt.Sprintf("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s", m.user, toId, title, text) |
|
|
|
_, err = w.Write([]byte(msg)) |
|
if err != nil { |
|
log.Error("real:%+v,err:%v", *m, err) |
|
return err |
|
} |
|
|
|
err = w.Close() |
|
if err != nil { |
|
log.Error("real:%+v,err:%v", *m, err) |
|
return err |
|
} |
|
|
|
client.Quit() |
|
return nil |
|
} |
|
|
|
// SendRealWithdrawMail 给玩家真实的邮箱发送邮件 |
|
func SendRealWithdrawMail(or *common.WithdrawOrder) error { |
|
withdrawCommon := &common.WithdrawCommon{} |
|
if err := json.Unmarshal([]byte(or.PayAccount), withdrawCommon); err != nil { |
|
log.Error("err:%v", err) |
|
return err |
|
} |
|
if withdrawCommon.Email == "" { |
|
log.Error("or:%+v,withdrawCommon:%+v,email is null", or, withdrawCommon) |
|
return fmt.Errorf("or:%+v,email is null", or) |
|
} |
|
if strings.Contains(GetConfigPlatform().Email, withdrawCommon.Email) { |
|
return nil |
|
} |
|
accounts := config.GetBase().Mails.Accounts |
|
if len(accounts) == 0 { |
|
return nil |
|
} |
|
|
|
channel := GetChannelByID(or.ChannelID) |
|
if channel == nil { |
|
return errors.New("unknown channel") |
|
} |
|
title := "" |
|
context := "" |
|
status := 0 |
|
if or.Status == common.StatusROrderFail { |
|
status = 0 |
|
payInfo := "" |
|
// if withdrawCommon.DrawType == common.WithdrawTypeUPI { |
|
// payInfo = fmt.Sprintf("UPI Account:%v", withdrawCommon.BankCode) |
|
// } else if withdrawCommon.DrawType == common.WithdrawTypeBank { |
|
// payInfo = fmt.Sprintf("BankCard Number:%v\n\nIFSC Code:%v", withdrawCommon.BankCardNo, withdrawCommon.BankCode) |
|
// } |
|
title = fmt.Sprintf(RealMailFailTitle, channel.Name) |
|
context = fmt.Sprintf(RealMailFailContext, withdrawCommon.Name, withdrawCommon.Name, |
|
withdrawCommon.Mobile, payInfo, GetConfigPlatform().Email, GetConfigPlatform().Whatsapp, channel.Name) |
|
} else if or.Status == common.StatusROrderFinish { |
|
status = 1 |
|
title = fmt.Sprintf(RealMailSuccessTitle, channel.Name) |
|
context = fmt.Sprintf(RealMailSuccessContext, withdrawCommon.Name, GetConfigPlatform().Email, |
|
GetConfigPlatform().Whatsapp, channel.Name) |
|
} |
|
if db.Redis().Exist(common.GetRedisKeyRealMail(or.UID, status)) { |
|
return nil |
|
} |
|
|
|
pass := config.GetBase().Mails.Pass |
|
rans := rand.Perm(len(accounts)) |
|
// 只尝试一次 |
|
for i := 0; i < 1; i++ { |
|
index := rans[i] |
|
if index > len(pass)-1 { |
|
break |
|
} |
|
m := NewMail(accounts[index], pass[index]) |
|
if err := m.Send(title, context, withdrawCommon.Email); err == nil { |
|
// 每24小时同类型邮件只发送一次 |
|
db.Redis().SetData(common.GetRedisKeyRealMail(or.UID, status), 1, 24*time.Hour) |
|
return nil |
|
} |
|
} |
|
return errors.New("send fail") |
|
}
|
|
|