示例#1
0
    def post(self, *args, **kwargs):
        gen_log.info("alipay post")
        order_id = self.get_argument("order_id", "")
        # 创建用于进行支付宝支付的工具对象
        alipay = AliPay(
            appid=default_settings.get('app_id', ''),
            app_notify_url=None,  # 默认回调url
            app_private_key_path=os.path.join(os.path.dirname(__file__),
                                              "pem/pkcs8_private.pem"),
            alipay_public_key_path=os.path.join(os.path.dirname(__file__),
                                                "pem/alipay_public.pem"),
            # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            sign_type="RSA2",  # RSA 或者 RSA2
            debug=True  # 默认False  配合沙箱模式使用
        )

        # 电脑网站支付,需要跳转到https://openapi.alipay.com/gateway.do? + order_string
        order_string = alipay.api_alipay_trade_page_pay(
            out_trade_no=order_id,
            total_amount=str(0.01),  # 将Decimal类型转换为字符串交给支付宝
            subject="云计算web个人",
            return_url=None,
            notify_url=None  # 可选, 不填则使用默认notify url
        )

        # 让用户进行支付的支付宝页面网址
        url = default_settings.get("alipay_url", "") + "?" + order_string

        return self.finish({"code": 0, "message": "请求支付成功", "url": url})
示例#2
0
def get_pu(ip="", html="", start="", end=""):
    try:
        session = get_session()
        # verify date
        if start and not is_date(start):
            gen_log.info("start format error:%s, %s"%(start, type(start)))
            return []
        if end and not is_date(end):
            gen_log.info("end format error:%s, %s" % (end, type(start)))
            return []
        query = api.get_pu_count(session, ip, html, start, end)
        results = query.all()
        _ = []
        for result in results:
            _.append({
                "ip": result.ip,
                "html": result.html,
                "count": int(result[2])
            })
        return _
    except Exception as ex:
        gen_log.error("pu query error:%r"%ex)
        return []
    finally:
        session.close()
示例#3
0
 def __(torn_self):
     user_name = torn_self.get_secure_cookie('user_name')
     user_level = torn_self.get_secure_cookie('user_level')
     gen_log.info("entry:%s,%s" % (user_name, user_level))
     if not user_name or user_level == "1":
         torn_self.redirect('/')
         return
     func(torn_self)
示例#4
0
    def put(self):
        """"add product"""
        upload_path = os.path.abspath(os.path.dirname(__file__)+os.path.sep+"..")
        upload_path = os.path.join(upload_path, 'static')
        file_metas = self.request.files.get('product_img', '')

        # save img
        img_path = ""
        product_name = self.get_argument("product_name", "")
        theme = self.get_argument("theme", '')
        gen_log.info('add product name:%s'%product_name)
        if not product_name:
            self.finish({'state': '3', 'message': 'Product name is none', 'error': 'Product name is none'})
            return
        if not theme:
            self.finish({'state': '4', 'message': 'Product theme is none', 'error': 'Product theme is none'})
            return
        for meta in file_metas:
            filename = meta['filename']
            filename = product_name + "_" +str(int(time.time())) + "." + filename.rpartition(".")[-1] #rename img meta
            #content_type = meta['content_type']
            img_path = os.path.join("product_img", filename)
            filepath = os.path.join(upload_path, img_path)
            with open(filepath, 'wb') as up:
                up.write(meta['body'])
        if not img_path:
            self.finish({'state': '1', 'message': 'img is none', 'error': 'img is none'})
            return
        data = {
            "name": product_name,
            "source": self.get_argument("source", ''),
            "theme": theme,
            "ori_price": float(self.get_argument("ori_price", 0)),
            "con_price": float(self.get_argument("con_price", 0)),
            "postage_price": float(self.get_argument("postage_price", 0)),
            "description": self.get_argument("description", ""),
            "links": self.get_argument("links", ""),
            "sort_num": int(self.get_argument("sort_num", 10000)),
            "img_path": img_path,
            "recommend": int(self.get_argument("recommend", 0)),
        }

        _ = loc_product.add_product(data)
        if not _:
            self.finish({'state': '2', 'message': 'product exit', 'error': 'product exit'})
            return

        self.finish({'state': '0', 'message': 'add product ok'})
示例#5
0
    def post(self):
        notify_time = self.get_argument("notify_time", "")
        notify_type = self.get_argument("notify_type", "")
        notify_id = self.get_argument("notify_id", "")
        charset = self.get_argument("charset", "")
        version = self.get_argument("version", "")
        sign_type = self.get_argument("sign_type", "")
        sign = self.get_argument("sign", "")
        auth_app_id = self.get_argument("auth_app_id", "")
        trade_no = self.get_argument("trade_no", "")

        gen_log.info("alipay call")
        gen_log.info("params: %s,%s,%s,%s,%s,%s,%s,%s,%s" %
                     (notify_time, notify_type, notify_id, charset, version,
                      sign_type, sign, auth_app_id, trade_no))

        self.finish(json.dumps({'state': 0, 'message': 'ok'}))
