renzheng 7 ani în urmă
părinte
comite
161adcd4ee

+ 12 - 0
jyservice/src/config.json

@@ -0,0 +1,12 @@
+{
+ "webport":":88",
+ "mongodb": {
+		"addr":"192.168.3.207:27080",
+		"db":"jyqyfw",
+		"pool":10
+	},
+	"redis":{
+		"addr":"jyqyfw=192.168.3.207:1380",
+		"pool":50
+	}
+}

+ 1 - 0
jyservice/src/github.com/89hmdys/toast

@@ -0,0 +1 @@
+Subproject commit 3a038d97263a2458545f6772c3ca218d6646954e

+ 1 - 0
jyservice/src/github.com/gorilla/mux

@@ -0,0 +1 @@
+Subproject commit 7f08801859139f86dfafd1c296e2cba9a80d292e

+ 1 - 0
jyservice/src/github.com/sirupsen/logrus

@@ -0,0 +1 @@
+Subproject commit 89742aefa4b206dcf400792f3bd35b542998eb3b

+ 1 - 0
jyservice/src/golang.org/x/crypto

@@ -0,0 +1 @@
+Subproject commit 6a293f2d4b14b8e6d3f0539e383f6d0d30fce3fd

+ 1 - 0
jyservice/src/golang.org/x/sys

@@ -0,0 +1 @@
+Subproject commit 4b45465282a4624cf39876842a017334f13b8aff

+ 14 - 0
jyservice/src/main.go

@@ -1,5 +1,19 @@
 package main
 
+import (
+	"net/http"
+	"usermanager"
+	"utils"
+
+	log "github.com/sirupsen/logrus"
+)
+
 func main() {
+	go Server()
+	log.Info("Start server...")
+	<-make(chan struct{}, 0)
+}
 
+func Server() {
+	http.ListenAndServe(utils.Sysconfig["webport"].(string), usermanager.Route)
 }

+ 15 - 0
jyservice/src/private.pem

@@ -0,0 +1,15 @@
+-----BEGIN private-----
+MIICXQIBAAKBgQC32pYyKWAWiI4CWZzxLgpad2pz1r6F9opDJaNQvFTQJiQivHlh
+sHQvyZ90ZDZbDxxAX/sqK4HMkDfBPBmol4UHRg5kAv9xkVEmyBtoLLljYRszxOje
+693EyKDAeME8KNVgLLaCsMuiyy2EaZMBGAvxSTmnd+t1pMjHHp8n7DGunwIDAQAB
+AoGBAJf9oftYDzKxs0yoDsGnwTFm1V9sYVdYKJc4L1pYR3lIfskkrOgguvyinyrW
+icUfqchiUL5c91JIy375E3E3yeV/xoS4y+6Cf0dAiq/iiGoBqBtzbSpF+UA0o/pP
+3yMu8WaueG2En8mpTN9kAcW9Cn279PtwMALfKmW1/NZdXJ2pAkEA8RL0gXGukWOZ
+auEMxp0OWvQm0R/lVz2XyfjSVQWfDT2vGMgDv6+2bUeT8DomJmx3oWQX2gq0uidb
+/Ir9rEvhWwJBAMM8r8GVva1gicTswBWi7tDHC8OGYY9a0MQ3IPCKDCC513Se0SJi
+rhSU1IL2PBBgnSS/atwJ+FwY6Cbynrs1Rw0CQQDBKJ3upcboyXQgtgfFkAvzhpMf
+lr3s4/YeJ5dn9mQVeOo2IfUW/tRdxS9dGUp+GQTVtNyDoXZjfavvsvJEvlvnAkAJ
+h6nQmj2S+/ZdnWzW4YgkusKRPbr/Y2BzY3mBJEvpQQkKUUJGGmkC6izhY6GU7xJc
+m9dcfEQaQsD6PbePzc71AkBEanolW+cy+XzlqxQPoR64h9oP+QaVS0mlD+u3YBWn
+M0OVEU2E6lZ2xR25WmM/VAplMzklBlfIhsfkvBDHFUDX
+-----END private-----

+ 6 - 0
jyservice/src/public.pem

