Пример #1
0
def profession_query(**kw):
    """ 行业信息查询 """
    now = datetime.now()
    req_packet = py8583.Iso8583(IsoSpec=py8583spec.IsoSpec1987BCD())
    req_packet.MTI('0100')
    req_packet.TPDU('6005810000')
    req_packet.HEADER('603100000000')
    req_packet.FieldData(3, '310000')  # 交易处理码
    req_packet.FieldData(11, now.strftime('%H%M%S'))  # 终端交易流水
    req_packet.FieldData(25, '87')  # 服务点条件码
    req_packet.FieldData(41, kw.get('TerminalNo', '52010009'))  # 终端代码
    req_packet.FieldData(42, kw.get('MerchantNo', '898520154110004'))  # 商户代码
    req_packet.FieldData(48, kw.get('OrgCode', None))  #行业特定信息
    req_packet.FieldData(64, '0000000000000000')
    req_packet.FieldData(
        64, calc_mac_cbc(MAB=req_packet.BuildIso()[11:-8]))  # 报文鉴别码
    print("行业信息查询: ")
    req_packet.PrintMessage()
    data = req_packet.BuildIso()
    data = struct.pack('!H', len(data)) + data
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((HOST, PORT))
    py8583.MemDump("Sending: ", data)
    sock.send(data)
    data = sock.recv(4096)
    py8583.MemDump('Received: ', data)
    sock.close()
    parse_package(data)
Пример #2
0
def payment_revoke(**kw):
    """ 缴费撤销 """
    now = datetime.now()
    req_packet = py8583.Iso8583(IsoSpec=py8583spec.IsoSpec1987BCD())
    req_packet.MTI('0200')
    req_packet.TPDU('6005810000')
    req_packet.HEADER('603100000000')
    req_packet.FieldData(2, kw.get('PAN', '6212142000000000012'))  # 主账号
    req_packet.FieldData(3, '280000')  # 交易处理码
    req_packet.FieldData(4, kw.get('amount', '1').rjust(12, '0'))  # 交易金额
    req_packet.FieldData(11, now.strftime('%H%M%S'))  # 终端交易流水
    req_packet.FieldData(14, '2912')  # 卡有效期
    req_packet.FieldData(22, '051')  # 服务点输入方式
    req_packet.FieldData(23, kw.get('CardOrder', '000'))  # 卡序列号
    req_packet.FieldData(25, '81')  # 服务点条件码
    req_packet.FieldData(26, '06')  # 服务点PIN获取码
    req_packet.FieldData(
        35, kw.get('Track2', '6212142000000000012=29122206899031006'))  # 二磁道数据
    req_packet.FieldData(36, kw.get('Track3', None))  # 三磁道数据
    req_packet.FieldData(37, kw.get('ReferNo', None))  # 原交易参考号
    req_packet.FieldData(38, kw.get('AuthNo', None))  # 原交易授权码
    req_packet.FieldData(41, kw.get('TerminalNo', '52010009'))  # 终端代码
    req_packet.FieldData(42, kw.get('MerchantNo', '898520154110004'))  # 商户代码
    req_packet.FieldData(
        48, 'KP77SG0C26323520140909356184                70000000201809#'
    )  # 行业特定信息
    req_packet.FieldData(49, '156')  # 交易货币代码
    req_packet.FieldData(52, kw.get('PinBlock', None))  # 个人标识码数据
    req_packet.FieldData(53, '2600000000000000')  # 安全控制信息
    req_packet.FieldData(60, now.strftime('22%y%m%d00000060'))
    req_packet.FieldData(61, kw.get('Field61', None))  # 原始交易信息
    req_packet.FieldData(64, '0000000000000000')
    req_packet.FieldData(
        64, calc_mac_cbc(MAB=req_packet.BuildIso()[11:-8]))  # 报文鉴别码
    print("缴费撤销: ")
    req_packet.PrintMessage()
    data = req_packet.BuildIso()
    data = struct.pack('!H', len(data)) + data
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((HOST, PORT))
    py8583.MemDump("Sending: ", data)
    sock.send(data)
    data = sock.recv(4096)
    py8583.MemDump('Received: ', data)
    sock.close()
    parse_package(data)
