Exemple #1
0
 def etc_deduct_notify(parkCode, outTradeNo, derateFee, payFee, payTime):
     """
     etc扣费下发通知
     :return:
     """
     etc_deduct_notify_data = {
         "flag": True,
         "data": {
             "parkCode": parkCode,
             "outTradeNo": outTradeNo,
             "derateFee": derateFee,
             "payFee": payFee,
             "payTime": payTime
         }
     }
     print('etc扣费下发请求')
     print(etc_deduct_notify_data)
     etc_deduct_notify_url = CommonConf.ETC_CONF_DICT['thirdApi'][
         'etc_deduct_notify_url']
     try:
         res = http_session.post(etc_deduct_notify_url,
                                 json=etc_deduct_notify_data)
         result = res.json()['result']
         logger.info('抬杆状态: {}'.format(result))
         if result == 'success':
             return True
     except:
         logger.error(traceback.format_exc())
     return False
Exemple #2
0
 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
Exemple #3
0
 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)
Exemple #4
0
    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
Exemple #6
0
 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
Exemple #8
0
def etc_toll_by_thread(body: OBUModel):
    time.sleep(2)
    # TODO 进行到此步骤,表示etc扣费成功,调用强哥接口
    payTime = CommonUtil.timestamp_format(int(time.time()), format='%Y-%m-%d %H:%M:%S')
    etc_deduct_notify_data = {
        "flag": True,
        "data": {
            "parkCode": body.park_code,
            "outTradeNo": body.trans_order_no,
            "derateFee": body.discount_amount,
            "payFee": body.deduct_amount,
            "payTime": payTime
        }
    }
    logger.info('etc扣费下发请求:')
    logger.info(json.dumps(etc_deduct_notify_data, ensure_ascii=False))
    etc_deduct_notify_url = 'http://z250h48353.zicp.vip:80/park/etcPayDetail'
    try:
        res = http_session.post(etc_deduct_notify_url, json=etc_deduct_notify_data)
        logger.info(res.json())
        result = res.json()['result']
        if result == 'success':
            return True
    except:
        logger.error(traceback.format_exc())
    return False
 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_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
Exemple #11
0
 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())
Exemple #13
0
 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())