Ejemplo n.º 1
0
    def setUp(self):
        self.interface_url = Config().get('realTime_interface',
                                          index=0)['common'] + interface_no
        self.sign_encrypt_url = Config().get('supportUrl',
                                             index=0)['sign_encrypt_url']
        self.decrypt_and_verify_url = Config().get(
            'supportUrl', index=0)['decrypt_and_verify_url']
        self.encrypt_headers = Header.encrypt_decrypt_headers
        self.http_header = Header().request_headers
        self.merOrderNo = random_str(5, 10)
        self.tradeDate = time.strftime("%Y%m%d", time.localtime())
        self.tradeTime = time.strftime("%H%M%S", time.localtime())
        cg2002_json = {
            "head": {
                "version": "1.0.0",
                "tradeType": "00",
                "merchantNo": self.merchantNo,
                "tradeDate": self.tradeDate,
                "tradeTime": self.tradeTime,
                "merOrderNo": self.merOrderNo,
                "tradeCode": self.tradeCode
            },
            "body": {
                "tradeCode": self.tradeCode_body,
                "queryFlow": self.queryFlow,
                "flowType": self.flowType
            }
        }

        # 加密
        self.request_string = json.dumps(cg2002_json)

        self.sign_and_encrypt_data = {"unencrypt_string": self.request_string}
        sign_and_encrypt_response = requests.post(
            self.sign_encrypt_url,
            data=json.dumps(self.sign_and_encrypt_data),
            headers=self.encrypt_headers)
        sign_and_encrypt_response_txt = json.loads(
            sign_and_encrypt_response.text)
        self.client = HTTPClient(url=self.interface_url,
                                 method='POST',
                                 timeout=10,
                                 headers=self.http_header)
        self.data = {
            "sign": sign_and_encrypt_response_txt['sign'],
            "jsonEnc": sign_and_encrypt_response_txt['jsonEnc'],
            "keyEnc": sign_and_encrypt_response_txt['keyEnc'],
            "merchantNo": self.merchantNo,
            "merOrderNo": self.merOrderNo
        }
Ejemplo n.º 2
0
    def setUp(self):
        self.interface_url = Config().get('page_interface',
                                          index=0)['common'] + interface_no
        self.sign_encrypt_url = Config().get('supportUrl',
                                             index=0)['sign_encrypt_url']
        self.decrypt_and_verify_url = Config().get(
            'supportUrl', index=0)['decrypt_and_verify_url']

        self.submit_url = Config().get('page_interface', index=0)['submit_url']
        self.submit_all_url = Config().get('page_interface',
                                           index=0)['submitAll_url']
        self.common_send_message_url = Config().get(
            'page_interface', index=0)['common_send_message_url']
        self.request_validateParam_url = Config().get(
            'page_interface', index=0)['request_validateParam_url']

        self.encrypt_headers = Header.encrypt_decrypt_headers
        self.http_header = Header().request_headers_page
        self.merOrderNo = random_str(5, 10)
        self.tradeDate = time.strftime("%Y%m%d", time.localtime())
        self.tradeTime = time.strftime("%H%M%S", time.localtime())
        cg1044_json = {
            "head": {
                "version": "1.0.0",
                "tradeType": "00",
                "merchantNo": self.merchantNo,
                "tradeDate": self.tradeDate,
                "tradeTime": self.tradeTime,
                "merOrderNo": self.merOrderNo,
                "tradeCode": self.tradeCode
            },
            "body": {
                "registerPhone": self.registerPhone,
                "custType": self.custType,
                "callbackUrl": self.callbackUrl,
                "responsePath": self.responsePath
            }
        }

        # 签名和加密
        # 加密
        self.request_string = json.dumps(cg1044_json)
        self.sign_and_encrypt_data = {"unencrypt_string": self.request_string}
        sign_and_encrypt_response = requests.post(
            self.sign_encrypt_url,
            data=json.dumps(self.sign_and_encrypt_data),
            headers=self.encrypt_headers)
        sign_and_encrypt_response_txt = json.loads(
            sign_and_encrypt_response.text)

        self.client = HTTPClient(url=self.interface_url,
                                 method='POST',
                                 timeout=10,
                                 headers=self.http_header)
        self.data = {
            "sign": sign_and_encrypt_response_txt['sign'],
            "jsonEnc": sign_and_encrypt_response_txt['jsonEnc'],
            "keyEnc": sign_and_encrypt_response_txt['keyEnc'],
            "merchantNo": self.merchantNo,
            "merOrderNo": self.merOrderNo
        }
