|
@@ -8,6 +8,7 @@ import (
|
|
"crypto/sha1"
|
|
"crypto/sha1"
|
|
"encoding/base64"
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
|
+ "fmt"
|
|
"hash"
|
|
"hash"
|
|
"io"
|
|
"io"
|
|
"log"
|
|
"log"
|
|
@@ -15,6 +16,7 @@ import (
|
|
"net/http"
|
|
"net/http"
|
|
"net/url"
|
|
"net/url"
|
|
"qfw/util"
|
|
"qfw/util"
|
|
|
|
+ "qfw/util/elastic"
|
|
"qfw/util/redis"
|
|
"qfw/util/redis"
|
|
"sort"
|
|
"sort"
|
|
"strconv"
|
|
"strconv"
|
|
@@ -37,22 +39,25 @@ func init() {
|
|
}
|
|
}
|
|
|
|
|
|
const (
|
|
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
|
|
var APPID, SECRET string
|
|
@@ -89,6 +94,7 @@ func OpenAction(w http.ResponseWriter, r *http.Request) {
|
|
rMsg = "签名过期"
|
|
rMsg = "签名过期"
|
|
} else {
|
|
} else {
|
|
apicount := redis.GetInt(REDISDB, "jyopenapi-"+appid)
|
|
apicount := redis.GetInt(REDISDB, "jyopenapi-"+appid)
|
|
|
|
+ log.Println("每天调用次数:", apicount, rMsg)
|
|
if apicount > LIMIT_COUNT {
|
|
if apicount > LIMIT_COUNT {
|
|
rCode = CODE_E4 //调用接口超过限制
|
|
rCode = CODE_E4 //调用接口超过限制
|
|
rMsg = "调用接口超过限制"
|
|
rMsg = "调用接口超过限制"
|
|
@@ -111,10 +117,11 @@ func OpenAction(w http.ResponseWriter, r *http.Request) {
|
|
[]string{"timestamp", strconv.Itoa(timestamp)},
|
|
[]string{"timestamp", strconv.Itoa(timestamp)},
|
|
[]string{"pagenum", strconv.Itoa(pagenum)},
|
|
[]string{"pagenum", strconv.Itoa(pagenum)},
|
|
})
|
|
})
|
|
- log.Println(signature, "-1212--:", sign)
|
|
|
|
|
|
+ ordernum := util.ObjToString((*res)["ordernum"])
|
|
if sign == signature {
|
|
if sign == signature {
|
|
if action == "getdata" {
|
|
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 {
|
|
} else {
|
|
rCode = CODE_E1 //签名错误
|
|
rCode = CODE_E1 //签名错误
|
|
@@ -129,7 +136,6 @@ func OpenAction(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- log.Println(rData, "---", rCode, "-", rMsg)
|
|
|
|
if rCode == 0 {
|
|
if rCode == 0 {
|
|
w.Header().Set("Accept-Charset", "utf-8")
|
|
w.Header().Set("Accept-Charset", "utf-8")
|
|
w.Header().Set("Content-Type", "application/json")
|
|
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())
|
|
log.Println("writejson err", err.Error())
|
|
}
|
|
}
|
|
} else {
|
|
} 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
|
|
//获取请求ip
|