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


Python Client.update_wx方法代码示例

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


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

示例1: handle_authorized

# 需要导入模块: from models import Client [as 别名]
# 或者: from models.Client import update_wx [as 别名]
def handle_authorized(data):
    authorizer_appid = data.get('AuthorizerAppid')
    authorization_code = data.get('AuthorizationCode')
    code_expire = data.get('AuthorizationCodeExpiredTime')

    logging.debug("authorized appid:%s code:%s expire:%s", 
                  authorizer_appid, authorization_code, code_expire)

    rds = g.im_rds
    db = g._db
    auth_code = authorization_code
    store_id = 0

    component_token = get_component_access_token(rds)
    if not component_token:
        return "授权失败"

    wx = WXOpenAPI(APPID, APPSECRET, component_token)
    r = wx.request_auth(auth_code)
    if r:
        info = r['authorization_info']
        wx_appid = info['authorizer_appid']
        access_token = info['authorizer_access_token']
        expires_in = info['expires_in']
        #提前10分钟过期
        if expires_in > 20*60:
            expires_in = expires_in - 10*60

        refresh_token = info['authorizer_refresh_token']
        funcs = info['func_info']
        fids = []
        for f in funcs:
            fid = f['funcscope_category']['id']
            fids.append(fid)

        is_app = False
        AUTHORIZATION_MESSAGE = 1
        AUTHORIZATION_CONTACT = 19
        if AUTHORIZATION_MESSAGE in fids:
            #公众号
            is_app = False
        elif AUTHORIZATION_CONTACT in fids:
            #小程序
            is_app = True
        else:
            logging.warning("no message authorization")
            return "没有消息权限"

        app_info = wx.request_info(wx_appid)
        if not app_info:
            logging.warning("request app info fail")
            return "获取公众号信息失败"
        name = app_info['authorizer_info']['nick_name']
        gh_id = app_info['authorizer_info']['user_name']

        app = App.get_wx(db, wx_appid)
        if app:
            Client.update_wx(db, wx_appid, refresh_token, 1)
            if app['store_id'] != 0 and app['store_id'] != store_id:
                return "已被其它账号授权"
        else:
            App.create_wx(db, name, gh_id, wx_appid, refresh_token, store_id, is_app)
        WX.set_access_token(rds, wx_appid, access_token, expires_in)
        return "授权成功"
    else:
        return "获取令牌失败"
开发者ID:richmonkey,项目名称:xiaowei_web,代码行数:68,代码来源:message.py

示例2: auth_callback

# 需要导入模块: from models import Client [as 别名]
# 或者: from models.Client import update_wx [as 别名]
def auth_callback(uid):
    rds = g.im_rds
    db = g._db
    auth_code = request.args.get('auth_code')
    expires_in = request.args.get('expires_in')
    if not auth_code or not expires_in:
        return "非法调用"

    seller = Seller.get_seller(db, uid)
    store_id = seller['store_id']

    logging.debug("auth callback code:%s uid:%s store_id:%s", 
                  auth_code, uid, store_id)

    component_token = get_component_access_token(rds)
    if not component_token:
        return "授权失败"

    wx = WXOpenAPI(APPID, APPSECRET, component_token)
    r = wx.request_auth(auth_code)
    if r:
        info = r['authorization_info']
        logging.debug("auth callback info:%s", info)
        wx_appid = info['authorizer_appid']
        access_token = info['authorizer_access_token']
        expires_in = info['expires_in']
        #提前10分钟过期
        if expires_in > 20*60:
            expires_in = expires_in - 10*60

        refresh_token = info['authorizer_refresh_token']
        funcs = info['func_info']
        fids = []
        for f in funcs:
            fid = f['funcscope_category']['id']
            fids.append(fid)

        is_app = False
        AUTHORIZATION_MESSAGE = 1
        AUTHORIZATION_CONTACT = 19
        if AUTHORIZATION_MESSAGE in fids:
            #公众号
            is_app = False
        elif AUTHORIZATION_CONTACT in fids:
            #小程序
            is_app = True
        else:
            logging.warning("no message authorization")
            return "没有消息权限"

        app_info = wx.request_info(wx_appid)
        if not app_info:
            logging.warning("request app info fail")
            return "获取公众号信息失败"
        name = app_info['authorizer_info']['nick_name']
        gh_id = app_info['authorizer_info']['user_name']

        app = App.get_wx(db, wx_appid)
        if app:
            Client.update_wx(db, wx_appid, refresh_token, 1)
            if app['store_id'] != 0 and app['store_id'] != store_id:
                return "已被其它账号授权"
            if app['store_id'] == 0:
                App.set_store_id(db, app['id'], store_id)
        else:
            App.create_wx(db, name, gh_id, wx_appid, refresh_token, store_id, is_app)
        WX.set_access_token(rds, wx_appid, access_token, expires_in)
        return "授权成功"
    else:
        return "获取令牌失败"
开发者ID:richmonkey,项目名称:xiaowei_web,代码行数:72,代码来源:message.py


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