renzheng 7 роки тому
батько
коміт
efd7095c55

+ 31 - 10
jyservice/src/config.json

@@ -1,12 +1,33 @@
 {
- "webport":":8801",
- "mongodb": {
-		"addr":"192.168.3.207:27080",
-		"db":"jyqyfw",
-		"pool":10
-	},
-	"redis":{
-		"addr":"jyqyfw=192.168.3.207:1380",
-		"pool":50
-	}
+    "webport": ":8801",
+    "mongodb": {
+        "addr": "192.168.3.207:27080",
+        "db": "jyqyfw",
+        "pool": 10
+    },
+    "redis": {
+        "addr": "jyqyfw=192.168.3.207:1380",
+        "pool": 50
+    },
+	"loglevel":5,
+    "plan": {
+        "A": {
+            "title": 1,
+            "detail": 1,
+            "publishtime": 1,
+            "href": 1
+        },
+        "B": {
+            "title": 1,
+            "detail": 1,
+            "publishtime": 1,
+            "href": 1,
+            "area": 1,
+            "toptype": 1,
+            "budget": 1,
+            "bidamount": 1,
+            "bidopentime": 1,
+            "buyer": 1
+        }
+    }
 }

+ 18 - 14
jyservice/src/usermanager/access_token.go

@@ -9,7 +9,7 @@ import (
 	"time"
 	. "utils"
 
-	//log "github.com/sirupsen/logrus"
+	log "github.com/sirupsen/logrus"
 )
 
 const (
@@ -28,7 +28,8 @@ func GetAccessToken(w http.ResponseWriter, r *http.Request) {
 		res, b := Mgo.FindOneByField("user", &map[string]interface{}{
 			"appid": appid,
 			"key":   key,
-		}, `{"_id":1}`)
+		}, `{"plan":1}`)
+		log.Debug(res, b)
 		if b && res != nil && *res != nil {
 			GetDataMapLock.Lock()
 			appidLock := GetDataMap[appid]
@@ -43,19 +44,22 @@ func GetAccessToken(w http.ResponseWriter, r *http.Request) {
 			limitKey := fmt.Sprintf("tokenlimit_%d_%s", t.Day(), appid)
 			limit := redis.GetInt(REDISDB, limitKey)
 			if limit < TOKEN_LIMIT_TIMES {
-				access_token := RsaEncrypt(fmt.Sprintf("%d,%s,%s", t.Unix(), appid, key))
-				if access_token != "" {
-					if redis.Put(REDISDB, "token_"+appid, access_token, TOKEN_TIMEOUT) {
-						d["access_token"] = url.QueryEscape(access_token)
-						if limit == 0 {
-							tn := time.Date(t.Year(), t.Month(), t.Day()+1, 0, 0, 0, 0, time.Local).Unix()
-							expire := int(tn - t.Unix())
-							limit++
-							redis.Put(REDISDB, limitKey, limit, expire)
-						} else {
-							redis.Incr(REDISDB, limitKey)
+				plan, _ := (*res)["plan"].(map[string]interface{})
+				if plan != nil && plan["name"] != nil {
+					access_token := RsaEncrypt(fmt.Sprintf("%d,%s,%s,%s", t.Unix(), appid, key, plan["name"]))
+					if access_token != "" {
+						if redis.Put(REDISDB, "token_"+appid, access_token, TOKEN_TIMEOUT) {
+							d["access_token"] = url.QueryEscape(access_token)
+							if limit == 0 {
+								tn := time.Date(t.Year(), t.Month(), t.Day()+1, 0, 0, 0, 0, time.Local).Unix()
+								expire := int(tn - t.Unix())
+								limit++
+								redis.Put(REDISDB, limitKey, limit, expire)
+							} else {
+								redis.Incr(REDISDB, limitKey)
+							}
+							d["expires_in"] = TOKEN_TIMEOUT
 						}
-						d["expires_in"] = TOKEN_TIMEOUT
 					}
 				}
 				if len(d) == 0 {

+ 13 - 4
jyservice/src/usermanager/getdata.go

@@ -50,13 +50,14 @@ func GetAllData(w http.ResponseWriter, r *http.Request) {
 func CheckUserInfo(access_token string, day, next, all int) (bcheck bool, appid string, d JSON) {
 	d = JSON{}
 	//第一层判断token是否失效或格式不对
+	planname := ""
 	if access_token != "" {
 		at := RsaDecrypt(access_token)
 		log.Debug("token:", at)
 		if at != "" {
 			tn := time.Now().Unix()
 			arr := strings.Split(at, ",")
-			if len(arr) == 3 { //时间,appid,key
+			if len(arr) == 4 { //时间,appid,key,套餐
 				t := util.Int64All(arr[0])
 				des := tn - t
 				log.Debug("des", des)
@@ -66,6 +67,7 @@ func CheckUserInfo(access_token string, day, next, all int) (bcheck bool, appid
 					log.Debug("redis_token", "\t", redis_token, "\t", access_token)
 					if redis_token != "" && redis_token == access_token { //token验证通过,验证今日次数、总条数、服务时间
 						bcheck = true
+						planname = arr[3]
 					} else {
 						d["code"] = CODE_TOKEN_EXPIRE
 						d["msg"] = MSG_TOKEN_EXPIRE
@@ -164,7 +166,14 @@ func CheckUserInfo(access_token string, day, next, all int) (bcheck bool, appid
 		}
 		//判断通过
 		if bcheck { //取数据
-			next, infos := getDataByAppid(appid, day, next, all, limittodaykey)
+			pn := planname[:1]
+			var fields map[string]interface{}
+			if pn == "A" {
+				fields = A
+			} else if pn == "B" {
+				fields = B
+			}
+			next, infos := getDataByAppid(appid, day, next, all, limittodaykey, fields)
 			if all == 1 && next > 0 {
 				d["next"] = next
 			}
@@ -179,7 +188,7 @@ func CheckUserInfo(access_token string, day, next, all int) (bcheck bool, appid
 }
 
 //获取数据
-func getDataByAppid(appid string, i_day, next, i_all int, limittodaykey string) (i_next int, infos []map[string]interface{}) {
+func getDataByAppid(appid string, i_day, next, i_all int, limittodaykey string, fields map[string]interface{}) (i_next int, infos []map[string]interface{}) {
 	query := map[string]interface{}{"appid": appid}
 	blastid := false
 	if i_all == 0 { //必须是当天才能使用lastid按顺序取信息
@@ -201,7 +210,7 @@ func getDataByAppid(appid string, i_day, next, i_all int, limittodaykey string)
 
 	log.Debug("query:", query)
 	i_next = next
-	data, bdata := Mgo.Find("usermail", query, `{"_id":1}`, `{"title":1,"detail":1,"publishtime":1,"href":1}`, false, i_next, QUERY_LIMIT)
+	data, bdata := Mgo.Find("usermail", query, `{"_id":1}`, fields, false, i_next, QUERY_LIMIT)
 	if bdata && data != nil && *data != nil && len(*data) > 0 {
 		infos = *data
 		if blastid {

+ 8 - 2
jyservice/src/utils/utils.go

@@ -40,10 +40,13 @@ const (
 
 var (
 	Sysconfig map[string]interface{}
+	A         map[string]interface{}
+	B         map[string]interface{}
 )
 
 func init() {
 	//初始化日志
+	util.ReadConfig(&Sysconfig)
 	t := &log.TextFormatter{}
 	t.TimestampFormat = "01-02 15:04:05.000"
 	t.ForceColors = true
@@ -51,8 +54,11 @@ func init() {
 	t.FullTimestamp = true
 	log.SetFormatter(t)
 	log.SetOutput(os.Stdout)
-	log.SetLevel(log.DebugLevel)
-	util.ReadConfig(&Sysconfig)
+	log.SetLevel(log.Level(util.IntAllDef(Sysconfig["loglevel"], 5)))
+	//
+	plan, _ := Sysconfig["plan"].(map[string]interface{})
+	A = plan["A"].(map[string]interface{})
+	B = plan["B"].(map[string]interface{})
 	initmongo()
 	redisconf := Sysconfig["redis"].(map[string]interface{})
 	redis.InitRedisBySize(util.ObjToString(redisconf["addr"]), util.IntAllDef(redisconf["pool"], 10), 20, 240)