|
@@ -9,6 +9,7 @@ import (
|
|
|
"fmt"
|
|
|
"net/http"
|
|
|
"qfw/util"
|
|
|
+ "regexp"
|
|
|
"time"
|
|
|
. "utils"
|
|
|
|
|
@@ -26,9 +27,10 @@ var (
|
|
|
func NewUser(w http.ResponseWriter, r *http.Request) {
|
|
|
username := r.FormValue("username")
|
|
|
t := time.Now()
|
|
|
- randomstr := util.GetLetterRandom(5)
|
|
|
- str := fmt.Sprintf("%s%d%s", randomstr[:2], t.Unix(), randomstr[2:])
|
|
|
- appid := "jy" + EncodeUtil.EncodeString(str)
|
|
|
+ // randomstr := util.GetLetterRandom(5)
|
|
|
+ // str := fmt.Sprintf("%s%d%s", randomstr[:2], t.Unix(), randomstr[2:])
|
|
|
+ // appid := "jy" + EncodeUtil.EncodeString(str)
|
|
|
+ appid := GetAppid(t.Unix())
|
|
|
key := util.GetComplexRandom(8, 3, 5)
|
|
|
id := Mgo.Save("user", &map[string]interface{}{"username": username, "createtime": t.Unix(), "appid": appid, "key": key})
|
|
|
log.Debug("create user success!", "\t", username)
|
|
@@ -39,6 +41,21 @@ func NewUser(w http.ResponseWriter, r *http.Request) {
|
|
|
WriteJSON(w, &ret)
|
|
|
}
|
|
|
|
|
|
+var strReg = regexp.MustCompile("^[0-9a-zA-Z]+$")
|
|
|
+
|
|
|
+func GetAppid(tn int64) (appid string) {
|
|
|
+ for {
|
|
|
+ randomstr := util.GetLetterRandom(5)
|
|
|
+ str := fmt.Sprintf("%s%d%s", randomstr[:2], tn, randomstr[2:])
|
|
|
+ appid = EncodeUtil.EncodeString(str)
|
|
|
+ if strReg.MatchString(appid) {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ appid = "jy" + appid
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
//购买服务
|
|
|
func NewService(w http.ResponseWriter, r *http.Request) {
|
|
|
appid := r.FormValue("appid")
|