def etc_deduct_upload(etc_deduct_info_json): """ etc支付上传 :trans_order_no: 订单号 :etc_deduct_info_json: 待上传的数据 :add_to_db: 是否入库 :return: """ # # 如果上传成功upload_flag=1, 上传失败upload_flag=0, 默认上传失败 upload_flag = 0 # 业务编码报文 # 将data 值base64 后,使用SHA256WithRSA 计算签名 sign = XlapiSignature.to_sign_with_private_key( etc_deduct_info_json, private_key=ThirdEtcApi.PRIVATE_KEY) upload_body = dict(appid=ThirdEtcApi.APPID, data=etc_deduct_info_json, sign=sign.decode(encoding='utf8')) # print('+' * 30) logger.info('上传etc扣费数据: {}'.format(etc_deduct_info_json)) try: res = http_session.post(ThirdEtcApi.ETC_UPLOAD_URL, data=upload_body) if res.json()['code'] == '000000': upload_flag = 1 logger.info(res.json()) except: logger.error(traceback.format_exc()) upload_fail_count = 0 if upload_flag else 1 return upload_flag, upload_fail_count
def download_blacklist_incre(): """ 下载增量黑名单, 定时每隔一小时跑一次 :return: """ data_dict = { "method": "getBlackListFile", "params": { "last_file_name": "", "version": "", "para_code": "65" } } data_json = json.dumps(data_dict, ensure_ascii=False) sign = XlapiSignature.to_sign_with_private_key( data_json, private_key=ThirdEtcApi.PRIVATE_KEY) upload_body = dict(appid=ThirdEtcApi.APPID, data=data_json, sign=sign.decode(encoding='utf8')) res = http_session.post(ThirdEtcApi.ETC_UPLOAD_URL, data=upload_body) res_json = res.json() logger.info('下载增量黑名单: {}'.format(res_json)) file_url = res_json['data']['file_url'] new_version = res_json['data']['new_version'] para_code = res_json['data']['para_code'] file_name = res_json['data']['file_name'] file_path = os.path.join(CommonConf.SQLITE_DIR, file_name) # 下载文件 CommonUtil.download_file(url=file_url, file_path=file_path) # 解压下载的zip文件 CommonUtil.unzipfile(src_file=file_path, dest_dir=CommonConf.SQLITE_DIR)
def tianxian_heartbeat(params): """ 天线心跳 :return: """ data_dict = {"method": "heartbeat", "params": params} data_json = json.dumps(data_dict, ensure_ascii=False) logger.info('上传天线心跳状态:{}'.format(data_json)) sign = XlapiSignature.to_sign_with_private_key( data_json, private_key=ThirdEtcApi.PRIVATE_KEY) upload_body = dict(appid=ThirdEtcApi.APPID, data=data_json, sign=sign.decode(encoding='utf8')) res = http_session.post(ThirdEtcApi.ETC_UPLOAD_URL, data=upload_body) command = res.json()['command'] # 查询天线的计费状态,charge=1开启计费,charge=0关闭计费 rsu_charge = DBRsuCharge.query_rsu_charge() # 00:暂停收费 # 11:正常收费(默认) if command == '00': logger.info('暂停etc收费') if rsu_charge == 1: DBRsuCharge.update_rsu_charge_on_off( charge=0, update_time=datetime.now()) else: if rsu_charge == 0: logger.info('开启etc收费') DBRsuCharge.update_rsu_charge_on_off( charge=1, update_time=datetime.now())
def upload_wugan(trans_order_no, park_code, plate_no, plate_color_code, plate_type_code, entrance_time, park_record_time, exit_time, device_no, deduct_amount): entrance_time = CommonUtil.timestamp_format(entrance_time, format='%Y%m%d%H%M%S') exit_time = CommonUtil.timestamp_format(exit_time, format='%Y%m%d%H%M%S') data_dict = { "method": "whitePay", "params": { "trans_order_no": trans_order_no, "park_code": park_code, "plate_no": plate_no, "plate_color_code": plate_color_code, "plate_type_code": plate_type_code, "entrance_time": entrance_time, "park_record_time": park_record_time, "exit_time": exit_time, "device_no": device_no, "deduct_amount": deduct_amount } } data_json = json.dumps(data_dict, ensure_ascii=False) logger.info('无感支付上传: {}'.format(data_json)) sign = XlapiSignature.to_sign_with_private_key(data_json, private_key=ThirdEtcApi.PRIVATE_KEY) upload_body = dict(appid=ThirdEtcApi.APPID, data=data_json, sign=sign.decode(encoding='utf8')) res = http_session.post(ThirdEtcApi.ETC_UPLOAD_URL, data=upload_body) # ('http://58.59.49.122:8810/api/gateway/etc', data=upload_body) # res_json = res.json() code, message = res_json['code'], res_json['message'] logger.info('无感支付上传: code: {}, message: {}'.format(code, message)) return code, message
def exists_in_blacklist(issuer_identifier, card_net, card_id): """ 通过第三方接口查询card_net+card_sn是否在黑名单中 :param issuer_identifier 发行商代码 :param card_net: card网络编号 :param card_id: card id :return: """ data_dict = { "method": "blacklist", "params": { "issuer_identifier": issuer_identifier, "card_net": str(card_net), "card_sn": card_id } } data_json = json.dumps(data_dict, ensure_ascii=False) sign = XlapiSignature.to_sign_with_private_key( data_json, private_key=ThirdEtcApi.PRIVATE_KEY) upload_body = dict(appid=ThirdEtcApi.APPID, data=data_json, sign=sign.decode(encoding='utf8')) try: res = http_session.post(ThirdEtcApi.ETC_UPLOAD_URL, data=upload_body) res_json = res.json() status = res_json['data']['status'] exist_flag = True if str(status) == '1' else False except: logger.error('查询黑名单时出现异常: '.format(traceback.format_exc())) exist_flag = True return exist_flag
def upload_vehicle_plate_no(park_code, plate_no, plate_color): """ 上传车辆信息 @param vehicle_info_json: @return: """ params = dict(park_code=park_code, plate_no=plate_no, plate_color_code=str(int(plate_color, 16)), record_time=CommonUtil.timestamp_format( int(time.time()), format='%Y%m%d%H%M%S')) vehicle_info_dict = dict(method='passThrough', params=params) vehicle_info_json = json.dumps(vehicle_info_dict, ensure_ascii=False) # # 如果上传成功upload_flag=1, 上传失败upload_flag=0, 默认上传失败 upload_flag = 0 # 业务编码报文 # 将data 值base64 后,使用SHA256WithRSA 计算签名 sign = XlapiSignature.to_sign_with_private_key( vehicle_info_json, private_key=ThirdEtcApi.PRIVATE_KEY) upload_body = dict(appid=ThirdEtcApi.APPID, data=vehicle_info_json, sign=sign.decode(encoding='utf8')) logger.info('上传车辆信息: {}'.format(vehicle_info_json)) try: res = http_session.post(ThirdEtcApi.ETC_UPLOAD_URL, data=upload_body) if res.json()['code'] == '000000': upload_flag = 1 logger.info(res.json()) except: logger.error(traceback.format_exc()) upload_fail_count = 0 if upload_flag else 1 return upload_flag, upload_fail_count
def reupload_vehicle_plate(): # 查询过去一天上传失败的 query_items = db_session.query(VehicleInfoOrm).filter( and_( VehicleInfoOrm.create_time > (datetime.now() - timedelta(days=2)), VehicleInfoOrm.upload_flag == 0)) for item in query_items: vehicle_info_json = item.vehicle_info # 将data 值base64 后,使用SHA256WithRSA 计算签名 sign = XlapiSignature.to_sign_with_private_key( vehicle_info_json, private_key=ThirdEtcApi.PRIVATE_KEY) upload_body = dict(appid=ThirdEtcApi.APPID, data=vehicle_info_json, sign=sign.decode(encoding='utf8')) logger.info('上传车辆信息: {}'.format(vehicle_info_json)) try: res = http_session.post(ThirdEtcApi.ETC_UPLOAD_URL, data=upload_body) if res.json()['code'] == '000000': db_session.delete(item) else: item.upload_fail_count += 1 except: item.upload_fail_count += 1 logger.error(traceback.format_exc()) # 数据修改好后提交 try: db_session.commit() except: db_session.rollback() logger.error(traceback.format_exc())
def upload_etc_fee_deduction(body: OBUModel2): """ 上传etc扣费信息 :param body: :return: """ logger.info('===============接收etc扣费上传请求===============') logger.info(body.json(ensure_ascii=False)) params = json.loads(body.json()) sign_combine = 'card_net_no:{},card_serial_no:{},card_sn:{},card_type:{},exit_time:{},obu_id:{},park_code:{},' \ 'plate_no:{},tac:{}'. format(body.card_net_no, body.card_serial_no, body.card_sn, body.card_type, body.exit_time, body.obu_id, body.park_code, body.plate_no, body.tac) print(sign_combine) sign = XlapiSignature.to_sign_with_private_key( text=sign_combine, private_key=CommonConf.ETC_CONF_DICT['thirdApi'] ['private_key']).decode(encoding='utf8') print(sign) etc_deduct_info_dict = {"method": "etcPayUpload", "params": params} result = dict(flag=True, errorCode='', errorMessage='', data=None) upload_flag = True if body.obu_id != '0' else False if not upload_flag: result['flag'] = False result['errorCode'] = '1' result['errorMessage'] = 'etc扣费上传失败' return result
def upload_vehicle_plate_no(park_code, plate_no, plate_color): """ 上传车辆信息 @param vehicle_info_json: @return: """ params = dict(park_code=park_code, plate_no=plate_no, plate_color_code=str(int(plate_color, 16)), record_time=CommonUtil.timestamp_format( int(time.time()), format='%Y%m%d%H%M%S')) vehicle_info_dict = dict(method='passThrough', params=params) vehicle_info_json = json.dumps(vehicle_info_dict, ensure_ascii=False) # # 如果上传成功upload_flag=1, 上传失败upload_flag=0, 默认上传失败 upload_flag = 0 # 业务编码报文 # 将data 值base64 后,使用SHA256WithRSA 计算签名 sign = XlapiSignature.to_sign_with_private_key( vehicle_info_json, private_key=ThirdEtcApi.PRIVATE_KEY) upload_body = dict(appid=ThirdEtcApi.APPID, data=vehicle_info_json, sign=sign.decode(encoding='utf8')) logger.info('上传车辆信息: {}'.format(vehicle_info_json)) try: res = http_session.post(ThirdEtcApi.ETC_UPLOAD_URL, data=upload_body) if res.json()['code'] == '000000': upload_flag = 1 logger.info(res.json()) except: logger.error(traceback.format_exc()) upload_fail_count = 0 if upload_flag else 1 if not upload_flag: db_engine, db_session = create_db_session( sqlite_dir=CommonConf.SQLITE_DIR, sqlite_database='etc_deduct.sqlite') # etc_deduct_info_json入库 DBClient.add(db_session=db_session, orm=VehicleInfoOrm( id=CommonUtil.random_str(32).lower(), vehicle_info=vehicle_info_json, upload_flag=upload_flag, upload_fail_count=upload_fail_count)) db_session.close() db_engine.dispose() return upload_flag, upload_fail_count
def upload_etc_fee_deduction(body: OBUModel2): """ 上传etc扣费信息 :param body: :return: """ logger.info('===============接收etc扣费上传请求===============') logger.info(body.json(ensure_ascii=False)) params = json.loads(body.json()) sign_combine = 'card_net_no:{},card_serial_no:{},card_sn:{},card_type:{},exit_time:{},obu_id:{},park_code:{},' \ 'plate_no:{},tac:{}'. format(body.card_net_no, body.card_serial_no, body.card_sn, body.card_type, body.exit_time, body.obu_id, body.park_code, body.plate_no, body.tac) print(sign_combine) sign = XlapiSignature.to_sign_with_private_key( text=sign_combine, private_key=CommonConf.ETC_CONF_DICT['thirdApi']['private_key']).decode(encoding='utf8') print(sign) etc_deduct_info_dict = {"method": "etcPayUpload", "params": params} # 业务编码报文json格式 # etc_deduct_info_json = json.dumps(etc_deduct_info_dict, ensure_ascii=False) # # 上传etc扣费数据 # upload_flag, upload_fail_count = ThirdEtcApi.etc_deduct_upload(etc_deduct_info_json) # db_engine, db_session = create_db_session(sqlite_dir=CommonConf.SQLITE_DIR, # sqlite_database='etc_deduct.sqlite') # # etc_deduct_info_json入库 # DBClient.add(db_session=db_session, # orm=ETCFeeDeductInfoOrm(id=CommonUtil.random_str(32).lower(), # trans_order_no=body.trans_order_no, # etc_info=etc_deduct_info_json, # upload_flag=upload_flag, # upload_fail_count=upload_fail_count)) # db_session.close() # db_engine.dispose() result = dict(flag=True, errorCode='', errorMessage='', data=None) upload_flag = True if body.obu_id != '0' else False if not upload_flag: result['flag'] = False result['errorCode'] = '1' result['errorMessage'] = 'etc扣费上传失败' return result
def white_status(park_code, plate_no, plate_color_code): data_dict = { "method": "whiteCheck", "params": { "park_code": park_code, "plate_no": plate_no, "plate_color_code": plate_color_code } } data_json = json.dumps(data_dict, ensure_ascii=False) sign = XlapiSignature.to_sign_with_private_key(data_json, private_key=ThirdEtcApi.PRIVATE_KEY) upload_body = dict(appid=ThirdEtcApi.APPID, data=data_json, sign=sign.decode(encoding='utf8')) res = http_session.post(ThirdEtcApi.ETC_UPLOAD_URL, data=upload_body) # ('http://58.59.49.122:8810/api/gateway/etc', data=upload_body) # res_json = res.json() logger.info('查询白名单: data: {}, res: {}'.format(data_json, json.dumps(res_json, ensure_ascii=False))) white_status = res_json['data']['status'] return white_status
def query_owe_history(): """查询欠费历史""" method_name = 'queryArrearageOrderInfoNoPic.do' data = dict(plateNo='川YP37431', plateType='7201') data = json.dumps(data, ensure_ascii=False) current_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) print(method_name, current_time, data) sign_value = method_name + current_time + ThirdEtcApi.APPID + data sign = XlapiSignature.to_sign_with_private_key( sign_value, private_key=ThirdEtcApi.PRIVATE_KEY) body = dict(t=current_time, appid=ThirdEtcApi.APPID, data=data, sign=sign) res = http_session.post( url= 'http://58.59.49.122:10001/vvpos/api/vpos/queryArrearageOrderInfoNoPic.do', data=body) # http://lnetc1.c2s.pub:6868 http://58.59.49.122:8810 print(res.json())
def download_fxf_blacklist(): """ 发行方黑名单接口 """ params = { "params_code": "1001", "park_code": CommonConf.ETC_CONF_DICT['etc'][0]['park_code'], } data_dict = {"method": "platformParams", "params": params} data_json = json.dumps(data_dict, ensure_ascii=False) logger.info('平台参数下载-发行方黑名单接口:{}'.format(data_json)) sign = XlapiSignature.to_sign_with_private_key( data_json, private_key=ThirdEtcApi.PRIVATE_KEY) upload_body = dict(appid=ThirdEtcApi.APPID, data=data_json, sign=sign.decode(encoding='utf8')) res_json = http_session.post(ThirdEtcApi.ETC_UPLOAD_URL, data=upload_body).json() if res_json['code'] == '000000': fxf_blacklist = res_json['data']['params_list'] with open(os.path.join(CommonConf.SQLITE_DIR, 'fxf_blacklist.pkl'), 'wb') as fw: pickle.dump(fxf_blacklist, fw)
def tianxian_heartbeat(params): """ 天线心跳 :return: """ data_dict = {"method": "heartbeat", "params": params} data_json = json.dumps(data_dict, ensure_ascii=False) logger.info('上传天线心跳状态:{}'.format(data_json)) sign = XlapiSignature.to_sign_with_private_key( data_json, private_key=ThirdEtcApi.PRIVATE_KEY) upload_body = dict(appid=ThirdEtcApi.APPID, data=data_json, sign=sign.decode(encoding='utf8')) res = http_session.post(ThirdEtcApi.ETC_UPLOAD_URL, data=upload_body) command = res.json()['command'] # 00:暂停收费 # 11:正常收费(默认) if command == '00': CommonConf.ETC_CONF_PATH = False logger.info('暂停收费') elif (command is None) or (command == '11'): CommonConf.ETC_CONF_PATH = True logger.info(res.json())
"psam_serial_no": "000026EC", "receivable_total_amount": 0, "serial_number": "3701071521078758", "tac": "CC688326", "terminal_id": "0137000482B2", "trans_before_balance": 43070, "trans_order_no": "1818620411622008756", "trans_type": "09", "vehicle_type": "1" } } # app_id app_id = CommonConf.ETC_CONF_DICT['thirdApi']['app_id'] # 私钥 private_key = CommonConf.ETC_CONF_DICT['thirdApi']['private_key'] # 业务编码报文 etc_deduct_info_json = json.dumps(etc_deduct_info_dict, ensure_ascii=False) # 将data 值base64 后,使用SHA256WithRSA 计算签名 sign = XlapiSignature.to_sign_with_private_key(etc_deduct_info_json, private_key=private_key) upload_body = dict(appid=app_id, data=etc_deduct_info_json, sign=sign.decode(encoding='utf8')) print('*' * 50) print(json.dumps(upload_body, ensure_ascii=False)) # pprint(upload_body) # pprint(json.dumps(upload_body, ensure_ascii=False)) res = requests.post(url='http://58.59.49.122:8810/api/gateway/etc', data=upload_body) print(res.json())