|
@@ -9,9 +9,12 @@ import (
|
|
|
"net/url"
|
|
|
"qfw/util"
|
|
|
"qfw/util/mail"
|
|
|
+ "qfw/util/sms"
|
|
|
"regexp"
|
|
|
"strings"
|
|
|
"time"
|
|
|
+
|
|
|
+ "github.com/go-xweb/httpsession"
|
|
|
)
|
|
|
|
|
|
//获取用户合并以前,合并以后的openid
|
|
@@ -146,3 +149,40 @@ func SendMailIdentCode(to, code string, auth []*mail.GmailAuth) bool {
|
|
|
|
|
|
return false
|
|
|
}
|
|
|
+
|
|
|
+//根据模板发送短信,模板是运营商设定的。
|
|
|
+//第三个参数是可变参数,可以传入多个,但要和模板相匹配
|
|
|
+func SendSMS(tplcode /*模板代码*/, mobile /*手机号码*/ string, param map[string]string) {
|
|
|
+ tmp := []string{}
|
|
|
+ for k, v := range param {
|
|
|
+ tmp = append(tmp, "#"+k+"#="+v)
|
|
|
+ }
|
|
|
+ text := strings.Join(tmp, "&")
|
|
|
+ sms.SendSms(mobile, tplcode, text)
|
|
|
+}
|
|
|
+
|
|
|
+//发送验证码
|
|
|
+func SendPhoneIdentCode(phone string, session *httpsession.Session) bool {
|
|
|
+ lastSentTime, _ := session.Get("identCodeTime").(int64)
|
|
|
+ //60秒之内不允许重复发
|
|
|
+ if lastSentTime > 0 && time.Now().Unix()-lastSentTime <= 60 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ s_ranNum := util.GetRandom(6) //生成随机数
|
|
|
+ session.Set("identCodeValue", s_ranNum)
|
|
|
+ session.Set("identCodeKey", phone)
|
|
|
+ session.Set("identCodeTime", time.Now().Unix())
|
|
|
+ //发送短信
|
|
|
+ param := make(map[string]string)
|
|
|
+ param["code"] = s_ranNum
|
|
|
+ log.Println("短信验证码", phone, s_ranNum)
|
|
|
+ SendSMS("2828060", phone, param)
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
+//删除短信验证码有关的session
|
|
|
+func ClearPhoneIdentSession(session *httpsession.Session) {
|
|
|
+ session.Del("identCodeValue")
|
|
|
+ session.Del("identCodeKey")
|
|
|
+ session.Del("identCodeTime")
|
|
|
+}
|