Ejemplo n.º 3
0
class TestCG1044(unittest.TestCase):
    '''
    TestCG1044测试类
    '''
    def setParameters(self, caseName, registerPhone, merchantNo, custType,
                      callbackUrl, responsePath, cardNo, code, name, phone,
                      mailAddr, idNo, tradeCode, respCode):
        '''

        :param case_name:
        :param merchant_no:
        :param trade_code_header:
        :param flow_type:
        :param resp_code:
        :param resp_desc:
        :param result_code:
        :param result_msg_result_status:
        :return:
        '''
        self.caseName = str(caseName)
        self.merchantNo = str(merchantNo)
        self.tradeCode = str(tradeCode)
        self.registerPhone = str(registerPhone)
        self.callbackUrl = str(callbackUrl)
        self.responsePath = str(responsePath)
        self.custType = str(custType)
        self.cardNo = str(cardNo)
        self.code = str(code)
        self.name = str(name)
        self.phone = str(phone)
        self.mailAddr = str(mailAddr)
        self.idNo = str(idNo)
        self.respCode = str(respCode)

    def setUp(self):
        self.interface_url = Config().get('page_interface',
                                          index=0)['common'] + interface_no
        self.sign_encrypt_url = Config().get('supportUrl',
                                             index=0)['sign_encrypt_url']
        self.decrypt_and_verify_url = Config().get(
            'supportUrl', index=0)['decrypt_and_verify_url']

        self.submit_url = Config().get('page_interface', index=0)['submit_url']
        self.submit_all_url = Config().get('page_interface',
                                           index=0)['submitAll_url']
        self.common_send_message_url = Config().get(
            'page_interface', index=0)['common_send_message_url']
        self.request_validateParam_url = Config().get(
            'page_interface', index=0)['request_validateParam_url']

        self.encrypt_headers = Header.encrypt_decrypt_headers
        self.http_header = Header().request_headers_page
        self.merOrderNo = random_str(5, 10)
        self.tradeDate = time.strftime("%Y%m%d", time.localtime())
        self.tradeTime = time.strftime("%H%M%S", time.localtime())
        cg1044_json = {
            "head": {
                "version": "1.0.0",
                "tradeType": "00",
                "merchantNo": self.merchantNo,
                "tradeDate": self.tradeDate,
                "tradeTime": self.tradeTime,
                "merOrderNo": self.merOrderNo,
                "tradeCode": self.tradeCode
            },
            "body": {
                "registerPhone": self.registerPhone,
                "custType": self.custType,
                "callbackUrl": self.callbackUrl,
                "responsePath": self.responsePath
            }
        }

        # 签名和加密
        # 加密
        self.request_string = json.dumps(cg1044_json)
        self.sign_and_encrypt_data = {"unencrypt_string": self.request_string}
        sign_and_encrypt_response = requests.post(
            self.sign_encrypt_url,
            data=json.dumps(self.sign_and_encrypt_data),
            headers=self.encrypt_headers)
        sign_and_encrypt_response_txt = json.loads(
            sign_and_encrypt_response.text)

        self.client = HTTPClient(url=self.interface_url,
                                 method='POST',
                                 timeout=10,
                                 headers=self.http_header)
        self.data = {
            "sign": sign_and_encrypt_response_txt['sign'],
            "jsonEnc": sign_and_encrypt_response_txt['jsonEnc'],
            "keyEnc": sign_and_encrypt_response_txt['keyEnc'],
            "merchantNo": self.merchantNo,
            "merOrderNo": self.merOrderNo
        }

    def test_cg1044(self):
        # 请求返回的密文
        try:
            request_response_cg1044 = self.client.send(data=self.data)
            token = request_response_cg1044.cookies.get_dict()['token']
            id = request_response_cg1044.cookies.get_dict()['id']
            message = request_response_cg1044.cookies.get_dict()['message']
            #JSESSIONID = request_response_cg1044.cookies.get_dict()['JSESSIONID']

            cookies = dict(message=message, id=id, token=token)

            # 获取验证码
            requests_message_url = self.common_send_message_url + "phoneNo=" + \
                self.phone + "&token=" + token + "&merOrderNo=" + self.merOrderNo
            self.client_message = HTTPClient(url=requests_message_url,
                                             method='GET',
                                             timeout=10,
                                             headers=self.http_header,
                                             cookies=cookies)

            self.data_message = {
                "phoneNo": self.phone,
                "token": token,
                "merOrderNo": self.merOrderNo
            }

            self.client_validateParam = HTTPClient(
                url=self.request_validateParam_url,
                method='POST',
                timeout=10,
                headers=self.http_header,
                cookies=cookies)
            self.data_validateParam = {
                "idNo": self.idNo,
                "merchantNo": self.merchantNo,
                "merOrderNo": self.merOrderNo
            }
            request_response_validateParam = self.client_validateParam.send(
                data=self.data_validateParam)
            request_response_message = self.client_message.send(
                data=self.data_message)

            # submit
            self.client_submit = HTTPClient(url=self.submit_url,
                                            method='POST',
                                            timeout=10,
                                            headers=self.http_header,
                                            cookies=cookies)
            self.data_submit = {
                "cardNo": self.cardNo,
                "code": 485125,
                "idNo": self.idNo,
                "name": self.name,
                "phone": self.phone,
                "smsCode": 485125,
                "mobile": self.registerPhone,
                "merchantNo": self.merchantNo,
                "merOrderNo": self.merOrderNo,
                "id": id,  # 需要修改id的值
                "token": token,
                "mailAddr": self.mailAddr
            }

            # request_response_submit = requests.post(self.submit_url,data=self.data_submit,headers=self.http_header)
            request_response_submit = self.client_submit.send(
                data=self.data_submit)
            submit_token = token
            submit_cookies = token

            # submitAll
            self.client_submitAll = HTTPClient(url=self.submit_all_url,
                                               method='POST',
                                               timeout=10,
                                               headers=self.http_header,
                                               cookies=cookies)
            self.data_submitAll = {
                "payPwd": "111111",
                "id": submit_cookies,
                "token": submit_token,
                "bankSms": "123456"
            }

            # request_response_submitAll = requests.post(self.submit_all_url,data=self.data_submitAll,headers=self.http_header)
            request_response_submitAll = self.client_submitAll.send(
                data=self.data_submitAll)
            respCode = request_response_submitAll.status_code
            self.assertEquals(respCode, 200)
            # logger.error(self.request_response_submitAll.text)
            print("恭喜,开户成功!")
        except requests.exceptions.ConnectTimeout:
            raise TimeoutError

    def tearDown(self):
        try:
            pass
        except requests.exceptions.ConnectTimeout:
            raise TimeoutError
