initial crm server
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"crm/global"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
)
|
||||
|
||||
var signingKey = []byte(global.Config.Jwt.SigningKey)
|
||||
|
||||
// 生成Token
|
||||
func GenToken(uid int64, expire int64) (string, error) {
|
||||
username := strconv.FormatInt(uid, 20)
|
||||
type Claims struct {
|
||||
Username string `json:"username"`
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
claims := Claims{username, jwt.RegisteredClaims{
|
||||
ExpiresAt: &jwt.NumericDate{Time: time.Now().Add(time.Duration(expire) * time.Hour)},
|
||||
Issuer: username,
|
||||
}}
|
||||
token, err := jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString(signingKey)
|
||||
return token, err
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"crm/global"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/gomail.v2"
|
||||
)
|
||||
|
||||
// 发送邮件
|
||||
// QQ邮箱:SMTP 服务器地址:smtp.qq.com(SSL协议端口:465/994 | 非SSL协议端口:25)
|
||||
// 163邮箱:SMTP 服务器地址:smtp.163.com(端口:25)
|
||||
func SendMail(email, content string) error {
|
||||
smtp := global.Config.Mail.Smtp
|
||||
secret := global.Config.Mail.Secret
|
||||
sender := global.Config.Mail.Sender
|
||||
m := gomail.NewMessage()
|
||||
m.SetHeader("From", sender) // 发件人
|
||||
m.SetHeader("To", email) // 收件人,可以多个收件人,但必须使用相同的 SMTP 连接
|
||||
m.SetHeader("Cc", email) // 抄送,可以多个
|
||||
m.SetHeader("Bcc", email) // 暗送,可以多个
|
||||
m.SetHeader("Subject", "ZOCRM") // 邮件主题
|
||||
m.SetBody("text/html", content)
|
||||
d := gomail.NewDialer(smtp, 25, sender, secret)
|
||||
// 关闭SSL协议认证
|
||||
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
if err := d.DialAndSend(m); err != nil {
|
||||
fmt.Printf("qq mail send error : %s", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
func RandInt(min, max int) int {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
if min >= max || min == 0 || max == 0 {
|
||||
return max
|
||||
}
|
||||
return rand.Intn(max-min+1) + min
|
||||
}
|
||||
Reference in New Issue
Block a user