示例#6
0
    def get(self, *args, **kwargs):
        # 创建用于进行支付宝支付的工具对象
        gen_log.info(
            "check alipay get:%s" %
            os.path.join(os.path.dirname(__file__), "pem/pkcs8_private.pem"))
        order_id = self.get_argument("order_id", "")
        alipay = AliPay(
            appid=default_settings.get("app_id", ""),
            app_notify_url=None,  # 默认回调url
            app_private_key_path=os.path.join(os.path.dirname(__file__),
                                              "pem/pkcs8_private.pem"),
            alipay_public_key_path=os.path.join(os.path.dirname(__file__),
                                                "pem/alipay_public.pem"),
            # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            sign_type="RSA2",  # RSA2,官方推荐,配置公钥的时候能看到
            debug=True  # 默认False  配合沙箱模式使用
        )

        while True:
            # 调用alipay工具查询支付结果
            response = alipay.api_alipay_trade_query(order_id)  # response是一个字典
            # 判断支付结果
            code = response.get("code")  # 支付宝接口调用成功或者错误的标志
            trade_status = response.get("trade_status")  # 用户支付的情况

            if code == "10000" and trade_status == "TRADE_SUCCESS":
                # 表示用户支付成功
                # 返回前端json,通知支付成功
                return self.finish({"code": 0, "message": "支付成功"})

            elif code == "40004" or (code == "10000"
                                     and trade_status == "WAIT_BUYER_PAY"):
                # 表示支付宝接口调用暂时失败,(支付宝的支付订单还未生成) 后者 等待用户支付
                # 继续查询
                print(code)
                print(trade_status)
                continue
            else:
                # 支付失败
                # 返回支付失败的通知
                return self.finish({"code": 1, "message": "支付失败"})
示例#7
0
def get_creating_user(**kwargs):
    email = kwargs.get("email", "")
    user_name = kwargs.get("name", "")
    gen_log.info("user name:%s" % user_name)
    try:
        #email = bs2unicode(email)
        session = get_session()
        if email:
            gen_log.info(1)
            query = api.model_query(session, "User", {
                "email": [email],
                "status": ["creating"]
            })
            result = query.first()
            return result
        if user_name:
            gen_log.info(2)
            query = api.model_query(session, "User", {
                "name": [user_name],
                "status": ["creating"]
            })
            result = query.first()
            return result
    except Exception as ex:
        gen_log.error("get creating user error:%r" % ex)
    finally:
        session.close()
示例#8
0
def like_keyword(keyword_id, user_name):
    try:
        session = get_session()
        query = api.model_query(session, "User_Like", {"keyword_id": [keyword_id], "user_name": [user_name]})
        if query.count() > 0:
            gen_log.info("The user has already clicked.")
            return False
        query = api.model_query(session, "ProductKeyword", {"id": [keyword_id]})
        if query.count() == 0:
            gen_log.info("Keyword id no exist.")
            return False
        data = {
            "user_name": user_name,
            "keyword_id": keyword_id
        }
        model_like = api.convert_model("User_Like", data)
        session.add(model_like)
        session.commit()
        return True
    except Exception as ex:
        gen_log.error("like keyword error:%r"%ex)
        return False
    finally:
        session.close()
示例#9
0
    def put(self):
        """update product"""
        product_name = self.get_argument("product_name", "")
        new_product_name = self.get_argument("new_name", "")
        gen_log.info('update product name:%s'%product_name)
        if not product_name:
            self.finish({'state': '3', 'message': 'product name is none'})
            return
        update_data = {}
        product_list = loc_product.get_product(name=product_name)
        img_path = product_list[0].get("img_path") if product_list else ""
        if not img_path:
            self.finish({'state': '3', 'message': 'product name is none'})
            return
        file_metas = self.request.files.get('product_img', '')
        if file_metas:
            gen_log.info('update product img:%s'%product_name)
            upload_path = os.path.abspath(os.path.dirname(__file__) + os.path.sep + "..")
            upload_path = os.path.join(upload_path, 'static')
            for meta in file_metas:
                filepath = os.path.join(upload_path, img_path)
                with open(filepath, 'wb') as up:
                    up.write(meta['body'])

        if new_product_name:
            update_data.update({"name": new_product_name})
        source = self.get_argument("source", '')
        if source:
            update_data.update({"source": source})
        theme = self.get_argument("theme", '')
        if theme:
            update_data.update({"theme": theme})
        ori_price = float(self.get_argument("ori_price", -1))
        if ori_price > -1:
            update_data.update({"ori_price": ori_price})
        con_price = float(self.get_argument("con_price", -1))
        if con_price > -1:
            update_data.update({"con_price": con_price})
        postage_price = float(self.get_argument("postage_price", -1))
        if postage_price > -1:
            update_data.update({"postage_price": postage_price})

        count_down_at = self.get_argument("count_down_at", "")
        if count_down_at:
            update_data.update({"count_down_at": count_down_at})
        description = self.get_argument("description", "")
        if description:
            update_data.update({"description": description})
        like_add_count = int(self.get_argument("like_add_count", -1))
        if like_add_count>-1:
            update_data.update({"like_add_count": like_add_count})
        links = self.get_argument("links", "")
        if links:
            update_data.update({"links": links})
        sort_num = int(self.get_argument("sort_num", -1))
        if sort_num > -1:
            update_data.update({"sort_num": sort_num})
        recommend = int(self.get_argument("recommend", -1))
        if recommend > -1:
            update_data.update({"recommend": recommend})

        if update_data:
            _ = loc_product.update_product(update_data, {"name": [product_name]})
            if not _:
                self.finish({'state': '2', 'message': 'update product faild'})
                return
        self.finish({'state': '0', 'message': 'Update product ok'})