openCard.py 9.41 KB
#coding=utf-8

# @Time    : 2021/7/16 14:09
# @Author  : Ljq
# @File    : openMasterCard.py
# @Software: PyCharm


"""
    主卡开卡页面接口
"""

import requests
import json
import re
import time
from interface.scripts import dealContentType as dCT

def getCustomerInfo(gatewayHost=None,clientHeaders=None,cCNum=360101199301010275):
    """
    查询输入的证件号是否有匹配客户信息
    :param cardHost:
    :param clientHeaders:
    :param cCNum:
    :return:
    """
    url = gatewayHost+"/card-web/card/getCustomerInfo.action"
    clientHeaders = dCT.jsonCT(clientHeaders)
    data = {"customerCertificateNumber":str(cCNum)}
    res = requests.post(url=url,headers=clientHeaders,data=json.dumps(data))
    return res

def getSubTypeName(gatewayHost=None,clientHeaders=None,customerId=131176):
    """
    查询客户身份类型名称
    :param gatewayHost:
    :param clientHeaders:
    :param customerId:
    :return:
    """
    url = gatewayHost+f"/card-web/customer/getSubTypeName.action?customerId={customerId}"
    res = requests.post(url=url,headers=clientHeaders)
    return res

def checkNewCardNo(gatewayHost=None,clientHeaders=None,**kwargs):
    """
    校验卡与当前客户类型状态是否匹配
    :param gatewayHost:
    :param clientHeaders:
    :param kwargs: 主卡:{"cardNo":"888810032426","cardType":10,"customerType":"in_province","customerId":131167}
                副卡:{"cardNo":"888800001130","cardType":20}
    :return:
    """
    url = gatewayHost+"/card-web/card/checkNewCardNo.action"
    clientHeaders = dCT.jsonCT(clientHeaders)
    print("kwargs ------------->",kwargs)
    if "cardType" not in kwargs or kwargs["cardType"]==10:
        data={"cardNo":"888810032426","cardType":10,"customerType":"in_province","customerId":131167}
    # elif kwargs["cardType"]==10:
    #     data = {"cardNo": "888810032426", "cardType": 10, "customerType": "in_province", "customerId": 131167}
    else:
        data={}
    data = dict(data,**kwargs)
    print(data)
    res = requests.post(url=url,headers=clientHeaders,data=json.dumps(data))
    return res

def getOpenCardFee(gatewayHost=None,clientHeaders=None):
    url = gatewayHost+"/card-web/card/getOpenCardFee.action"
    res = requests.get(url=url,headers=clientHeaders)
    return res

def openMasterCard(gatewayHost=None,clientHeaders=None,**kwargs):
    """
    开卡接口
    :param gatewayHost:
    :param clientHeaders:
    :param kwargs: {"customerName":"长歌园外买家自动化用户不要动","customerType":"outside_buyer","customerId":131183,
                    "customerOrganizationType":"individual","customerCredentialType":"ID","customerContactsPhone":"18080001015",
                    "loginPwd":"111111","cardNo":"888810005703","customerCertificateNumber":"230681202105267887","cardType":10,
                    "costFee":888,"customerCode":"00130892","name":"长歌",
                    "createSource":1,"holdName":"长歌园外买家自动化用户不要动","holdContactsPhone":"18080001015","customerSyncModifyHoldinfo":1}
    :return:
    """
    url = gatewayHost+"/card-web/card/openMasterCard.action"
    clientHeaders = dCT.jsonCT(clientHeaders)
    data={"customerName":"","customerType":"","customerId":None,"customerOrganizationType":"","customerCredentialType":"","customerContactsPhone":"","loginPwd":"","cardNo":"","customerCertificateNumber":"","cardType":None,"costFee":None,"customerCode":"","name":"","createSource":1,"holdName":"","holdContactsPhone":"","customerSyncModifyHoldinfo":1}
    data=dict(data,**kwargs)
    print("openMasterCard   data ---->  ",data)
    res = requests.post(url=url,headers=clientHeaders,data=json.dumps(data))
    return res

