wangshan 7 жил өмнө
parent
commit
c9570dfb86

+ 8 - 0
.gitignore

@@ -0,0 +1,8 @@
+pkg
+bin
+*/pkg
+*.exe
+*.log
+*/src/src
+*.data
+*/bin

+ 4 - 1
src/apiservice/oamanager/createuser.go

@@ -5,6 +5,7 @@ import (
 	"log"
 	"qfw/util"
 	"regexp"
+	"strconv"
 	"time"
 
 	"github.com/go-xweb/xweb"
@@ -30,6 +31,7 @@ func (c *Createuser) CreateUser() error {
 	t := time.Now()
 	status := "1"
 	var appid, secret string
+	count := mongodb.Count("user", nil)
 	res, _ := mongodb.FindOneByField("user", &map[string]interface{}{
 		"username": username,
 		"userip":   userip,
@@ -42,7 +44,8 @@ func (c *Createuser) CreateUser() error {
 	} else {
 		appid = GetAppid(t.Unix())
 		secret = util.GetComplexRandom(8, 3, 5)
-		id := mongodb.Save("user", &map[string]interface{}{"username": username, "userip": userip, "createtime": t.Unix(), "appid": appid, "secret": secret, "status": "1"})
+		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})
 		if len(id) > 0 {
 			log.Println("保存用户成功!")
 		}

+ 42 - 22
src/apiservice/oamanager/oamanager.go

@@ -8,6 +8,7 @@ import (
 	"crypto/sha1"
 	"encoding/base64"
 	"encoding/json"
+	"fmt"
 	"hash"
 	"io"
 	"log"
@@ -15,6 +16,7 @@ import (
 	"net/http"
 	"net/url"
 	"qfw/util"
+	"qfw/util/elastic"
 	"qfw/util/redis"
 	"sort"
 	"strconv"
@@ -37,22 +39,25 @@ func init() {
 }
 
 const (
-	LIMIT_TIME  = 3000 //链接超时时间
-	LIMIT_COUNT = 3000 //每天接口限制
-	REDISDB     = "jyOpenAPI"
-	CODE_E1     = 40000
-	MSG_E1      = "签名错误"
-	CODE_E2     = 40001
-	MSG_E2      = "参数错误"
-	CODE_E3     = 40002
-	MSG_E3      = "签名过期"
-	CODE_E4     = 40003
-	MSG_E4      = "调用接口超过限制"
-	CODE_E5     = 40004
-	MSG_E5      = "内部错误"
-	CODE_E6     = 40005
-	MSG_E6      = "IP未授权"
-	MSG_SUCCESS = "请求成功"
+	LIMIT_TIME       = 30000 //签名超时时间
+	LIMIT_COUNT      = 3000  //每天接口限制
+	REDISDB          = "jyOpenAPI"
+	CODE_E1          = 40000
+	MSG_E1           = "签名错误"
+	CODE_E2          = 40001
+	MSG_E2           = "参数错误"
+	CODE_E3          = 40002
+	MSG_E3           = "签名过期"
+	CODE_E4          = 40003
+	MSG_E4           = "调用接口超过限制"
+	CODE_E5          = 40004
+	MSG_E5           = "内部错误"
+	CODE_E6          = 40005
+	MSG_E6           = "IP未授权"
+	MSG_SUCCESS      = "请求成功"
+	INDEX            = "bidding"
+	TYPE             = "bidding"
+	LIMIT_LIST_COUNT = 100
 )
 
 var APPID, SECRET string
@@ -89,6 +94,7 @@ func OpenAction(w http.ResponseWriter, r *http.Request) {
 			rMsg = "签名过期"
 		} else {
 			apicount := redis.GetInt(REDISDB, "jyopenapi-"+appid)
+			log.Println("每天调用次数:", apicount, rMsg)
 			if apicount > LIMIT_COUNT {
 				rCode = CODE_E4 //调用接口超过限制
 				rMsg = "调用接口超过限制"
@@ -111,10 +117,11 @@ func OpenAction(w http.ResponseWriter, r *http.Request) {
 							[]string{"timestamp", strconv.Itoa(timestamp)},
 							[]string{"pagenum", strconv.Itoa(pagenum)},
 						})
-						log.Println(signature, "-1212--:", sign)
+						ordernum := util.ObjToString((*res)["ordernum"])
 						if sign == signature {
 							if action == "getdata" {
-								rData["data"] = GetData(pagenum, keyword)
+								rData["data"], rData["count"] = GetData(pagenum, keyword, ordernum)
+								redis.Put(REDISDB, "jyopenapi-"+appid, apicount+1, 0)
 							}
 						} else {
 							rCode = CODE_E1 //签名错误
@@ -129,7 +136,6 @@ func OpenAction(w http.ResponseWriter, r *http.Request) {
 			}
 		}
 	}
-	log.Println(rData, "---", rCode, "-", rMsg)
 	if rCode == 0 {
 		w.Header().Set("Accept-Charset", "utf-8")
 		w.Header().Set("Content-Type", "application/json")
@@ -141,13 +147,27 @@ func OpenAction(w http.ResponseWriter, r *http.Request) {
 			log.Println("writejson err", err.Error())
 		}
 	} else {
-		w.Write([]byte("{\"code\":" + strconv.Itoa(rCode) + "}"))
+		w.Write([]byte(fmt.Sprintf("{\"code\":%d,\"msg\":\"%s\"}", rCode, rMsg)))
 	}
 }
 
 //
-func GetData(pagenum int, keyword string) {
-
+func GetData(pagenum int, keyword string, ordernum string) (list []map[string]interface{}, count int64) {
+	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 := elastic.GetPage(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"
+			delete(v, "_id")
+		}
+	}
+	list = *res
+	return
 }
 
 //获取请求ip

BIN
src/src.exe


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

@@ -23,10 +23,10 @@ $(function(){
 		url: "/open",
 		data:{	appid:"jyoaACJUW1BJXwECCA1fDwUj",
 				pagenum:1,
-				keyword:"拓普网络",
-				timestamp:1519719472,
+				keyword:"广安建新建设工程有限责任公司",
+				timestamp:1519778778,
 				action:"getdata",
-				signature:"kSqioYVr4YKLgqeRx/czLCzUUoI=",
+				signature:"7njN6QvJN53z9YsLmqgjzfv533A=",
 			},
 		dataType: "json",
 		success: function(r){