def bank_card_img(customerid, token):
    '''
    银行卡图片上传
    :param token:
    :param customerid:
    :return: 图片地址
    '''
    logging.info('------------------------start:银行卡图片上传---------------------')
    head = common_public.App_head()
    head['TOKEN'] = token
    dir = os.getcwd() + r'\img\bank_img.jpg'
    url = common_public.URL() + 'api_007'
    data1 = {
        'HEAD': common_public.App_head(),
        'BODY': {
            "bizType": "stCard",
            "id": customerid
        }
    }

    data = json.dumps(data1)
    logging.info('data:' + data)
    files = {
        "REQ_MESSAGE": (None, data),
        'idPicture': ('bank_img.jpg', open(dir, 'rb'), 'image/jpg')
    }
    respons = requests.post(url=url, files=files)
    logging.info('respons:' + respons.text)
    logging.info('---------------------end:银行卡图片上传---------------------')
    result = respons.json()
    return result['BODY']['imgPath']
 def register(self):
     '''
     手机号注册商户
     :return:
     '''
     logging.info(
         '---------------------start:手机号注册商户-------------------------')
     url = common_public.URL() + 'api_001'
     data1 = {
         "HEAD": common_public.App_head(),
         "BODY": {
             "code": "6666",
             "password": "******",
             "mobile": self.mobile,
             "firPassword": "******",
             "type": "1",
             "accountType": "1"
         }
     }
     logging.info('请求地址:' + url)
     logging.info('请求参数:' + data1)
     data = json.dumps(data1)
     respons = requests.post(url=url, data=data)
     assert respons.status_code == 200
     logging.info(
         '-----------------end:手机号注册成功----------------------------------')
def customer_information(
    token,
    customerid,
    electronic_signature_img,
):
    url = common_public.URL() + 'api_418'
    logging.info('----------------start:完善商户信息-------------------')
    head = common_public.App_head()
    head['TOKEN'] = token
    head['TYPE'] = '2'
    data = {
        'HEAD': head,
        'BODY': {
            "mercAreaId": "5211",
            "accountType": "1",
            "mercCityId": "5210",
            "manageInfoPath": electronic_signature_img,
            "type": "1",
            "merShortName": common_public.customer_name_company(),
            "mccCode": "5462",
            "mercFullName": common_public.customer_name_company(),
            "whetherBusiness": "2",
            "id": customerid,
            "mercAddress": "陕西省西安市应人石村",
            "mercProvId": "5200",
            "manageInfoState": "10"
        }
    }
    data1 = json.dumps(data)
    logging.info('data:' + data1)
    respons = requests.post(url, data=data1)
    logging.info('respons:' + respons.text)
    logging.info('---------------------end:完善商户信息---------------------')
def identity_check(customerid, frontpath, backpath, holdpath, token):
    '''
    身份信息确认(customerid,frontpath,backpath,holdpath)
    :return:请求respons
    '''
    logging.info('------start:身份信息确认-----------')
    head = common_public.App_head()
    head['TYPE'] = '2'
    head['ACCOUNT_TYPE'] = '1'
    head['TOKEN'] = token

    url = common_public.URL() + 'api_161'
    data1 = {
        'HEAD': head,
        'BODY': {
            "realName": common_public.customer_name(),
            "expiryDateEnd": "20391026",
            "address": "山西省河津市世纪花园1单元101",
            "holdPath": holdpath,
            "frontPath": frontpath,
            "backPath": backpath,
            "idCard": common_public.id_card_number(),
            "expiryDateBegin": "20191026",
            "id": customerid
        }
    }
    data = json.dumps(data1)
    logging.info('url:' + url)
    logging.info("requests:" + data)
    respons = requests.post(url=url, data=data)
    logging.info('result:' + respons.text)
    assert respons.status_code == 200
    logging.info('-----------------end:身份确认完成----------------')
    return data1['BODY']
def ID_upload_hold(customer):
    '''
    手持身份证照片
    :return:图片地址
    '''
    logging.info('------start:上传手持身份证-----------')

    url = common_public.URL() + 'api_007'
    dir = os.getcwd() + r'\img\hold.jpg'
    data1 = {
        "HEAD": common_public.App_head(),
        "BODY": {
            "id": customer,
            "bizType": "idImg",
            "imageType": 3,
            "accountType": "1"
        }
    }

    data = json.dumps(data1)

    files = {
        'REQ_MESSAGE': (None, data),
        'idPicture': ('hold.jpg', open(dir, 'rb'), 'image/jpg')
    }
    logging.info('url:' + url)
    logging.info('data:' + data)

    respons = requests.post(url=url, files=files)
    logging.info('respons:' + respons.text)
    assert respons.status_code == 200
    result = respons.json()
    logging.info('return:' + result['BODY']['imgPath'])
    logging.info('--------------------end:上传手持身份证----------------')
    return result['BODY']['imgPath']