@@ -0,0 +1,6 @@
+-----BEGIN public-----
+MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC32pYyKWAWiI4CWZzxLgpad2pz
+1r6F9opDJaNQvFTQJiQivHlhsHQvyZ90ZDZbDxxAX/sqK4HMkDfBPBmol4UHRg5k
+Av9xkVEmyBtoLLljYRszxOje693EyKDAeME8KNVgLLaCsMuiyy2EaZMBGAvxSTmn
+d+t1pMjHHp8n7DGunwIDAQAB
+-----END public-----

+ 64 - 0
jyservice/src/usermanager/access_token.go

@@ -0,0 +1,64 @@
+package usermanager
+
+import (
+	"fmt"
+	"net/http"
+	"qfw/util/redis"
+	"time"
+	. "utils"
+	//log "github.com/sirupsen/logrus"
+)
+
+const (
+	TOKEN_TIMEOUT     = 7200
+	TOKEN_LIMIT_TIMES = 201
+	//key : 每天token上限tokenlimit_*  token的key token_*  每天调用数据api次数上限getlimit_*
+)
+
+//jyqyfw/user表
+//用户的accesstoken维护,每个用户分配一个 应用id=appid,用户密钥=key
+func GetAccessToken(w http.ResponseWriter, r *http.Request) {
+	d := JSON{}
+	appid := r.FormValue("appid")
+	key := r.FormValue("key")
+	if appid != "" && key != "" {
+		res, b := Mgo.FindOneByField("user", &map[string]interface{}{
+			"appid": appid,
+			"key":   key,
+		}, `{"_id":1}`)
+		if b && res != nil && *res != nil {
+			limitKey := fmt.Sprintf("tokenlimit_%s", appid)
+			limit := redis.GetInt(REDISDB, limitKey)
+			if limit < TOKEN_LIMIT_TIMES {
+				t := time.Now()
+				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["code"] = CODE_SUCCESS
+						d["access_token"] = access_token
+						d["times"] = redis.Incr(REDISDB, limitKey)
+						tn := time.Date(t.Year(), t.Month(), t.Day()+1, 0, 0, 0, 0, time.Local).Unix()
+						expire := int(tn - t.Unix())
+						if expire > 0 {
+							redis.SetExpire(REDISDB, limitKey, expire)
+						}
+					}
+				}
+				if len(d) == 0 {
+					//服务出错
+					d["code"] = CODE_E2
+					d["msg"] = MSG_E2
+				}
+			} else {
+				//超过次数
+				d["code"] = CODE_E3
+				d["msg"] = MSG_E3
+			}
+		}
+	}
+	if len(d) == 0 {
+		d["code"] = CODE_E1
+		d["msg"] = MSG_E1
+	}
+	WriteJSON(w, d)
+}

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

