Пример #1
0
 def __init__(self):
     self.db = get_mongo(current_app.config['MONGO_PASSWD_B64'])
     self.admin = self.db['wx_admin']
     refresh_access_token(
         url=current_app.config['API_REFRESH_ACCESS_TOKEN'],
         passwd=current_app.config['MONGO_PASSWD_B64'],
         app_id=current_app.config['WX_APP_ID'],
         secret=current_app.config['WX_APP_SECRET'])
     self.token = self._get_type('access_token')
Пример #2
0
def refresh_access_token(url, passwd, app_id, secret):
    admin = get_mongo(passwd)['wx_admin']
    access_token = admin.find_one({'type': {'$eq': 'access_token'}})

    if sys.platform == 'darwin':
        return

    if access_token and access_token['expire'] > get_timestamp() + 3600:
        print(f"当前token仍有效, {access_token['token']}.")
        return

    import requests
    import json

    param = {
        'grant_type': 'client_credential',
        'appid': app_id,
        'secret': secret
    }
    res = requests.get(url, params=param)

    if res.status_code == 200:
        res = res.content
        res = json.loads(res)
        if 'errcode' in res:
            print(f"token更新失败, {res['errmsg']}")
            return
        access_token = {
            'type': 'access_token',
            'token': res['access_token'],
            'expire': get_timestamp() + res['expires_in']
        }
        admin.replace_one({'type': {
            '$eq': 'access_token'
        }},
                          access_token,
                          upsert=True)
        print(f"token更新成功, {access_token['token']}.")
Пример #3
0
 def __init__(self, timeout=30 * 60):
     self.timeout = timeout
     db = get_mongo(current_app.config['MONGO_PASSWD_B64'])
     self._db = db['xinshou_session']
     self.init_db()
Пример #4
0
 def __init__(self):
     db = get_mongo(current_app.config['MONGO_PASSWD_B64'])
     self._log = db['cp_daily_log']
     self._token = db['cp_daily_token']
     self._work = db['cp_daily']
     self._loc = db['cp_daily_location']
Пример #5
0
 def __init__(self):
     db = get_mongo(current_app.config['MONGO_PASSWD_B64'])
     self._db = db['credits']
     self._log = db['credits_log']
     self.init_db()
Пример #6
0
 def __init__(self):
     db = get_mongo(current_app.config['MONGO_PASSWD_B64'])
     self._db = db['xinshou_msg_log']
Пример #7
0
 def __init__(self):
     db = get_mongo(current_app.config['MONGO_PASSWD_B64'])
     self._db = db['wx_auth']
Пример #8
0
 def __init__(self):
     db = get_mongo(current_app.config['MONGO_PASSWD_B64'])
     self._db = db['xinshou_location']
     self.clean()