Browse Source

增加服务端提交参数

csk 5 years ago
parent
commit
2e412df9e2

+ 7 - 1
apps/limit/biz/demo_year_limit.py

@@ -6,7 +6,7 @@
 # date: 2019-12-18
 
 import json
-from flask import Flask, Response
+from flask import Flask, request, Response
 
 # Flask对象
 app = Flask(__name__)
@@ -20,6 +20,12 @@ def response_headers(content):
 
 @app.route('/al/cus/yearLimit', methods=['GET', 'POST'])
 def query_year_limit():
+    if request.method == 'POST':
+        post_form = request.form
+        print("/al/cus/yearLimit POST请求参数post_form:{}".format(str(post_form)))
+    if request.method == 'GET':
+        args_form = request.args
+        print("/al/cus/yearLimit GET请求参数args_form:{}".format(str(args_form)))
     result = {
         "code": "0",
         "msg": "跨境额度查询成功",

+ 5 - 2
apps/limit/biz/signature.py

@@ -38,8 +38,11 @@ class Signature:
     def sign_with_md5(self):
         self.__dict_sort_asc()
         self.__params_joint()
-        self.__out_params['sign'] = md5(self.__joint_str.encode("utf-8")).hexdigest()
-        print('md5签名的参数:{}'.format(str(self.__out_params)))
+        sign_str = md5(self.__joint_str.encode("utf-8")).hexdigest()
+        print('md5签名的参数值:{}'.format(sign_str))
+
+        self.__out_params['sign'] = sign_str
+        print('请求参数签名结果:{}'.format(str(self.__out_params)))
         return self.__out_params
 
 

+ 8 - 6
apps/limit/biz/year_limit_query.py

@@ -46,15 +46,17 @@ class YearLimitQuery:
     def __sign(self):
         req_params = self.__build_req_params()
         instance = Signature(req_params, self.__secret_key)
-        ret = instance.sign_with_md5()
-        print(str(ret))
+        ret_sign = instance.sign_with_md5()
+        return ret_sign
 
     # 额度查询请求并返回结果
-    def __req(self):
+    def __req(self, req_params):
         result = {}
         try:
             req_url = config_json["year_limit_url"]
-            response = requests.request("POST", req_url, timeout=20)
+            # GET方法,必须是params=str(dict or list or tuple or bytes)
+            # POST方法,必须是data=dict or list or tuple or bytes or file
+            response = requests.request("POST", req_url, data=req_params, timeout=20)
             if response.text:
                 result = json.loads(response.text)
                 print("API返回数据:{}".format(result))
@@ -89,8 +91,8 @@ class YearLimitQuery:
         return result
 
     def query(self):
-        self.__sign()
-        return self.__req()
+        ret = self.__sign()
+        return self.__req(ret)
 
 
 # 单元测试