@@ -0,0 +1,198 @@
+/**
+数据获取服务
+**/
+package usermanager
+
+import (
+	"net/http"
+	"qfw/util"
+	"qfw/util/redis"
+	"strings"
+	"time"
+	. "utils"
+
+	log "github.com/sirupsen/logrus"
+)
+
+//day:0
+//next:0
+const (
+	GETDATA_LIMIT_TIMES = 1001 //获取数据次数
+	QUERY_LIMIT         = 100
+)
+
+func GetData(w http.ResponseWriter, r *http.Request) {
+	d := JSON{}
+	access_token := r.FormValue("access_token")
+	log.Debug(access_token)
+	if access_token != "" {
+		at := RsaDecrypt(access_token)
+		b := false
+		if at != "" {
+			tn := time.Now().Unix()
+			arr := strings.Split(at, ",")
+			if len(arr) == 3 { //时间,appid,key
+				b = true
+				t := util.Int64All(arr[0])
+				des := tn - t
+				log.Debug("des", des)
+				if des >= 0 && des <= TOKEN_TIMEOUT {
+					appid := arr[1]
+					redis_token := redis.GetStr(REDISDB, "token_"+appid)
+					log.Debug("redis_token", redis_token, access_token)
+					if redis_token == access_token { //token验证通过,验证今日次数、总条数、服务时间
+						//"limittoday_" //值小于0时禁止
+						//"limitnum_" 值为小于零时实时判断
+						//"limittime_" 只判断一次,过期重新判断,用户续费时可以设置此值过期
+						limittime := redis.GetInt(REDISDB, "limittime_"+appid)
+						var THISNUM interface{}
+						if limittime < 1 {
+							res, bflag := Mgo.FindOneByField("user", &map[string]interface{}{
+								"appid": appid,
+							}, `{"plan":1}`)
+							if bflag && res != nil && *res != nil {
+								if m1 := util.ObjToMap((*res)["plan"]); m1 != nil {
+									THISNUM = (*m1)["current"]
+									starttime := util.Int64All((*m1)["starttime"])
+									endtime := util.Int64All((*m1)["endtime"])
+									if starttime <= tn && tn <= endtime { //在服务时间内
+										limittime = int(endtime - tn)
+										redis.Put(REDISDB, "limittime_"+appid, limittime, limittime) //存入值
+									}
+								}
+							}
+						}
+						if limittime > 0 { //在服务期内
+							//判断今日次数
+							limittoday := redis.Incr(REDISDB, "limittoday_"+appid)
+							if limittoday > GETDATA_LIMIT_TIMES { //当天调用超过次数
+
+							} else {
+								if limittoday == 1 { //设值过期时间
+									now := time.Now()
+									tomorrow := time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, time.Local)
+									err := redis.SetExpire(REDISDB, "limittoday_"+appid, int(tomorrow.Unix()-now.Unix()))
+									if err != nil {
+										log.Error("set expire err!", err.Error())
+									}
+								}
+								limitnum := redis.Get(REDISDB, "limitnum_"+appid) //值
+								if limitnum == nil {                              //值为空时从数据库中提取
+									if THISNUM == nil {
+										res1, bflag1 := Mgo.FindOneByField("user", &map[string]interface{}{
+											"appid": appid,
+										}, `{"plan":1}`)
+										if bflag1 && res1 != nil && *res1 != nil {
+											if m1 := util.ObjToMap((*res1)["plan"]); m1 != nil {
+												THISNUM = (*m1)["current"]
+											}
+										}
+									}
+									if THISNUM != nil {
+										num := util.IntAll(THISNUM)
+										if num > 0 {
+											bparam := true
+											redis.Put(REDISDB, "limitnum_"+appid, num, 0)
+											//通过,可以返回取数据 day:0,all:1,next:0  ,100条
+											query := map[string]interface{}{"appid": appid}
+											i_all := util.IntAll(r.FormValue("all"))
+											if i_all == 1 {
+
+											} else if i_all != 0 {
+												bparam = false
+											} else {
+												query["bget"] = 0
+											}
+											i_day := util.IntAll(r.FormValue("all"))
+											createtime := map[string]interface{}{}
+											switch i_day { //保留最近5天数据
+											case 0:
+
+											case -1:
+											case -2:
+											case -3:
+											case -4:
+											default:
+												bparam = false
+											}
+											if i_day > -5 && i_day < 1 {
+												min, max := GetDayMinMax(time.Now().AddDate(0, 0, i_day))
+												createtime["$gte"] = min
+												createtime["$lte"] = max
+												query["createtime"] = createtime
+											} else {
+												bparam = false
+											}
+											if bparam {
+												log.Debug("query:", query)
+												i_next := util.IntAll(r.FormValue("next"))
+												data, bdata := Mgo.Find("usermail", query, `{"_id":1}`, `{"_id":0,"title":1,"detail":1,"publishtime":1,"href":1}`, false, i_next, QUERY_LIMIT)
+												if bdata && data != nil && *data != nil && len(*data) > 0 {
+													if i_all != 1 {
+														//更新
+														a1 := (*data)[0]
+														idq := map[string]interface{}{
+															"$gte": a1["_id"],
+														}
+														q1 := map[string]interface{}{
+															"appid": appid,
+														}
+														if len(*data) > 0 {
+															a2 := (*data)[len(*data)-1]
+															idq["$lte"] = a2["_id"]
+														}
+														q1["_id"] = idq
+														bupdate := Mgo.Update("usermail", q1, map[string]interface{}{
+															"$set": map[string]interface{}{
+																"bget": 1,
+															},
+														}, false, false)
+														if !bupdate {
+															log.Error("update get data error:", appid)
+														}
+													}
+													d["data"] = *data
+													if len(*data) == QUERY_LIMIT {
+														d["next"] = i_next + QUERY_LIMIT
+													} else {
+														d["next"] = -1
+													}
+												} else { //没有数据
+
+												}
+											}
+										}
+									}
+								}
+							}
+						}
+					} else {
+						d["code"] = CODE_TOKEN_EXPIRE
+						d["msg"] = MSG_TOKEN_EXPIRE
+					}
+				} else { //超时
+					d["code"] = CODE_TOKEN_EXPIRE
+					d["msg"] = MSG_TOKEN_EXPIRE
+				}
+			}
+		}
+		if !b {
+			d["code"] = CODE_E0
+			d["msg"] = MSG_E0
+		}
+	} else {
+		d["code"] = CODE_E1
+		d["msg"] = MSG_E1
+	}
+	WriteJSON(w, &d)
+}
+
+//sess := Mgo.GetMgoConn()
+//defer Mgo.DestoryMongoConn(sess)
+//it := sess.DB(Mgo.DbName).C("usermail").Find(&query).Sort("-publishtime").Select(map[string]interface{}{
+//	"_id": 0, "title": 1, "detail": 1, "publishtime": 1, "href": 1,
+//}).Skip(i_next).Limit(100).Iter()
+//n := 0
+//for tmp := make(map[string]interface{}); it.Next(&tmp); n++ {
+
+//}

