| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 | package smsMgrimport (	"encoding/json"	"math/rand"	"sync"	"time"	"github.com/GiterLab/aliyun-sms-go-sdk/dysms"	"github.com/tobyzxj/uuid")const (	signName  = "华力机电"	accessID  = "QtFHg1yctStmJlH8"	accessKey = "uGkK7A0C1mjXDPvZnnJ0oaZ5qu3ORX"	smsTmp    = "SMS_213086656")var (	mutex    sync.Mutex	codeList = make(map[string]int64))func SendCode(phone string) error {	rand.Seed(time.Now().UnixNano())	code := rand.Int63n(99999-10000) + 10000	body, err := json.Marshal(map[string]interface{}{"code": code})	if err != nil {		return err	}	dysms.HTTPDebugEnable = false	dysms.SetACLClient(accessID, accessKey)	_, err = dysms.SendSms(uuid.New(), phone, signName, smsTmp, string(body)).DoActionWithException()	if err != nil {		return err	}	mutex.Lock()	codeList[phone] = code	mutex.Unlock()	return nil}func GetCode(phone string) (int64, bool) {	mutex.Lock()	v, ok := codeList[phone]	delete(codeList, phone)	mutex.Unlock()	return v, ok}
 |