当前位置: 首页>>代码示例>>Python>>正文


Python WechatBasic.create_qrcode方法代码示例

本文整理汇总了Python中wechat_sdk.WechatBasic.create_qrcode方法的典型用法代码示例。如果您正苦于以下问题:Python WechatBasic.create_qrcode方法的具体用法?Python WechatBasic.create_qrcode怎么用?Python WechatBasic.create_qrcode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wechat_sdk.WechatBasic的用法示例。


在下文中一共展示了WechatBasic.create_qrcode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_qrcode

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import create_qrcode [as 别名]
    def test_create_qrcode(self):
        data = {"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "123"}}}

        # 测试无 appid 和 appsecret 初始化
        wechat = WechatBasic()
        with self.assertRaises(NeedParamError):
            wechat.create_qrcode(data)

        # 测试有 appid 和 appsecret 初始化
        wechat = WechatBasic(appid=self.appid, appsecret=self.appsecret)
        with HTTMock(wechat_api_mock):
            resp = wechat.create_qrcode(data)
            self.assertEqual(resp['ticket'], 'gQH47joAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL2taZ2Z3TVRtNzJXV1Brb3ZhYmJJAAIEZ23sUwMEmm3sUw==')
            self.assertEqual(resp['expire_seconds'], 60)
            self.assertEqual(resp['url'], 'http://weixin.qq.com/q/kZgfwMTm72WWPkovabbI')
开发者ID:14F,项目名称:wechat-python-sdk,代码行数:17,代码来源:test_basic.py

示例2: create_qrcode

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import create_qrcode [as 别名]
    def create_qrcode(cls, name):
        from app import Qrcode
        token, expired_at = _wechat.get_access_token()
        wechat = WechatBasic(
            appid=settings.app_id,
            appsecret=settings.secret,
            access_token=token,
            access_token_expires_at=expired_at)
        payload = {
            "action_name": "QR_LIMIT_STR_SCENE",
            "action_info": {"scene": {"scene_str": name}}}
        resp = wechat.create_qrcode(payload)
        ticket = resp.get('ticket', '')
        url = resp.get('url', '')
        data = cls.show_qrcode(ticket)
        if not data:
            raise
        output = cStringIO.StringIO()
        output.write(data)

        # upload
        p = qiniu.PutPolicy(settings.bucket)
        path = '/qrcode/%s' % name
        path, hash_key = p.upload(output, path)
        output.close()

        Qrcode.create_code(name, ticket, url, path, hash_key)
        p = qiniu.PublicGetPolicy(settings.bucket, path)
        return p.get_url()
开发者ID:southwolf,项目名称:wechat-admin,代码行数:31,代码来源:qrcode.py

示例3: bind_saler

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import create_qrcode [as 别名]
def bind_saler():
    """绑定收银台"""
    bid = int(request.args.get("bid", 0))
    do = request.args.get("do", 0)
    brand = Brand.query.get(bid)
    salers = brand.brand_salers.count()
    users = brand.brandaccounts
    shop_id = 0
    # 获取二维码
    wechat = WechatBasic(
        appid=current_app.config.get("WECHAT_APPID"), appsecret=current_app.config.get("WECHAT_APPSECRET")
    )
    temp_data = {
        "expire_seconds": 604800,
        "action_name": "QR_SCENE",
        "action_info": {"scene": {"scene_id": int(str("11") + str(brand.id))}},
    }
    # data = {"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": int(str("11") + str(brand.id))}}}
    get_ticket_data = wechat.create_qrcode(temp_data)
    ticket = get_ticket_data.get("ticket")
    if do == "download_qrcode":
        logging.info("download_qrcode")
        response = wechat.show_qrcode(ticket)
        response = make_response(response.content)
        response.headers["Content-Type"] = "image/jpg"
        attachment_name = "attachment; filename=汝州百事优惠圈绑定收银台专用二维码.jpg"
        response.headers["Content-Disposition"] = attachment_name
        return response

    return render_template("shop/bind_saler.html", brand=brand, ticket=ticket, users=users)
开发者ID:yyt030,项目名称:quanduoduo,代码行数:32,代码来源:shop.py

示例4: checkout

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import create_qrcode [as 别名]
def checkout():
    verify = False
    is_expire = False
    usedit = False
    discount_id = request.args.get("discount_id", 0, type=int)
    record_id = request.args.get("record_id", 0, type=int)  # 领取id
    do = request.args.get("do")
    discount = Discount.query.get_or_404(discount_id)
    shops = discount.shops
    record = GetTicketRecord.query.get_or_404(record_id)
    if record.status == "usedit":
        usedit = True
    if discount:
        expire_date = discount.create_at + timedelta(days=discount.usable)
        print discount.create_at, discount.usable
        expire_date = expire_date.date()
        if datetime.datetime.now().date() > expire_date:
            is_expire = True

    # 获取二维码ticket
    if do == "get_qrcode":
        if record.status == "verify":
            verify = True
        if not record.ticket:
            # 获取永久二维码 scene_id前缀12表示是优惠券类型的二维码
            wechat = WechatBasic(
                appid=current_app.config.get("WECHAT_APPID"), appsecret=current_app.config.get("WECHAT_APPSECRET")
            )
            data = {
                "action_name": "QR_LIMIT_SCENE",
                "action_info": {"scene": {"scene_id": int(str("12") + str(record.id))}},
            }
            get_ticket_data = wechat.create_qrcode(data)
            ticket = get_ticket_data.get("ticket")
            session["ticket"] = ticket
            # 写入数据库
            record.ticket = ticket
            db.session.add(record)
            db.session.commit()
        else:
            ticket = record.ticket
        return json.dumps({"message": {"verify": verify, "ticket": ticket, "expire": 0}})
    elif do == "download_qrcode":
        return ""
    return render_template(
        "shop/checkout.html",
        shops=shops,
        expire_date=expire_date,
        is_expire=is_expire,
        record_id=record_id,
        record=record,
        usedit=usedit,
        discount=discount,
    )
开发者ID:yyt030,项目名称:quanduoduo,代码行数:56,代码来源:shop.py

示例5: _compute_qrcode

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import create_qrcode [as 别名]
 def _compute_qrcode(self):
     self.ensure_one()
     tool.token_tool.refresh()
     wechat = WechatBasic(token=__builtin__.token["access_token"], appid=__builtin__.appid,
                          appsecret=__builtin__.appsecret)
     data = dict()
     # data["expire_seconds"] = 604800
     data["action_name"] = "QR_LIMIT_SCENE"
     data["action_info"] = {"scene": {"scene_id": self.id}}
     ret = wechat.create_qrcode(data)
     # ret = wechat.show_qrcode()
     self.weixin_qrcode = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s" % ret["ticket"]
开发者ID:Primary-Traxex,项目名称:wechat_base,代码行数:14,代码来源:bind_wizard.py

示例6: detail

# 需要导入模块: from wechat_sdk import WechatBasic [as 别名]
# 或者: from wechat_sdk.WechatBasic import create_qrcode [as 别名]
def detail():
    discount_id = int(request.args.get("id", 0))
    if not discount_id:
        discount_id = int(request.args.get("did", 0))
    do = request.args.get("do")
    discount = Discount.query.get_or_404(discount_id)

    # discount.count 每天0:00清零 TODO 脚本任务
    left_count = discount.number - discount.count
    discount_shop_count = discount.shops.count()
    shop_photos = ShopPhoto.query.filter(ShopPhoto.brand_id == discount.brand_id)
    user_agent = request.headers.get('User-Agent')

    curr_user = g.user
    # user的领券情况
    # 该用户下领用的存在有效期的券(含使用或者未使用)
    curr_ticket_record = GetTicketRecord.query.filter(GetTicketRecord.user_id == curr_user.id,
                                                      GetTicketRecord.discount_id == discount_id,
                                                      GetTicketRecord.create_at >= datetime.datetime.now() - datetime.timedelta(
                                                          days=discount.usable))
    monday = datetime.datetime.now() - datetime.timedelta(days=datetime.datetime.now().weekday())
    sunday = datetime.datetime.now() + datetime.timedelta(days=7 - datetime.datetime.now().weekday())
    curr_ticket_records_week = curr_ticket_record.filter(GetTicketRecord.create_at >= monday,
                                                         GetTicketRecord.create_at <= sunday).count()
    # print user_agent
    if do == 'post':
        if 'MicroMessenger' not in user_agent:
            return json.dumps({"message": "请在微信里操作", "redirect": "permit", "type": "tips"})
        else:
            expire_datetime = discount.get_expire_datetime
            # expire_datetime_format = expire_datetime.strftime("%Y-%m%-%d")
            expire_datetime_format = str(expire_datetime.date())
            record = GetTicketRecord.query.filter(GetTicketRecord.user_id == g.user.id,
                                                  GetTicketRecord.discount_id == discount_id).first()
            if record:
                if record.status != 'expire':
                    return json.dumps(
                        {"message": {}, "redirect": "", "type": "error"})
            openid = session['openid']

            wechat = WechatBasic(appid=appid, appsecret=appsecret)
            # wechat.send_text_message(session['openid'], "test")
            # 调用公众号消息模板A0XK30w_sZPti5_gn33PJ5msng7yb71zAEcRa0E44oM发送领券通知
            template_id = 'A0XK30w_sZPti5_gn33PJ5msng7yb71zAEcRa0E44oM'
            """{first.DATA}}
            优惠券:{{keyword1.DATA}}
            来源:{{keyword2.DATA}}
            过期时间:{{keyword3.DATA}}
            使用说明:{{keyword4.DATA}}
            {{remark.DATA}}
            """
            json_data = {
                "first": {
                    "value": "恭喜你领券成功!",
                    "color": "#173177"
                },
                "keyword1": {
                    "value": discount.title,
                    "color": "#173177"
                },
                "keyword2": {
                    "value": "网页获取",
                    "color": "#173177"
                },
                "keyword3": {
                    "value": expire_datetime_format,
                    "color": "#173177"
                },
                "remark": {
                    "value": "凭优惠券详情二维码领取",
                    "color": "#173177"
                }
            }
            # 领取后需要写入到get_discount_record 表
            # TODO 下次是否能领取则通过这张表的数据来判断
            year = time.strftime("%Y", time.localtime())[2:]
            # TODO 根据时间戳生成唯一id,可能有点不规范
            code = year + str(time.time())[4:-3]
            record = GetTicketRecord(user_id=g.user.id, discount_id=discount_id, code=code)
            db.session.add(record)
            discount.count = discount.count + 1
            db.session.add(discount)
            db.session.commit()
            url = current_app.config.get('SITE_DOMAIN') + (
                url_for('shop.checkout', discount_id=discount_id, record_id=record.id))
            wechat.send_template_message(openid, template_id, json_data, url)

            # still 表示本周还能领多少张 TODO 静态数据需要替换
            # allow 表示本周允许领取多少张
            still = discount.number * discount.usable - 1
            # 获取永久二维码 scene_id前缀12表示是优惠券类型的二维码
            wechat = WechatBasic(appid=current_app.config.get('WECHAT_APPID'),
                                 appsecret=current_app.config.get('WECHAT_APPSECRET'))
            data = {"action_name": "QR_LIMIT_SCENE",
                    "action_info": {"scene": {"scene_id": int(str("12") + str(record.id))}}}
            get_ticket_data = wechat.create_qrcode(data)
            ticket = get_ticket_data.get("ticket")
            session['ticket'] = ticket
            # 写入数据库
            record.ticket = ticket
#.........这里部分代码省略.........
开发者ID:yyt030,项目名称:quanduoduo,代码行数:103,代码来源:discount.py


注:本文中的wechat_sdk.WechatBasic.create_qrcode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。