+ 77 - 0
jyservice/src/usermanager/user.go

@@ -0,0 +1,77 @@
+/**
+初始化用户服务
+1.创建用户
+2.购买服务
+**/
+package usermanager
+
+import (
+	"fmt"
+	"net/http"
+	"qfw/util"
+	"time"
+	. "utils"
+
+	log "github.com/sirupsen/logrus"
+)
+
+//生成appid和key
+//用户名称 appid 注册时间 key
+//套餐类型(A1,A2,A3,B1,B2,B3) 服务开始时间 服务结束时间
+var (
+	EncodeUtil = &util.SimpleEncrypt{"qyfw2017jy"}
+)
+
+//创建新用户
+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)
+	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)
+	ret := JSON{"msg": "err"}
+	if len(id) > 10 {
+		ret["msg"] = "ok"
+	}
+	WriteJSON(w, &ret)
+}
+
+//购买服务
+func NewService(w http.ResponseWriter, r *http.Request) {
+	appid := r.FormValue("appid")
+	plan := r.FormValue("plan")
+	ret := JSON{"msg": "err!"}
+	if appid != "" && plan != "" && Mgo.Count("user", `{"appid":"`+appid+`"}`) == 1 {
+		res, bp := Mgo.FindOne("serviceplan", &map[string]interface{}{
+			"_id": plan,
+		})
+		if bp && res != nil && *res != nil {
+			limit := (*res)["limit"]
+			t := time.Now()
+			end := t.AddDate(1, 0, 1)
+			end1 := time.Date(end.Year(), end.Month(), end.Day(), 0, 0, 0, 0, time.Local)
+			//log.Debug(t.Unix(), "-", end.Unix(), util.FormatDate(&t, util.Date_Full_Layout), util.FormatDate(&end1, util.Date_Full_Layout))
+			id := Mgo.Save("buyrecord", &map[string]interface{}{"appid": appid, "plan": plan, "createtime": t.Unix(), "starttime": t.Unix(), "endtime": end1.Unix()})
+			if id != "" {
+				//后结考虑延期时间
+				if Mgo.Update("user", `{"appid":"`+appid+`"}`, &map[string]interface{}{
+					"$set": map[string]interface{}{
+						"plan": map[string]interface{}{
+							"name":      plan,
+							"starttime": t.Unix(),
+							"endtime":   end1.Unix(),
+							"recordid":  id,
+							"current":   limit,
+						},
+					},
+				}, false, false) {
+					ret["msg"] = "ok"
+				}
+			}
+		}
+	}
+	WriteJSON(w, &ret)
+}

+ 19 - 0
jyservice/src/usermanager/usermanager.go

@@ -0,0 +1,19 @@
+package usermanager
+
+import (
+	"net/http"
+
+	"github.com/gorilla/mux"
+)
+
+var (
+	Route = mux.NewRouter()
+)
+
+func init() {
+	Route.HandleFunc("/api1/user/access_token", GetAccessToken).Methods("POST")
+	Route.HandleFunc("/api1/user/newuser", NewUser).Methods("POST")
+	Route.HandleFunc("/api1/user/newservice", NewService).Methods("POST")
+	Route.HandleFunc("/api1/data/getdata", GetData).Methods("POST")
+	http.Handle("/", Route)
+}

