package util

import (
	"fmt"
	"go.uber.org/zap"
	"math/rand"
	"time"
	"ydMonitoring/config"
)

func CreatCode() string {
	const chars = "0123456789"
	result := make([]byte, 6)
	rand.Seed(time.Now().UnixNano())
	for i := range result {
		index := rand.Intn(len(chars))
		result[i] = chars[index]
	}
	return string(result)
}

func SendModel(phone string, msg []string) error {
	ss := NewSMS(config.Config.GetString("submail.appid"), config.Config.GetString("submail.signature"))

	//code := CreatCode()
	content := fmt.Sprintf("【数据预警提示】以下数据出现异常\n：%s", msg)
	res, err := ss.Send(phone, content)
	if err != nil || res.Status != SUCCESS {
		fmt.Println("发送短信验证码出现异常", zap.Any("res", res), zap.Error(err))
		return err
	} else {
		//验证码装入redis并且设置过期时间
		return nil
	}
}