Ejemplo n.º 4
0
    def test_cg1044(self):
        # 请求返回的密文
        try:
            request_response_cg1044 = self.client.send(data=self.data)
            token = request_response_cg1044.cookies.get_dict()['token']
            id = request_response_cg1044.cookies.get_dict()['id']
            message = request_response_cg1044.cookies.get_dict()['message']
            #JSESSIONID = request_response_cg1044.cookies.get_dict()['JSESSIONID']

            cookies = dict(message=message, id=id, token=token)

            # 获取验证码
            requests_message_url = self.common_send_message_url + "phoneNo=" + \
                self.phone + "&token=" + token + "&merOrderNo=" + self.merOrderNo
            self.client_message = HTTPClient(url=requests_message_url,
                                             method='GET',
                                             timeout=10,
                                             headers=self.http_header,
                                             cookies=cookies)

            self.data_message = {
                "phoneNo": self.phone,
                "token": token,
                "merOrderNo": self.merOrderNo
            }

            self.client_validateParam = HTTPClient(
                url=self.request_validateParam_url,
                method='POST',
                timeout=10,
                headers=self.http_header,
                cookies=cookies)
            self.data_validateParam = {
                "idNo": self.idNo,
                "merchantNo": self.merchantNo,
                "merOrderNo": self.merOrderNo
            }
            request_response_validateParam = self.client_validateParam.send(
                data=self.data_validateParam)
            request_response_message = self.client_message.send(
                data=self.data_message)

            # submit
            self.client_submit = HTTPClient(url=self.submit_url,
                                            method='POST',
                                            timeout=10,
                                            headers=self.http_header,
                                            cookies=cookies)
            self.data_submit = {
                "cardNo": self.cardNo,
                "code": 485125,
                "idNo": self.idNo,
                "name": self.name,
                "phone": self.phone,
                "smsCode": 485125,
                "mobile": self.registerPhone,
                "merchantNo": self.merchantNo,
                "merOrderNo": self.merOrderNo,
                "id": id,  # 需要修改id的值
                "token": token,
                "mailAddr": self.mailAddr
            }

            # request_response_submit = requests.post(self.submit_url,data=self.data_submit,headers=self.http_header)
            request_response_submit = self.client_submit.send(
                data=self.data_submit)
            submit_token = token
            submit_cookies = token

            # submitAll
            self.client_submitAll = HTTPClient(url=self.submit_all_url,
                                               method='POST',
                                               timeout=10,
                                               headers=self.http_header,
                                               cookies=cookies)
            self.data_submitAll = {
                "payPwd": "111111",
                "id": submit_cookies,
                "token": submit_token,
                "bankSms": "123456"
            }

            # request_response_submitAll = requests.post(self.submit_all_url,data=self.data_submitAll,headers=self.http_header)
            request_response_submitAll = self.client_submitAll.send(
                data=self.data_submitAll)
            respCode = request_response_submitAll.status_code
            self.assertEquals(respCode, 200)
            # logger.error(self.request_response_submitAll.text)
            print("恭喜,开户成功!")
        except requests.exceptions.ConnectTimeout:
            raise TimeoutError