Пример #3
0
def payment_reversal(**kw):
    """ 冲正交易 """
    req_packet = py8583.Iso8583(IsoSpec=py8583spec.IsoSpec1987BCD())
    req_packet.MTI('0400')
    req_packet.TPDU('6005810000')
    req_packet.HEADER('603100000000')
    req_packet.FieldData(3, '190000')  # 交易处理码
    req_packet.FieldData(4, kw.get('amount', '1').rjust(12, '0'))  # 交易金额
    req_packet.FieldData(11, kw.get('TraceNo', None))  # 原交易流水
    req_packet.FieldData(14, '2912')  # 卡有效期
    req_packet.FieldData(22, '051')  # 服务点输入方式
    req_packet.FieldData(23, kw.get('CardOrder', '000'))  # 卡序列号
    req_packet.FieldData(25, '81')  # 服务点条件码
    req_packet.FieldData(
        35, kw.get('Track2', '6212142000000000012=29122206899031006'))  # 二磁道数据
    req_packet.FieldData(36, kw.get('Track3', None))  # 三磁道数据
    req_packet.FieldData(38, kw.get('AuthNo', None))  # 原交易授权码
    req_packet.FieldData(39, '96')  # 冲正原因
    req_packet.FieldData(41, kw.get('TerminalNo', '52010009'))  # 终端代码
    req_packet.FieldData(42, kw.get('MerchantNo', '898520154110004'))  # 商户代码
    req_packet.FieldData(
        48,
        'KP77SG0C26323520140909356184                70000000201809#')  #行业特定信息
    req_packet.FieldData(49, '156')  # 交易货币代码
    req_packet.FieldData(55, kw.get('ICData', None))  # IC卡数据域
    req_packet.FieldData(60, kw.get('Field60', None))
    req_packet.FieldData(61, kw.get('Field61', None))  # 原始交易信息
    req_packet.FieldData(64, '0000000000000000')
    req_packet.FieldData(
        64, calc_mac_cbc(MAB=req_packet.BuildIso()[11:-8]))  # 报文鉴别码
    print("冲正交易: ")
    req_packet.PrintMessage()
    data = req_packet.BuildIso()
    data = struct.pack('!H', len(data)) + data
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((HOST, PORT))
    py8583.MemDump("Sending: ", data)
    sock.send(data)
    data = sock.recv(4096)
    py8583.MemDump('Received: ', data)
    sock.close()
    parse_package(data)
Пример #4
0
def balance_query(**kw):
    """ 账户余额查询 """
    now = datetime.now()
    req_packet = py8583.Iso8583(IsoSpec=py8583spec.IsoSpec1987BCD())
    req_packet.MTI('0200')
    req_packet.TPDU('6005810000')
    req_packet.HEADER('603100000000')
    req_packet.FieldData(2, kw.get('PAN', '6212142000000000012'))  # 主账号
    req_packet.FieldData(3, '300000')  # 交易处理码
    req_packet.FieldData(11, now.strftime('%H%M%S'))  # 终端交易流水
    req_packet.FieldData(14, '2912')  # 卡有效期
    req_packet.FieldData(22, '051')  # 服务点输入方式
    req_packet.FieldData(23, kw.get('CardOrder', '000'))  # 卡序列号
    req_packet.FieldData(25, '00')  # 服务点条件码
    req_packet.FieldData(26, '06')  # 服务点PIN获取码
    req_packet.FieldData(
        35, kw.get('Track2', '6212142000000000012=29122206899031006'))  # 二磁道数据
    req_packet.FieldData(36, kw.get('Track3', None))  # 三磁道数据
    req_packet.FieldData(41, kw.get('TerminalNo', '52010009'))  # 终端代码
    req_packet.FieldData(42, kw.get('MerchantNo', '898520154110004'))  # 商户代码
    req_packet.FieldData(49, '156')  # 交易货币代码
    req_packet.FieldData(52, kw.get('PinBlock', None))  # 个人标识码数据
    req_packet.FieldData(53, '2600000000000000')  # 安全控制信息
    req_packet.FieldData(55, kw.get('ICData', None))  # IC卡数据域
    req_packet.FieldData(60, now.strftime('01%y%m%d00000060'))
    req_packet.FieldData(64, '0000000000000000')
    req_packet.FieldData(
        64, calc_mac_cbc(MAB=req_packet.BuildIso()[11:-8]))  # 报文鉴别码
    print("账户余额查询:")
    req_packet.PrintMessage()
    data = req_packet.BuildIso()
    data = struct.pack('!H', len(data)) + data
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((HOST, PORT))
    py8583.MemDump("Sending: ", data)
    sock.send(data)
    data = sock.recv(4096)
    py8583.MemDump('Received: ', data)
    sock.close()
    parse_package(data)
Пример #5
0
def terminal_checkin(**kw):
    """ 设备终端签到 """
    now = datetime.now()
    req_packet = py8583.Iso8583(IsoSpec=py8583spec.IsoSpec1987BCD())
    req_packet.MTI('0800')
    req_packet.TPDU('6005810000')
    req_packet.HEADER('603100000000')
    req_packet.FieldData(11, int(now.strftime('%H%M%S')))  # 终端流水
    req_packet.FieldData(41, kw.get('TerminalNo', '52010009'))  # 终端代码
    req_packet.FieldData(42, kw.get('MerchantNo', '898520154110004'))  # 商户代码
    req_packet.FieldData(60, now.strftime('00%y%m%d003'))
    print("设备终端签到:")
    req_packet.PrintMessage()
    data = req_packet.BuildIso()
    data = struct.pack('!H', len(data)) + data
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((HOST, PORT))
    py8583.MemDump("Sending: ", data)
    sock.send(data)
    data = sock.recv(4096)
    py8583.MemDump('Received: ', data)
    sock.close()
    parse_package(data)