def add_bank_information(token, id, realname, idcard, bankmobile, img):
    '''
    添加结算卡
    :param token:token
    :param id:商户id
    :param realname:商户实名名称
    :param idcard:商户身份证号
    :param bankmobile:商户银行卡预留手机号
    :param img:银行卡图片地址
    :return:
    '''
    logging.info('----------------------start:添加银行卡确认-------------------')
    URL = common_public.URL() + 'api_016'
    head = common_public.App_head()
    head['TOKEN'] = token
    head['TYPE'] = '2'
    data = {
        'HEAD': head,
        'BODY': {
            "code": "6666",
            "codeType": 3,
            "accountName": realname,
            "idCard": idcard,
            "accountType": 1,
            "bankMobile": bankmobile,
            "type": "1",
            "realName": realname,
            "isPublicAcc": "0",
            "bankbranchName": "中国建设银行股份有限公司北京平谷新开街支行",
            "tposBankFrontPath": img,
            "id": id,
            "account": common_public.bank_number(),
            "paybankNo": "105100031442"
        }
    }

    data1 = json.dumps(data)
    logging.info('data:' + data1)
    respons = requests.post(url=URL, data=data1)
    logging.info('respons:' + respons.text)
    logging.info('----------------end:添加银行卡确认-----------------------')
    def code(self):
        '''
        注册获取验证码
        :return:

        '''

        url = common_public.URL() + 'api_002'
        data1 = {
            "HEAD": common_public.App_head(),
            "BODY": {
                "type": "1",
                "mobile": self.mobile
            }
        }
        logging.info('请求地址:' + url + ',' + '请求参数:' + data1)
        data = json.dumps(data1)
        respons = requests.post(url=url, data=data)
        result = respons.json()
        assert result['HEAD']['MSG'] == '操作成功'
        logging.info(
            '---------------------end------------验证码获取成功---------------------')
def ID_upload_positive(customerid):
    '''
    身份证正面上传
    :return:图片地址
    '''
    logging.info('------start:上传身份证正面-----------')

    url = common_public.URL() + 'api_007'
    dir = os.getcwd() + r'\img\positive.jpg'
    data1 = {
        "HEAD": common_public.App_head(),
        "BODY": {
            "id": customerid,
            "bizType": "idImg",
            "imageType": '1'
        }
    }
    data = json.dumps(data1)
    # 上传文件单独构造成以下形式
    # 'img' 上传文件的键名
    # 'demo' 上传到服务器的文件名,可以和上传的文件名不同
    # open('D:/demo.jpg') 打开的文件对象,注意文件路径正确
    # 'image/jpeg' Content-Type类型

    files = {
        'REQ_MESSAGE': (None, data),
        'idPicture': ('positive.jpg', open(dir, 'rb'), 'image/jpg')
    }
    logging.info('url:' + url)
    logging.info('data:' + data)

    respons = requests.post(url=url, files=files)

    logging.info('respons:' + respons.text)
    assert respons.status_code == 200
    result = respons.json()
    logging.info('return:' + result['BODY']['imgPath'])
    logging.info('--------------------end:上传身份证正面----------------')
    return result['BODY']['imgPath']
def electronic_signature(token, customerid):
    '''
    确认函图片上场
    :param token:token
    :param customerid:商户id
    :return: 返回地址
    '''
    url = common_public.URL() + 'api_007'
    head = common_public.App_head()
    head['TOKEN'] = token
    head['TYPE'] = '2'
    logging.info('----------------start:确认函图片上传')
    dir = os.getcwd() + r'\img\signature.jpg'
    data1 = {
        'HEAD': head,
        'BODY': {
            'bizType': "csAuth",
            "accountType": "1",
            "id": customerid,
            "imageType": "7"
        }
    }

    data = json.dumps(data1)
    logging.info('respons:' + data)
    files = {
        "REQ_MESSAGE": (None, data),
        'idPicture': ('signature.jpg', open(dir, 'rb'), 'image/jpg')
    }

    respons = requests.post(url=url, files=files)
    logging.info('respons:' + respons.text)
    result = respons.json()

    logging.info('---------------------end:确认函图片上传---------------------')
    logging.info('return:' + result['BODY']['imgPath'])

    return result['BODY']['imgPath']
def login(mobile, password):
    '''
    账号密码登录
    :return:BODY:{"customerInfo":{"customerId":32,"bindState":10,"authState":1,"bankState":1,
    "actnState":1,"examineState":0,"agreementState":1,"signTime":"20201027","policyId":0,
    "mobile":"15600000033","realName":"监督活动","idCard":"142703199110162789","pendIncome":0,
    "depositAmount":null},
    "token":"vqtQipq6K72Hw9NZf6DQor15cjcpQkXcw9Gxw6ZkulNrIRRQiLpTDOb6RZ4WlAR99ZQIFTEC1rGvbAJXmNzwChkm8XGpQPjOXF5zS0ZCpqY=",
    "isVip":false,"isBuyVip":false}}
    '''
    logging.info('----------------start:商户登录------------------------')
    url = common_public.URL() + 'api_004'
    data1 = {
        "HEAD": common_public.App_head(),
        "BODY": {
            "password": password,
            "accountType": "1",
            "mobile": mobile
        }
    }
    logging.info('请求地址:' + url)

    data = json.dumps(data1)
    logging.info('请求参数:' + data)

    respons = requests.post(url=url, data=data)
    logging.info('----------------end:返回值------------------------')
    logging.info(respons.text)
    assert respons.status_code == 200
    print(respons.cookies)
    coolies = requests.utils.dict_from_cookiejar(respons.cookies)
    print(coolies)

    result = respons.json()
    assert result['HEAD']['MSG'] == '操作成功'
    logging.info('----------------end:登录成功------------------------')
    return result['BODY']
Beispiel #11
0
 def set_url(self, url):
     logging.info(
         '------------------------------start----------------------')
     url1 = common_public.URL() + url
     logging.info('url:' + url1)
     self.url = url1