Ejemplo n.º 5
0
class TestCG2001(unittest.TestCase):
    '''
    TestCG2001测试类
    '''
    def setParameters(self, case_name, merchant_no, trade_code, acctNo,
                      resp_code, resp_desc):
        '''

        :param case_name:
        :param merchant_no:
        :param trade_code_header:
        :param flow_type:
        :param resp_code:
        :param resp_desc:
        :param result_code:
        :param result_msg_result_status:
        :return:
        '''
        self.caseName = str(case_name)
        self.merchantNo = str(merchant_no)
        self.tradeCode = str(trade_code)
        self.acctNo = str(acctNo)
        self.respCode = str(resp_code)
        self.respDesc = str(resp_desc)
        self.response = None

    def setUp(self):
        self.interface_url = Config().get('realTime_interface',
                                          index=0)['common'] + interface_no
        self.sign_encrypt_url = Config().get('supportUrl',
                                             index=0)['sign_encrypt_url']
        self.decrypt_and_verify_url = Config().get(
            'supportUrl', index=0)['decrypt_and_verify_url']
        self.encrypt_headers = Header.encrypt_decrypt_headers
        self.http_header = Header().request_headers
        self.merOrderNo = random_str(5, 10)
        self.tradeDate = time.strftime("%Y%m%d", time.localtime())
        self.tradeTime = time.strftime("%H%M%S", time.localtime())
        cg2001_json = {
            "head": {
                "version": "1.0.0",
                "tradeType": "00",
                "merchantNo": self.merchantNo,
                "tradeDate": self.tradeDate,
                "tradeTime": self.tradeTime,
                "merOrderNo": self.merOrderNo,
                "tradeCode": self.tradeCode
            },
            "body": {
                "acctNo": self.acctNo
            }
        }

        # 加密
        self.request_string = json.dumps(cg2001_json)

        self.sign_and_encrypt_data = {"unencrypt_string": self.request_string}
        sign_and_encrypt_response = requests.post(
            self.sign_encrypt_url,
            data=json.dumps(self.sign_and_encrypt_data),
            headers=self.encrypt_headers)
        sign_and_encrypt_response_txt = json.loads(
            sign_and_encrypt_response.text)
        self.client = HTTPClient(url=self.interface_url,
                                 method='POST',
                                 timeout=10,
                                 headers=self.http_header)
        self.data = {
            "sign": sign_and_encrypt_response_txt['sign'],
            "jsonEnc": sign_and_encrypt_response_txt['jsonEnc'],
            "keyEnc": sign_and_encrypt_response_txt['keyEnc'],
            "merchantNo": self.merchantNo,
            "merOrderNo": self.merOrderNo
        }

    def test_cg2001(self):
        try:
            request_response = self.client.send(
                data=json.dumps(self.data).encode())
            request_response_txt = json.loads(request_response.text)
            self.decrypt_and_verify_data = {
                "sign": request_response_txt['sign'],
                "jsonEnc": request_response_txt['jsonEnc'],
                "keyEnc": request_response_txt['keyEnc']
            }
            self.decrypt_and_verify_response = requests.post(
                self.decrypt_and_verify_url,
                data=json.dumps(self.decrypt_and_verify_data),
                headers=self.encrypt_headers)
            self.check_result()
        except requests.exceptions.ConnectTimeout:
            raise TimeoutError

    def tearDown(self):
        try:
            pass
        except requests.exceptions.ConnectTimeout:
            raise TimeoutError

    def check_result(self):
        self.result = json.loads(self.decrypt_and_verify_response.text)
        self.check = json.loads((self.result['json']))
        self.check2 = json.dumps((self.check['head']))
        self.check3 = json.loads(self.check2)
        logger.error(self.decrypt_and_verify_response.text)
        #self.assertEqual(self.check3['respCode'], self.respCode)
        print("余额查询成功,测试结果为:" + self.check3['respDesc'])
        print("余额查询响应报文为:")
        print(self.check)
Ejemplo n.º 6
0
# @File    : extractor.py
# @Software: PyCharm
"""

"""抽取器类,从响应结果中抽取部分数据"""

import json
import jmespath

class JMESPathExtractor(object):
    """
    用JMESPath实现的抽取器,对于json格式数据实现简单方式的抽取。
    """
    def extract(self, query=None, body=None):
        try:
            return jmespath.search(query, json.loads(body))
        except Exception as  e:
            raise ValueError('Invalid query:' + query + str(e))
        

if __name__ == '__main__':
    from utils.configHttp import HTTPClient
    res = HTTPClient(url='http://wthrcdn.etouch.cn/weather_mini?citykey=101010100').send()
    print(res.text)
    
    j = JMESPathExtractor()
    j_1 = j.extract(query='data.forecast[1].date', body=res.text)
    j_2 = j.extract(query='data.ganmao', body=res.text)
    print(j_1, j_2)