+ 18 - 0
jyservice/src/utils/httputil.go

@@ -0,0 +1,18 @@
+package utils
+
+import (
+	"encoding/json"
+	"net/http"
+
+	log "github.com/sirupsen/logrus"
+)
+
+func WriteJSON(w http.ResponseWriter, data interface{}) {
+	resByte, err := json.Marshal(data)
+	if err != nil {
+		log.Error("writejson err", err.Error())
+		return
+	}
+	w.Header().Set("Content-Type", "application/json")
+	w.Write(resByte)
+}

+ 20 - 0
jyservice/src/utils/mongodb.go

@@ -0,0 +1,20 @@
+package utils
+
+import (
+	"qfw/util"
+	"qfw/util/mongodb"
+)
+
+var (
+	Mgo *mongodb.MongodbSim
+)
+
+func initmongo() {
+	mconf := Sysconfig["mongodb"].(map[string]interface{})
+	Mgo = &mongodb.MongodbSim{
+		MongodbAddr: mconf["addr"].(string),
+		DbName:      mconf["db"].(string),
+		Size:        util.IntAllDef(mconf["pool"], 5),
+	}
+	Mgo.InitPool()
+}

+ 129 - 0
jyservice/src/utils/ras.go

@@ -0,0 +1,129 @@
+package utils
+
+import (
+	"crypto/rand"
+	"crypto/rsa"
+	"crypto/x509"
+	"encoding/base64"
+	"encoding/pem"
+	"os"
+
+	log "github.com/sirupsen/logrus"
+)
+
+var (
+	Private = []byte(`-----BEGIN private-----
+MIICXQIBAAKBgQC32pYyKWAWiI4CWZzxLgpad2pz1r6F9opDJaNQvFTQJiQivHlh
+sHQvyZ90ZDZbDxxAX/sqK4HMkDfBPBmol4UHRg5kAv9xkVEmyBtoLLljYRszxOje
+693EyKDAeME8KNVgLLaCsMuiyy2EaZMBGAvxSTmnd+t1pMjHHp8n7DGunwIDAQAB
+AoGBAJf9oftYDzKxs0yoDsGnwTFm1V9sYVdYKJc4L1pYR3lIfskkrOgguvyinyrW
+icUfqchiUL5c91JIy375E3E3yeV/xoS4y+6Cf0dAiq/iiGoBqBtzbSpF+UA0o/pP
+3yMu8WaueG2En8mpTN9kAcW9Cn279PtwMALfKmW1/NZdXJ2pAkEA8RL0gXGukWOZ
+auEMxp0OWvQm0R/lVz2XyfjSVQWfDT2vGMgDv6+2bUeT8DomJmx3oWQX2gq0uidb
+/Ir9rEvhWwJBAMM8r8GVva1gicTswBWi7tDHC8OGYY9a0MQ3IPCKDCC513Se0SJi
+rhSU1IL2PBBgnSS/atwJ+FwY6Cbynrs1Rw0CQQDBKJ3upcboyXQgtgfFkAvzhpMf
+lr3s4/YeJ5dn9mQVeOo2IfUW/tRdxS9dGUp+GQTVtNyDoXZjfavvsvJEvlvnAkAJ
+h6nQmj2S+/ZdnWzW4YgkusKRPbr/Y2BzY3mBJEvpQQkKUUJGGmkC6izhY6GU7xJc
+m9dcfEQaQsD6PbePzc71AkBEanolW+cy+XzlqxQPoR64h9oP+QaVS0mlD+u3YBWn
+M0OVEU2E6lZ2xR25WmM/VAplMzklBlfIhsfkvBDHFUDX
+-----END private-----`)
+	Public = []byte(`-----BEGIN public-----
+MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC32pYyKWAWiI4CWZzxLgpad2pz
+1r6F9opDJaNQvFTQJiQivHlhsHQvyZ90ZDZbDxxAX/sqK4HMkDfBPBmol4UHRg5k
+Av9xkVEmyBtoLLljYRszxOje693EyKDAeME8KNVgLLaCsMuiyy2EaZMBGAvxSTmn
+d+t1pMjHHp8n7DGunwIDAQAB
+-----END public-----`)
+)
+
+func initrsa() {
+	//GenRsaKey(1024)
+	//	str := RsaEncrypt("你好")
+	//	log.Debug(str)
+	//	log.Debug(RsaDecrypt(str))
+}
+
+func RsaEncrypt(orig string) (encodestr string) {
+	origData := []byte(orig)
+	block, _ := pem.Decode(Public)
+	if block == nil {
+		log.Error("public key error")
+		return
+	}
+	pubInterface, err := x509.ParsePKIXPublicKey(block.Bytes)
+	if err != nil {
+		return
+	}
+	pub := pubInterface.(*rsa.PublicKey)
+	res, err := rsa.EncryptPKCS1v15(rand.Reader, pub, origData)
+	if err == nil {
+		encodestr = base64.StdEncoding.EncodeToString(res)
+	} else {
+		log.Error("rsa en err", err.Error())
+	}
+	return
+}
+
+// 解密
+func RsaDecrypt(text string) (orig string) {
+	ciphertext, err := base64.StdEncoding.DecodeString(text)
+	if err != nil {
+		log.Error("ras De error", err.Error())
+		return
+	}
+	block, _ := pem.Decode(Private)
+	if block == nil {
+		log.Error("private key error!")
+		return
+	}
+	priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
+	if err != nil {
+		return
+	}
+	res, err := rsa.DecryptPKCS1v15(rand.Reader, priv, ciphertext)
+	if err == nil {
+		orig = string(res)
+	} else {
+		log.Error("ras De error", err.Error())
+	}
+	return
+}
+
+func GenRsaKey(bits int) error {
+	// 生成私钥文件
+	privateKey, err := rsa.GenerateKey(rand.Reader, bits)
+	if err != nil {
+		return err
+	}
+	derStream := x509.MarshalPKCS1PrivateKey(privateKey)
+	block := &pem.Block{
+		Type:  "private",
+		Bytes: derStream,
+	}
+	file, err := os.Create("private.pem")
+	if err != nil {
+		return err
+	}
+	err = pem.Encode(file, block)
+	if err != nil {
+		return err
+	}
+	// 生成公钥文件
+	publicKey := &privateKey.PublicKey
+	derPkix, err := x509.MarshalPKIXPublicKey(publicKey)
+	if err != nil {
+		return err
+	}
+	block = &pem.Block{
+		Type:  "public",
+		Bytes: derPkix,
+	}
+	file, err = os.Create("public.pem")
+	if err != nil {
+		return err
+	}
+	err = pem.Encode(file, block)
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 56 - 0
jyservice/src/utils/utils.go

@@ -0,0 +1,56 @@
+package utils
+
+import (
+	"os"
+	"qfw/util"
+	"qfw/util/redis"
+	"time"
+
+	log "github.com/sirupsen/logrus"
+)
+
+type JSON map[string]interface{}
+
+const (
+	REDISDB           = "jyqyfw"
+	CODE_TOKEN_EXPIRE = 1001 //token过期
+	MSG_TOKEN_EXPIRE  = "token已过期"
+	CODE_E0           = 10011
+	MSG_E0            = "token错误"
+	CODE_E1           = 1002
+	MSG_E1            = "参数错误"
+	CODE_E2           = 1003
+	MSG_E2            = "服务出错"
+	CODE_E3           = 1004
+	MSG_E3            = "调用次数过超限制"
+	//------
+	CODE_SUCCESS = 1
+	MSG_SUCCESS  = "请求成功"
+)
+
+var (
+	Sysconfig map[string]interface{}
+)
+
+func init() {
+	//初始化日志
+	t := &log.TextFormatter{}
+	t.TimestampFormat = "01-02 15:04:05.000"
+	t.ForceColors = true
+	t.DisableTimestamp = false
+	t.FullTimestamp = true
+	log.SetFormatter(t)
+	log.SetOutput(os.Stdout)
+	log.SetLevel(log.DebugLevel)
+	util.ReadConfig(&Sysconfig)
+	initmongo()
+	redisconf := Sysconfig["redis"].(map[string]interface{})
+	redis.InitRedisBySize(util.ObjToString(redisconf["addr"]), util.IntAllDef(redisconf["pool"], 10), 20, 240)
+	log.Debug("Util init over...")
+	initrsa()
+}
+
+func GetDayMinMax(t time.Time) (int64, int64) {
+	min := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local).Unix()
+	return min, min + 86400
+}