思路

封装通用加密接口方法api

封装,知道是base64的就调用base64解码,有其他的加解密算法,让开发给,去调用即可,如果是三方的post过去让三方解码

封装:

import requests
import json
import base64
class ApiRequest:

    def send(self,data:dict):
        res = requests.request(data["method"],data["'url"],headers= data["headers"])
        if data["encoding"] == "base64":
            return json.loads(base64.decode(res.content))
        elif data["encoding"] == "private":
            requests.post("url",data=res.content)

调用:

from unittest import TestCase
from api import test_request1

class TestApiRequest(TestCase):
    req_data = {
        "method": "get",
        "url": "http://127.0.0.1:9999/demo1.text",
        "headers": None,
        "encoding": "base64"
    }
    def test_send(self):
        ar = test_request1.ApiRequest
        print(ar.send(self.req_data))
posted on 2021-09-12 16:36  嗷呜喵喵  阅读(74)  评论(0编辑  收藏  举报