示例#1
0
 def delete(self):
     """
     删除征信配置
     """
     self.reqparse.add_argument("interface",
                                type=str,
                                required=True,
                                location=['json', 'args'],
                                code=1014010001,
                                desc="接口编号")
     self.reqparse.add_argument("operator_id",
                                type=str,
                                location=['json', 'args'],
                                required=True,
                                code=1014010001,
                                desc="操作人ID")
     raw_args_dict = self.reqparse.parse_args(strict=True)
     if not CreditConf.objects(interface=raw_args_dict["interface"],
                               is_delete=0).count() == 1:
         return 1014010004  # 接口编码错误
     try:
         de_data = CreditConf.objects(interface=raw_args_dict["interface"],
                                      is_delete=0)
         de_data.update(set__is_delete=int(1))
         msg = self.create_log_msg(operator_id=raw_args_dict["operator_id"],
                                   interface=raw_args_dict["interface"],
                                   data=json.dumps(raw_args_dict,
                                                   ensure_ascii=False),
                                   status="SUCCESS")
         self.operator_log(operator_id=raw_args_dict["operator_id"],
                           log_data=msg,
                           method="DELETE")
         logger.info(msg)
         return 0
     except Exception as e:
         msg = self.create_log_msg(operator_id=raw_args_dict["operator_id"],
                                   interface=raw_args_dict["interface"],
                                   data=json.dumps(raw_args_dict,
                                                   ensure_ascii=False),
                                   status="FAILED")
         self.operator_log(operator_id=raw_args_dict["operator_id"],
                           log_data=msg,
                           method="DELETE")
         logger.error(msg)
         return 1014020001  # 数据格式错误
示例#2
0
 def trans_task(self, trx, operator, operator_id):
     """
     处理事务重做的具体逻辑
     """
     try:
         trans = self.get_schedbin_message(trx)
         if not trans:
             logger.info("Query failed, trx: {}".format(trx))
             return False
         resp = requests.post(schedu_redo_url, json=trans, timeout=15)
         if not (resp.status_code == 200 and resp.json()["code"] == 0):
             logger.warning("response trx: {} status: {} result {}".format(
                 trx, resp.status_code, resp.text))
             return False
         logger.info("Request success. trx: {}.".format(trx))
         return True
     except Exception as e:
         logger.error("Redo faild.trx: [{}]. error: {}".format(trx, e))
         return False
     return True
示例#3
0
文件: sms.py 项目: GSIL-Monitor/xxw
def verify_code(phone: str, verify_type: int, verify_code: str):
    """
    短信验证
    phone:验证手机号
    verify_type: 动码类型
    verify_code:验证码
    """
    url = "/msg/verification/run_verify_code"
    try:
        payload = {"phone": phone, "type": verify_type, "verify_code": verify_code}
        headers = {"content-type": "application/json"}
        res = requests.post(host + url, data=json.dumps(payload), headers=headers).json()
        if res["code"] != 0:
            logger.info("verify_code fail: {}".format(res))
            return False
        return True
    except Exception as e:
        import traceback
        logger.error("verify_code error {}".format(traceback.format_exc()))
        return False
示例#4
0
 def put(self):
     """
     更新征信配置
     """
     self.reqparse.add_argument("interface",
                                type=str,
                                required=True,
                                location=['json', 'args'],
                                code=1014010001,
                                desc="接口编号")
     self.reqparse.add_argument("operator_id",
                                type=str,
                                location=['json', 'args'],
                                required=True,
                                code=1014010001,
                                desc="操作人ID")
     self.reqparse.add_argument("supplier",
                                type=str,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="接口供应商")
     self.reqparse.add_argument("product",
                                type=str,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="产品名称")
     self.reqparse.add_argument("type",
                                type=str,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="接口类型")
     self.reqparse.add_argument("desc",
                                type=str,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="接口描述")
     self.reqparse.add_argument("secret_key",
                                type=str,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="安全码")
     self.reqparse.add_argument("url",
                                type=str,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="接口api")
     self.reqparse.add_argument("retry",
                                type=int,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="重试次数")
     self.reqparse.add_argument("method",
                                type=str,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="请求方式")
     self.reqparse.add_argument("headers",
                                type=dict,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="请求头参数字典")
     self.reqparse.add_argument("auth_info",
                                type=dict,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="接口认证信息")
     self.reqparse.add_argument("account_config",
                                type=dict,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="人行账号配置")
     self.reqparse.add_argument("rate_limit",
                                type=dict,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="限速配置字典")
     self.reqparse.add_argument("timeout",
                                type=int,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="超时时间")
     self.reqparse.add_argument("expire",
                                type=int,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="缓存过期时间")
     self.reqparse.add_argument("status",
                                type=int,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="接口状态")
     self.reqparse.add_argument("sys_params",
                                type=dict,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="系统参数字典")
     self.reqparse.add_argument("user_params",
                                type=dict,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="用户参数字典")
     self.reqparse.add_argument("input_params",
                                type=dict,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="请求参数字典")
     self.reqparse.add_argument("success_code_dict",
                                type=dict,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="成功状态码字典")
     self.reqparse.add_argument("retry_code_dict",
                                type=dict,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="失败重试状态码字典")
     self.reqparse.add_argument("failed_code_dict",
                                type=dict,
                                location=['json', 'args'],
                                code=1014010002,
                                desc="失败状态码字典")
     raw_args_dict = self.reqparse.parse_args(strict=True)
     if not CreditConf.objects(interface=raw_args_dict["interface"],
                               is_delete=0).count() == 1:
         return 1014010004  # 接口编码错误
     up_data = CreditConf.objects.filter(
         interface=raw_args_dict["interface"])[0]
     raw_args_dict["update_time"] = utc_timestamp()
     try:
         for k, v in raw_args_dict.items():
             if k not in ["operator_id"]:
                 setattr(up_data, k, v or None)
         up_data.save()
         msg = self.create_log_msg(operator_id=raw_args_dict["operator_id"],
                                   interface=raw_args_dict["interface"],
                                   data=json.dumps(raw_args_dict,
                                                   ensure_ascii=False),
                                   status="SUCCESS")
         self.operator_log(operator_id=raw_args_dict["operator_id"],
                           log_data=msg,
                           method="PUT")
         logger.info(msg)
         return 0
     except Exception as e:
         msg = self.create_log_msg(operator_id=raw_args_dict["operator_id"],
                                   interface=raw_args_dict["interface"],
                                   data=json.dumps(raw_args_dict,
                                                   ensure_ascii=False),
                                   status="FAILED")
         self.operator_log(operator_id=raw_args_dict["operator_id"],
                           log_data=msg,
                           method="PUT")
         logger.error(msg)
         return 1014020001  # 数据格式错误
示例#5
0
def catch_error(error):
    traceback.print_exc()
    logger.error(request.data)
    return jsonify({"code": -1, "msg": "服务器内部错误", "data": {}}), 200