Exemplo n.º 1
0
def we_qrcode_url(request, state=None):
    authorizer_appid = request.GET.get('authorizer_appid', '')
    action_name = request.GET.get('action_name', 'QR_SCENE')
    scene_id = int(request.GET.get('scene_id', 0))
    scene_str = request.GET.get('scene_str', '')
    expire_seconds = int(request.GET.get('expire_seconds', 2592000))

    CFG = final_cfg(request, state=state or 'qrcode_url')

    if state == 'component':
        token = authorizer_access_token(
            component_appid=CFG['appID'],
            component_secret=CFG['appsecret'],
            authorizer_appid=authorizer_appid,
            storage=redis_storage(request),
            token_fetched_func=component_token_fetched_func,
            auth_token_fetched_func=component_auth_token_fetched_func)
    else:
        token = access_token(CFG['appID'],
                             CFG['appsecret'],
                             storage=redis_storage(request),
                             token_fetched_func=token_fetched_func)

    return {
        'qrinfo':
        qrcode_create(action_name=action_name,
                      scene_id=scene_id,
                      scene_str=scene_str,
                      expire_seconds=expire_seconds,
                      appid=CFG['appID'],
                      secret=CFG['appsecret'],
                      token=token,
                      storage=redis_storage(request)),
    }
Exemplo n.º 2
0
    def test_token_mem(self):
        appid = WECHAT.get('JSAPI', {}).get('appID')
        appsecret = WECHAT.get('JSAPI', {}).get('appsecret')

        token = Token(appid=appid, secret=appsecret)
        access_token1 = token.access_token()
        assert isinstance(access_token1, basestring)

        access_token2 = access_token(appid=appid, secret=appsecret)
        assert isinstance(access_token2, basestring)

        access_token3 = final_access_token(cls=token,
                                           appid=appid,
                                           secret=appsecret)
        assert isinstance(access_token3, basestring)

        assert access_token1 == access_token3 != access_token2
Exemplo n.º 3
0
    def test_token_redis(self):
        appid = WECHAT.get('JSAPI', {}).get('appID')
        appsecret = WECHAT.get('JSAPI', {}).get('appsecret')

        r = redis.StrictRedisExtensions(host='localhost', port=6379, db=0)
        storage = RedisStorage(r)

        token = Token(appid=appid, secret=appsecret, storage=storage)
        access_token1 = token.access_token()
        assert isinstance(access_token1, basestring)

        access_token2 = access_token(appid=appid,
                                     secret=appsecret,
                                     storage=storage)
        assert isinstance(access_token2, basestring)

        access_token3 = final_access_token(cls=token,
                                           appid=appid,
                                           secret=appsecret,
                                           storage=storage)
        assert isinstance(access_token3, basestring)

        assert access_token1 == access_token3 == access_token2