def __init__(self, to_user_name, from_user_name, media_id): super().__init__() self.d.update({ 'ToUserName': to_user_name, 'FromUserName': from_user_name, 'CreateTime': get_timestamp(), 'MediaId': media_id })
def __init__(self, to_user_name, from_user_name, content): super().__init__() self.d.update({ 'ToUserName': to_user_name, 'FromUserName': from_user_name, 'CreateTime': get_timestamp(), 'Content': content })
def remember_location(self, event: wx.receive.LocationEvent): l = { 'id': event.from_user_name, 'ctime': get_timestamp(), 'cdate': get_now_date(), 'longitude': event.longitude, 'latitude': event.latitude, 'scale': event.scale, 'label': event.label, 'poi': event.poi } self._loc.insert_one(l)
def set(self, event: LocationEvent): l = { 'id': event.from_user_name, 'ctime': get_timestamp(), 'cdate': get_now_date(), 'longitude': event.longitude, 'latitude': event.latitude, 'scale': event.scale, 'label': event.label, 'poi': event.poi } self._db.insert_one(l)
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']}.")
def add_user(self, stu_no, passwd, open_id): l = { 'id': open_id, 'no': stu_no, 'pwd': passwd, 'cdate': get_now_date(), 'ctime': get_timestamp(), 'retry': 0 } self._log.insert_one(l) url = 'http://authserver.njit.edu.cn/authserver/login?service=https%3A%2F%2Fnjit.campusphere.net%2Fportal%2Flogin' s = get_wisedu_session(url, stu_no, passwd) if s: l = check_now(l) self._work.insert_one(l) return s is not None
def get_access_token(self) -> str: res = self.token if self.token['expire'] < get_timestamp() + 3630: res = self.token = self._get_type('access_token') return res['token']