Exemplo n.º 1
0
 def post(self):
     apis = HttpApi.apis()
     if self.api_name not in apis:
         raise HttpError(400, "INVALID_APINAME", "%s Not Found" % self.api_name)
     api_func = apis[self.api_name]
     logger.info("[request] api_name: %s, device_id: %s, client_ip: %s, called_func: %s",
                 self.api_name, self.device_id, self.client_ip, api_func.__name__)
     return api_func(self)
Exemplo n.º 2
0
def finishSupply(handler):
    body = handler.body
    device_id = handler.device_id

    with RPCClient() as rpc:
        data = rpc.invbox.finish_supply(device_id, body["no"])

    if data["resultCode"]:
        raise HttpError(400, "SUPPLY_FAIL", data["resultMsg"])
    return handler.write_json({})
Exemplo n.º 3
0
def write_client_log(handler):
    device_id = handler.device_id
    body = handler.body

    if "type" not in body or "data" not in body:
        raise HttpError(400, "LACK_PARAM", "缺少参数")
    stype = body["type"]
    data = body["data"]

    logger.info('[client] "%s" "%s" "%s"' % (device_id, stype, data))
    return handler.write_json({})
Exemplo n.º 4
0
    def prepare(self):
        try:
            data = json.loads(self.request.body)
        except:
            raise HttpError(400, "INVALID_JSON", "json格式错误")

        if "header" not in data or "body" not in data:
            raise HttpError(400, "INVALID_PARAMS", "缺少header或body字段")

        self.header = data["header"]
        self.body = data["body"]
        if "apiName" not in self.header or "deviceId" not in self.header:
            raise HttpError(400, "INVALID_PARAMS", "缺少apiName或devcieId字段")

        x_real_ip = self.request.headers.get("X-Real-IP")
        remote_ip = x_real_ip or self.request.remote_ip

        self.api_name = self.header["apiName"]
        self.device_id = self.header["deviceId"]
        self.client_ip = remote_ip
Exemplo n.º 5
0
def get_permission(handler):
    body = handler.body
    token = body.get("token", "")

    mappings = {
        "buhuo2018": "suppler",
        "yhfxfh2018": "admin"
    }

    if token not in mappings:
        raise HttpError(400, "INVALID_TOKEN", "无效token")

    return handler.write_json({"role": mappings[token]})
Exemplo n.º 6
0
def exchange_item(handler):
    "兑换商品"
    body = handler.body
    stype = body.get("type", "")

    if stype not in ["redeem", "voiceCode"]:
        raise HttpError(400, "PARAM_ERROR", "type字段取值错误")

    if stype == "voiceCode" and "user_id" not in body:
        raise HttpError(400, "PARAM_ERROR", "缺少user_id字段")

    with RPCClient() as rpc:
        if stype == "redeem":
            res = rpc.invbox.exchange_item_by_redeem(handler.device_id,
                                                     body["code"])
        else:
            user_id = body["user_id"]
            res = rpc.invbox.exchange_item_by_voice(handler.device_id,
                                                    body["code"],
                                                    user_id)
    if res["resultCode"]:
        raise HttpError(400, "FAIL", res["resultMsg"])
    return handler.write_json(res)
Exemplo n.º 7
0
def get_order(handler):
    body = handler.body

    with RPCClient() as rpc:
        order_info = rpc.invbox.get_order_detail(body["orderNo"])
        if not order_info:
            raise HttpError(400, "NOT_FUNCD_ORDER", "未找到订单信息")

    data = {
        "orderNo": order_info["orderNo"],
        "deviceBoxNo": order_info["roadNo"],
        "itemAmount": order_info["itemAmount"],
        "item": order_info["item"],
        "payMoney": order_info["payMoney"],
        "orderStatus": order_info["status"],
        "payAt": order_info["payAt"],
        "payType": order_info["payType"] or 0,
    }

    return handler.write_json(data)