Browse Source

完善api

renzheng 7 years ago
parent
commit
4032994bb9

+ 3 - 2
jyservice/src/usermanager/access_token.go

@@ -4,12 +4,13 @@ import (
 	"fmt"
 	"net/http"
 	"net/url"
+	"qfw/util"
 	"qfw/util/redis"
 	"sync"
 	"time"
 	. "utils"
 
-	log "github.com/sirupsen/logrus"
+	//log "github.com/sirupsen/logrus"
 )
 
 const (
@@ -21,6 +22,7 @@ const (
 //jyqyfw/user表
 //用户的accesstoken维护,每个用户分配一个 应用id=appid,用户密钥=key
 func GetAccessToken(w http.ResponseWriter, r *http.Request) {
+	defer util.Catch()
 	d := JSON{}
 	appid := r.FormValue("appid")
 	key := r.FormValue("key")
@@ -29,7 +31,6 @@ func GetAccessToken(w http.ResponseWriter, r *http.Request) {
 			"appid": appid,
 			"key":   key,
 		}, `{"plan":1}`)
-		log.Debug(res, b)
 		if b && res != nil && *res != nil {
 			GetDataMapLock.Lock()
 			appidLock := GetDataMap[appid]

+ 1 - 0
jyservice/src/usermanager/getdata.go

@@ -48,6 +48,7 @@ func GetAllData(w http.ResponseWriter, r *http.Request) {
 }
 
 func CheckUserInfo(access_token string, day, next, all int) (bcheck bool, appid string, d JSON) {
+	defer util.Catch()
 	d = JSON{}
 	//第一层判断token是否失效或格式不对
 	planname := ""

+ 20 - 3
jyservice/src/usermanager/user.go

@@ -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")