unknown 7 éve
szülő
commit
875d1cbfe5

BIN
pkg/windows_amd64/apiservice/config.a


BIN
pkg/windows_amd64/apiservice/oamanager.a


BIN
pkg/windows_amd64/apiservice/tools.a


+ 23 - 3
src/apiservice/oamanager/createuser.go

@@ -5,15 +5,16 @@ import (
 	"log"
 	"qfw/util"
 	"regexp"
-	"strconv"
 	"time"
 
 	"github.com/go-xweb/xweb"
+	"gopkg.in/mgo.v2/bson"
 )
 
 type Createuser struct {
 	*xweb.Action
 	createUser xweb.Mapper `xweb:"/createUser"`
+	updateUser xweb.Mapper `xweb:"/updateUser"`
 }
 
 func init() {
@@ -44,8 +45,16 @@ func (c *Createuser) CreateUser() error {
 	} else {
 		appid = GetAppid(t.Unix())
 		secret = util.GetComplexRandom(8, 3, 5)
-		ordernum := strconv.Itoa(count + 1)
-		id := mongodb.Save("user", &map[string]interface{}{"username": username, "userip": userip, "createtime": t.Unix(), "appid": appid, "secret": secret, "status": "1", "ordernum": ordernum})
+		ordernum := count + 1
+		data := make(map[string]interface{})
+		data["username"] = username
+		data["userip"] = userip
+		data["createtime"] = t.Unix()
+		data["appid"] = appid
+		data["secret"] = secret
+		data["status"] = 1
+		data["ordernum"] = ordernum
+		id := mongodb.Save("user", data)
 		if len(id) > 0 {
 			log.Println("保存用户成功!")
 		}
@@ -54,6 +63,17 @@ func (c *Createuser) CreateUser() error {
 	return nil
 }
 
+//修改用户信息
+func (c *Createuser) UpdateUser() error {
+	defer util.Catch()
+	username := c.GetString("username")
+	if username != "" {
+		set := bson.M{"$set": bson.M{"status": 0}}
+		mongodb.Update("user", bson.M{"username": username}, set, false, false)
+	}
+	c.ServeJson(map[string]interface{}{"msg": "修改成功!"})
+	return nil
+}
 func GetAppid(tn int64) (appid string) {
 	for {
 		randomstr := util.GetLetterRandom(5)

+ 43 - 29
src/apiservice/oamanager/oamanager.go

@@ -1,6 +1,7 @@
 package oamanager
 
 import (
+	. "apiservice/config"
 	"apiservice/tools"
 	"bytes"
 	"compress/gzip"
@@ -39,8 +40,8 @@ func init() {
 }
 
 const (
-	LIMIT_TIME       = 300  //签名超时时间
-	LIMIT_COUNT      = 3000 //每天接口限制
+	LIMIT_TIME       = 30000 //签名超时时间
+	LIMIT_COUNT      = 3000  //每天接口限制
 	REDISDB          = "jyOpenAPI"
 	CODE_E1          = 40000
 	MSG_E1           = "签名错误"
@@ -54,10 +55,9 @@ const (
 	MSG_E5           = "内部错误"
 	CODE_E6          = 40005
 	MSG_E6           = "IP未授权"
-	MSG_SUCCESS      = "请求成功"
 	INDEX            = "bidding"
 	TYPE             = "bidding"
-	LIMIT_LIST_COUNT = 100
+	LIMIT_LIST_COUNT = 10
 )
 
 var APPID, SECRET string
@@ -69,11 +69,12 @@ func (o *Oamanager) Index() error {
 
 //
 func OpenAction(w http.ResponseWriter, r *http.Request) {
+	defer util.Catch()
+	oaday := strconv.Itoa(time.Now().Day())
 	rData := make(map[string]interface{})
 	var rCode = 0
 	var rMsg = ""
-	defer util.Catch()
-	if r.Method == "POST" {
+	if r.Method == "POST" { //POST请求
 		var (
 			action       = r.FormValue("action")
 			keyword      = r.FormValue("keyword")
@@ -83,31 +84,35 @@ func OpenAction(w http.ResponseWriter, r *http.Request) {
 			ttamp        = time.Now().Unix()
 			timestamp, _ = strconv.Atoi(r.FormValue("timestamp"))
 		)
-		if appid == "" || action == "" || keyword == "" || timestamp == 0 || signature == "" { //
-			rCode = CODE_E1 //签名错误
-			rMsg = "签名错误"
+		if appid == "" || action == "" || keyword == "" || timestamp == 0 || signature == "" { //参数验证
+			rCode = CODE_E2 //签名错误
+			rMsg = MSG_E2
 		} else {
 			ttmp1 := strconv.Itoa(timestamp)
 			ttmp2, _ := strconv.ParseInt(ttmp1, 10, 64)
-			if (ttamp - ttmp2) > LIMIT_TIME {
+			if (ttamp - ttmp2) > LIMIT_TIME { //签名时间验证
 				rCode = CODE_E3 //签名过期
-				rMsg = "签名过期"
+				rMsg = MSG_E3
 			} else {
-				apicount := redis.GetInt(REDISDB, "jyopenapi-"+appid)
+				apicount := redis.GetInt(REDISDB, "jyoacount-"+appid+oaday)
 				log.Println("每天调用次数:", apicount)
-				if apicount >= LIMIT_COUNT {
+				if apicount >= LIMIT_COUNT { //调用接口上限判断
 					rCode = CODE_E4 //调用接口超过限制
-					rMsg = "调用接口超过限制"
+					rMsg = MSG_E4
 				} else {
 					if pagenum == 0 {
 						pagenum = 1
 					}
-					res, _ := mongodb.FindOneByField("user", &map[string]interface{}{
+					res, ok := mongodb.FindOneByField("user", &map[string]interface{}{
 						"appid": appid,
 					}, nil)
-					if len(*res) > 0 {
-						comip := GetAPIIP(r)
-						if (*res)["userip"] == comip {
+					if !ok {
+						rCode = CODE_E5 //内部错误
+						rMsg = MSG_E5
+					}
+					if len(*res) > 0 && (*res)["status"] == 1 { //查看用户是否存在
+						userip := GetAPIIP(r)
+						if (*res)["userip"] == userip { //验证用户ip
 							APPID = appid
 							SECRET = util.ObjToString((*res)["secret"])
 							sign := GET(action, [][]string{
@@ -116,28 +121,34 @@ func OpenAction(w http.ResponseWriter, r *http.Request) {
 								[]string{"timestamp", strconv.Itoa(timestamp)},
 								[]string{"pagenum", strconv.Itoa(pagenum)},
 							})
-							ordernum := util.ObjToString((*res)["ordernum"])
-							if sign == signature {
+							log.Println(signature, "签名串:", sign)
+							ordernum := (*res)["ordernum"].(int)
+							if sign == signature { //签名串验证
 								if action == "getdata" {
-									rData["data"], rData["count"] = GetData(pagenum, keyword, ordernum)
-									redis.Put(REDISDB, "jyopenapi-"+appid, apicount+1, 0)
+									rData["data"] = GetData(pagenum, keyword, ordernum)
+									redis.Put(REDISDB, "jyoacount-"+appid+oaday, apicount+1, 24*60*60)
+								} else {
+									rCode = CODE_E1 //签名错误
+									rMsg = MSG_E1
 								}
 							} else {
 								rCode = CODE_E1 //签名错误
-								rMsg = "签名错误"
+								rMsg = MSG_E1
 							}
 						} else {
+							rCode = CODE_E6 //IP未授权
+							rMsg = MSG_E6
 						}
 					} else {
 						rCode = CODE_E1 //签名错误
-						rMsg = "签名错误"
+						rMsg = MSG_E1
 					}
 				}
 			}
 		}
 	} else {
 		rCode = CODE_E1 //签名错误
-		rMsg = "签名错误"
+		rMsg = MSG_E1
 	}
 	if rCode == 0 {
 		w.Header().Set("Accept-Charset", "utf-8")
@@ -155,18 +166,21 @@ func OpenAction(w http.ResponseWriter, r *http.Request) {
 }
 
 //
-func GetData(pagenum int, keyword string, ordernum string) (list []map[string]interface{}, count int) {
+func GetData(pagenum int, keyword string, ordernum int) (list []map[string]interface{}) {
+	//	query1 := `{"query": {"bool": {"must":[`
+	//	query1 += `{"term":{"winner":"` + keyword + `"}}`
+	//	query1 += `],"should": [],"minimum_should_match": 0}}}`
+	//	count = elastic.Count(INDEX, TYPE, query1)
 	start := (pagenum - 1) * LIMIT_LIST_COUNT
 	query := `{"TERM_winner":"` + keyword + `"}`
-	res, ct := elastic.GetOAPage(INDEX, TYPE, query, `{"publishtime":-1}`, `"_id","title","publishtime"`, start, LIMIT_LIST_COUNT)
+	res, _ := elastic.GetOAPage(INDEX, TYPE, query, `{"publishtime":-1}`, `"_id","title","publishtime"`, start, LIMIT_LIST_COUNT)
 	if len(*res) > 0 {
 		for _, v := range *res {
-			v["href"] = "/article/" + util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]), ordernum) + ".html"
+			v["href"] = Sysconfig["jyaddress"].(string) + "/article/" + util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]), strconv.Itoa(ordernum)) + ".html"
 			delete(v, "_id")
 		}
 	}
 	list = *res
-	count = ct
 	return
 }
 

+ 2 - 1
src/config.json

@@ -5,5 +5,6 @@
     "elasticsearch": "http://192.168.3.18:9800",
     "elasticPoolSize": 30,
     "redisaddrs": "jyOpenAPI=192.168.3.18:3380",
-    "webport": "8081"
+    "webport": "8081",
+	"jyaddress":"https://www.jianyu360.com/"
 }

BIN
src/src.exe


+ 1 - 1
src/web/templates/app/app.html

@@ -39,7 +39,7 @@
 				
 			</section>
 			<footer>
-				<a href="#">剑鱼招标订阅</a>提供数据支持
+				<a href="https://www.jianyu360.com/">剑鱼招标订阅</a>提供数据支持
 			</footer>
 		</div>
 		

+ 4 - 4
src/web/templates/pc/article.html

@@ -21,11 +21,11 @@ $(function(){
 		type: "POST",
 		url: "/open",
 		data:{	appid:"jyoaACJUW1BJXwECCA1fDwUj",
-				pagenum:1,
-				keyword:"广安建新建设工程有限责任公司",
-				timestamp:1519797630,
+				pagenum:2,
+				keyword:"万达信息股份有限公司",
+				timestamp:1519869324,
 				action:"getdata",
-				signature:"okaWRbhotH6xY9jhvZnLyLoz5XQ=",
+				signature:"s1Cds28hxfDsXHOU4ktGdvgXNr0=",
 			},
 		dataType: "json",
 		success: function(r){