#!/user/bin/env python
# -*-encoding:utf-8-*-
import flask
import hashlib
app = flask.Flask(__name__)
@app.route(rule="/getsign",methods=["POST","GET"])
def getsign():
if flask.request.method in ["POST"]:
params = flask.request.get_json()
pid = flask.request.headers.get("pid")
timestap = flask.request.headers.get("clienttime")
appkey = "*s&iN#G70*"
keys = params.keys()
keys = sorted(keys)
queryString = ""
appKey = appkey
for key in keys:
queryString += key + "=" + str(params[key]) + "&"
if len(queryString) > 0:
queryString = queryString[:len(queryString) - 1]
queryString = queryString + appKey
result = hashlib.md5(queryString.encode()).hexdigest()
if pid in ["66595239"] and str(params["clienttime"]) == str(timestap):
return str({"code":0,"msg":"成功","sign":str(result[8:24])}),200,{"pid":pid,"clienttime":timestap}
elif pid not in ["66595239"] and str(params["clienttime"]) == str(timestap):
return str({"code":1,"msg":"非指定用户,拒绝请求","sign":""}),403,{"pid":pid,"clienttime":timestap}
elif pid in ["66595239"] and str(params["clienttime"]) != str(timestap):
return str({"code": 2, "msg": "时间戳不对应,请检查!", "sign": ""}), 403, {"pid": pid, "clienttime": timestap}
else:
return str({"code": 3, "msg": "时间戳用户不对应,请检查!", "sign": ""}), 403, {"pid": pid, "clienttime": timestap}
elif flask.request.method in ["GET"]:
params = flask.request.args
d = {}
for k,v in params.items():
d.update({k:v})
pid = flask.request.headers.get("pid")
timestap = flask.request.headers.get("clienttime")
appkey = "*s&iN#G70*"
keys = params.keys()
keys = sorted(keys)
queryString = ""
appKey = appkey
for key in keys:
queryString += key + "=" + str(params[key]) + "&"
if len(queryString) > 0:
queryString = queryString[:len(queryString) - 1]
queryString = queryString + appKey
result = hashlib.md5(queryString.encode()).hexdigest()
if pid in ["66595239"] and str(d["clienttime"]) == str(timestap):
return str({"code":0,"msg":"成功","sign":str(result[8:24])}),200,{"pid":pid,"clienttime":timestap}
elif pid not in ["66595239"] and str(d["clienttime"]) == str(timestap):
return str({"code":1,"msg":"非指定用户,拒绝请求","sign":""}),403,{"pid":pid,"clienttime":timestap}
elif pid in ["66595239"] and str(d["clienttime"]) != str(timestap):
return str({"code": 2, "msg": "时间戳不对应,请检查!", "sign": ""}), 403, {"pid": pid, "clienttime": timestap}
else:
return str({"code": 3, "msg": "时间戳用户不对应,请检查!", "sign": ""}), 403, {"pid": pid, "clienttime": timestap}
if __name__ == '__main__':
app.run(host="127.0.0.1",port=8080,debug=True)
#!/user/bin/env python
# -*-encoding:utf-8-*-
import time
import requests
import json
from publicMethod import getSign
from publicMethod import mysql
from publicMethod import conmand
from urllib.parse import urlencode
from rediscluster import RedisCluster
class case:
def __init__(self):
self.timestap = int(time.time() * 1000)
self.headerUrl = {
"Content-Type":"application/x-www-form-urlencoded",
"pid":"66595239",
"clienttime": str(self.timestap)
}
self.headerJson = {
"Content-Type":"application/json",
"pid":"66595239",
"clienttime": str(self.timestap)
}
def getsign_post(self):
self.url = "http://127.0.0.1:8080/getsign"
self.body = {
"appid": "2860",
"clientver": "300000",
"clienttime": str(self.timestap),
"uuid": "eddbf2b6e7055dc45fad51efb7d95796",
"mid": "81542419015019914174620791166427706049",
"dfid": "-",
"device": "eddbf2b6e7055dc45fad51efb7d95796",
"playerId": "66595239",
"sn": "0",
}
r = requests.post(url=self.url,json=self.body,headers=self.headerJson)
print(r.text)
print(r.status_code)
print(r.headers)
def getsign_get(self):
self.url = "http://127.0.0.1:8080/getsign?"
self.uri = {
"appid": "2860",
"clientver": "300000",
"clienttime": str(self.timestap),
"uuid": "eddbf2b6e7055dc45fad51efb7d95796",
"mid": "81542419015019914174620791166427706049",
"dfid": "-",
"device": "eddbf2b6e7055dc45fad51efb7d95796",
"playerId": "66595239",
"sn": "0",
}
r = requests.get(url=self.url+urlencode(self.uri),headers=self.headerUrl)
print(r.text)
print(r.status_code)
print(r.headers)
if __name__ == '__main__':
r = case()
r.getsign_post()
r.getsign_get()
|