|
@@ -57,7 +57,7 @@ const (
|
|
|
MSG_E6 = "IP未授权"
|
|
|
INDEX = "bidding"
|
|
|
TYPE = "bidding"
|
|
|
- LIMIT_LIST_COUNT = 10
|
|
|
+ LIMIT_LIST_COUNT = 100
|
|
|
)
|
|
|
|
|
|
var APPID, SECRET string
|
|
@@ -74,16 +74,18 @@ func OpenAction(w http.ResponseWriter, r *http.Request) {
|
|
|
rData := make(map[string]interface{})
|
|
|
var rCode = 0
|
|
|
var rMsg = ""
|
|
|
+ var username string
|
|
|
+ var apicount int
|
|
|
+ var (
|
|
|
+ action = r.FormValue("action")
|
|
|
+ keyword = r.FormValue("keyword")
|
|
|
+ appid = r.FormValue("appid")
|
|
|
+ pagenum, _ = strconv.Atoi(r.FormValue("pagenum"))
|
|
|
+ signature = r.FormValue("signature")
|
|
|
+ ttamp = time.Now().Unix()
|
|
|
+ timestamp, _ = strconv.Atoi(r.FormValue("timestamp"))
|
|
|
+ )
|
|
|
if r.Method == "POST" { //POST请求
|
|
|
- var (
|
|
|
- action = r.FormValue("action")
|
|
|
- keyword = r.FormValue("keyword")
|
|
|
- appid = r.FormValue("appid")
|
|
|
- pagenum, _ = strconv.Atoi(r.FormValue("pagenum"))
|
|
|
- signature = r.FormValue("signature")
|
|
|
- ttamp = time.Now().Unix()
|
|
|
- timestamp, _ = strconv.Atoi(r.FormValue("timestamp"))
|
|
|
- )
|
|
|
if appid == "" || action == "" || keyword == "" || timestamp == 0 || signature == "" { //参数验证
|
|
|
rCode = CODE_E2 //签名错误
|
|
|
rMsg = MSG_E2
|
|
@@ -94,15 +96,12 @@ func OpenAction(w http.ResponseWriter, r *http.Request) {
|
|
|
rCode = CODE_E3 //签名过期
|
|
|
rMsg = MSG_E3
|
|
|
} else {
|
|
|
- apicount := redis.GetInt(REDISDB, "jyoacount-"+appid+oaday)
|
|
|
+ apicount = redis.GetInt(REDISDB, "jyoacount-"+appid+oaday)
|
|
|
log.Println("每天调用次数:", apicount)
|
|
|
if apicount >= LIMIT_COUNT { //调用接口上限判断
|
|
|
rCode = CODE_E4 //调用接口超过限制
|
|
|
rMsg = MSG_E4
|
|
|
} else {
|
|
|
- if pagenum == 0 {
|
|
|
- pagenum = 1
|
|
|
- }
|
|
|
res, ok := mongodb.FindOneByField("user", &map[string]interface{}{
|
|
|
"appid": appid,
|
|
|
}, nil)
|
|
@@ -113,19 +112,30 @@ func OpenAction(w http.ResponseWriter, r *http.Request) {
|
|
|
if len(*res) > 0 && (*res)["status"] == 1 { //查看用户是否存在
|
|
|
userip := GetAPIIP(r)
|
|
|
log.Println(userip, "-ip--", (*res)["userip"])
|
|
|
+ var sign string
|
|
|
if (*res)["userip"] == userip { //验证用户ip
|
|
|
APPID = appid
|
|
|
SECRET = util.ObjToString((*res)["secret"])
|
|
|
- sign := GET(action, [][]string{
|
|
|
- []string{"keyword", keyword},
|
|
|
- []string{"appid", appid},
|
|
|
- []string{"timestamp", strconv.Itoa(timestamp)},
|
|
|
- //[]string{"pagenum", strconv.Itoa(pagenum)},
|
|
|
- })
|
|
|
- log.Println(action, "--", keyword, "---", appid, "--", timestamp, "--", pagenum)
|
|
|
+ if r.FormValue("pagenum") == "" {
|
|
|
+ pagenum = 1
|
|
|
+ sign = GET(action, [][]string{
|
|
|
+ []string{"keyword", keyword},
|
|
|
+ []string{"appid", appid},
|
|
|
+ []string{"timestamp", strconv.Itoa(timestamp)},
|
|
|
+ //[]string{"pagenum", strconv.Itoa(pagenum)},
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ sign = GET(action, [][]string{
|
|
|
+ []string{"keyword", keyword},
|
|
|
+ []string{"appid", appid},
|
|
|
+ []string{"timestamp", strconv.Itoa(timestamp)},
|
|
|
+ []string{"pagenum", strconv.Itoa(pagenum)},
|
|
|
+ })
|
|
|
+ }
|
|
|
log.Println(signature, "签名串:", sign)
|
|
|
ordernum := (*res)["ordernum"].(int)
|
|
|
if sign == signature { //签名串验证
|
|
|
+ username = util.ObjToString((*res)["username"])
|
|
|
if action == "getdata" {
|
|
|
rData["data"] = GetData(pagenum, keyword, ordernum)
|
|
|
redis.Put(REDISDB, "jyoacount-"+appid+oaday, apicount+1, 24*60*60)
|
|
@@ -152,6 +162,7 @@ func OpenAction(w http.ResponseWriter, r *http.Request) {
|
|
|
rCode = CODE_E1 //签名错误
|
|
|
rMsg = MSG_E1
|
|
|
}
|
|
|
+ go APIlog(username, action, keyword, appid, rMsg, signature, pagenum, timestamp, rCode, apicount)
|
|
|
if rCode == 0 {
|
|
|
w.Header().Set("Accept-Charset", "utf-8")
|
|
|
w.Header().Set("Content-Type", "application/json")
|