def openMasterCardDef(gatewayHost=None,clientHeaders=None,cCNum=None,cardNo=None,loginPwd=111111,applyUserName=None):

    # 获取手续费
    costFee = getOpenCardFee(gatewayHost=gatewayHost, clientHeaders=clientHeaders).json()["data"]
    print(costFee)
    # 获取客户信息
    resCusInfo = getCustomerInfo(gatewayHost=gatewayHost, clientHeaders=clientHeaders,
                                     cCNum=cCNum).json()["data"]
    print(resCusInfo)
    # 客户信息准备
    customerName = resCusInfo["name"]
    customerType = resCusInfo["customerType"]
    customerId = resCusInfo["id"]
    customerOrganizationType = resCusInfo["organizationType"]
    customerCredentialType = resCusInfo["certificateType"]
    customerContactsPhone = resCusInfo["customerContactsPhone"]
    customerCertificateNumber = resCusInfo["certificateNumber"]
    customerCode = resCusInfo["code"]
    name = applyUserName
    holdName = resCusInfo["name"]
    holdContactsPhone = resCusInfo["customerContactsPhone"]

    # 卡片状态校验
    resCheck = checkNewCardNo(gatewayHost=gatewayHost, clientHeaders=clientHeaders,
                                  cardNo=cardNo,
                                  customerId=customerId,
                                  customerType=customerType)
    print(resCheck.json())
    # assert "200" == resCheck.json()["code"], "卡片校验失败"

    # 开卡
    print("开始开卡")
    resOpenCard = openMasterCard(gatewayHost=gatewayHost, clientHeaders=clientHeaders,
                                     cardNo=cardNo,
                                     costFee=costFee, customerName=customerName, customerType=customerType,
                                     customerId=customerId, loginPwd=loginPwd,
                                     customerOrganizationType=customerOrganizationType,
                                     customerCredentialType=customerCredentialType,
                                     customerContactsPhone=customerContactsPhone,
                                     customerCertificateNumber=customerCertificateNumber, customerCode=customerCode,
                                     name=name, holdName=holdName, holdContactsPhone=holdContactsPhone, cardType=10)
    print("resOpenCard.json()", resOpenCard.json())
    return resOpenCard

def getAccountInfo(gatewayHost=None,clientHeaders=None,cardNo=None):
    url = gatewayHost+"/card-web/card/getAccountInfo.action"
    clientHeaders=dCT.jsonCT(clientHeaders)
    data = {"cardNo":str(cardNo)}
    res = requests.post(url=url,headers=clientHeaders,data=json.dumps(data))
    return res

def openSlaveCard(gatewayHost=None,clientHeaders=None,**kwargs):
    """

    :param gatewayHost:
    :param clientHeaders:
    :param kwargs:{"customerName":"长歌一","customerType":null,"customerId":131136,"customerOrganizationType":"individual",
            "customerCredentialType":"ID","customerContactsPhone":"18050005001","loginPwd":"111111","cardNo":"800000020435",
                "customerCertificateNumber":"110101200803075932","cardType":20,"costFee":999,"customerCode":"00130845",
                "name":"沈阳长歌","parentAccountId":104547,"createSource":1,"parentLoginPwd":"111111","holdName":"长歌一",
                "holdContactsPhone":"18050005001","customerSyncModifyHoldinfo":1}
    :return:
    """
    url = gatewayHost+"/card-web/card/openSlaveCard.action"
    clientHeaders = dCT.jsonCT(clientHeaders)
    data={"customerName":"长歌一","customerType":None,"customerId":131136,"customerOrganizationType":"individual","customerCredentialType":"ID","customerContactsPhone":"18050005001","loginPwd":"111111","cardNo":"800000020435","customerCertificateNumber":"110101200803075932","cardType":20,"costFee":999,"customerCode":"00130845","name":"沈阳长歌","parentAccountId":104547,"createSource":1,"parentLoginPwd":"111111","holdName":"长歌一","holdContactsPhone":"18050005001","customerSyncModifyHoldinfo":1}
    data = dict(data,**kwargs)
    res = requests.post(url=url,headers=clientHeaders,data=json.dumps(data))
    return res

def openSlaveCardDef(gatewayHost=None,clientHeaders=None,cardNo=None,slaveCardNo=None,loginPwd=None,applyUserName=None,parentLoginPwd=None):
    costFee = getOpenCardFee(gatewayHost=gatewayHost, clientHeaders=clientHeaders).json()["data"]
    print(costFee)
    resGet = getAccountInfo(gatewayHost=gatewayHost, clientHeaders=clientHeaders, cardNo=cardNo).json()["data"]
    print("resGet    --->   ", resGet)
    customerName = resGet["customerName"]
    customerId = resGet["customerId"]
    customerCredentialType = resGet["customerCertificateType"]
    customerContactsPhone = resGet["customerContactsPhone"]
    customerCertificateNumber = resGet["customerCertificateNumber"]
    cardType = 20
    customerCode = resGet["customerCode"]
    name = applyUserName
    parentAccountId = resGet["accountId"]
    holdName = customerName
    holdContactsPhone = customerContactsPhone
    resOpenSlaveCard = openSlaveCard(gatewayHost=gatewayHost, clientHeaders=clientHeaders,
                                         customerName=customerName,
                                         customerId=customerId, customerContactsPhone=customerContactsPhone,
                                         loginPwd=loginPwd, cardNo=slaveCardNo,
                                         customerCertificateNumber=customerCertificateNumber, cardType=cardType,
                                         costFee=costFee, customerCode=customerCode,
                                         name=name, parentAccountId=parentAccountId, parentLoginPwd=parentLoginPwd,
                                         holdName=holdName,
                                         holdContactsPhone=holdContactsPhone,
                                         customerCredentialType=customerCredentialType
                                         )
    return resOpenSlaveCard