示例#1
0
def get_accounts():
    id_list = []
    with MongoClient(MONGO_HOST, MONGO_PORT) as client:
        collection = client.math_questions.account

        for i in list(collection.find()):
            phone = utils.rsa_decrypt(i['phone'])
            pwd = utils.rsa_decrypt(i['password'])
            id_list.append({'phone': phone, 'password': pwd})

    return id_list
示例#2
0
文件: study.py 项目: frcz/zhihuiguo
 def save_record(dic, chapter_id, lesson_id):
     if dic['studiedLessonDto'] is not None and dic['studiedLessonDto'][
             'watchState'] == 1:
         return
     p = {'deviceId': app_key, 'userId': user, 'versionKey': 1}
     rt = post(SIGN, '/student/tutorial/getSaveLearningRecordToken', p)
     token = utils.rsa_decrypt(rsa_key, rt)
     video_time = dic['videoSec']
     chapter_id = chapter_id or dic['chapterId']
     j = {
         'lessonId': lesson_id,
         'learnTime': str(timedelta(seconds=video_time)),
         'userId': user,
         'personalCourseId': link_course_id,
         'recruitId': recruit_id,
         'chapterId': chapter_id,
         'sourseType': 3,
         'playTimes': video_time,
         'videoId': dic['videoId'],
         'token': token,
         'deviceId': app_key
     }
     if lesson_id is None:
         j['lessonId'] = dic['id']
     else:
         j['lessonVideoId'] = dic['id']
     json_str = json.dumps(j, sort_keys=True, separators=(',', ':'))
     p = {
         'jsonStr': json_str,
         'secretStr': utils.rsa_encrypt(rsa_key, json_str),
         'versionKey': 1
     }
     rt = post(SIGN, '/student/tutorial/saveLearningRecordByToken', p)
     logger.info(dic['name'] + rt)
示例#3
0
def get_argument(key: str,
                 type=None,
                 default='',
                 decrypt: bool = False,
                 required=False,
                 error: str = None):
    value = None

    if request.json:
        value = request.json.get(key)
    else:
        value = request.form.get(key)

    error = error or 'argument ({key}) is not exists !'.format(key=key)

    # key不存在
    if value is None: abort(400, error)

    # 验证是否存在 str:'' 400, int:0 正常
    if not value and required:

        if isinstance(value, str):
            abort(400, error)
        if isinstance(value, int):
            return value

    # 数据是否解密
    if decrypt: value = rsa_decrypt(value)

    # 数据转型
    if type: value = type(value)

    return value
示例#4
0
def login():
    account = input('Account(Phone):')
    password = getpass(prompt='Password:'******'account': account,
        'password': password,
        'areaCode': '86',
        'appVersion': '4.0.6',
        'clientType': '1',
        'imei': uuid.uuid4().hex
    }
    pp = {
        'paramJsonStr':
        utils.rsa_encrypt_public(public_key,
                                 json.dumps(p, separators=(',', ':'))),
        'timeNote':
        '1515340800'
    }
    d = post('/newuser/userLoginByAccount', pp, sleep=False)
    u = d['userId']
    uu = d['userUUID']

    p = {
        'type': 3,
        'userUUID': uu,
        'secretStr': utils.rsa_encrypt(rsa_key, str(u)),
        'versionKey': 1
    }
    d = post('/student/user/getUserInfoAndAuthenticationByUUID',
             p,
             sleep=False)
    ai = json.loads(utils.rsa_decrypt(rsa_key, d['authInfo']))
    ui = json.loads(utils.rsa_decrypt(rsa_key, d['userInfo']))
    logger.info(ai)
    logger.info(ui)
    n = ui['realName']
    logger.info(f'{u} {uu} {n}')
    with open('userinfo.py', 'w+', encoding='utf-8') as f:
        f.writelines(f'USER = {u}\n')
        f.writelines(f'UUID = "{uu}"\n')
        f.writelines(f'NAME = "{n}"\n')
    logger.info('Login OK.')
    return u, uu, n
示例#5
0
文件: study.py 项目: frcz/zhihuiguo
def login():
    account = input(u'账号(手机):')
    password = getpass(prompt=u'密码:')
    assert account or password

    p = {'appkey': app_key}
    global ticket
    ticket = post(NONE, '/api/ticket', p)

    p = {
        'platform': 'android',
        'm': account,
        'appkey': app_key,
        'p': password,
        'client': 'student',
        'version': '2.8.9'
    }
    d = post(TICKET, '/api/login', p)
    u = d['userId']
    se = d['secret']

    s.headers.clear()
    p = {
        'type': 3,
        'userId': u,
        'secretStr': utils.rsa_encrypt(rsa_key, u),
        'versionKey': 1
    }
    d = post(SIGN, '/appstudent/student/user/getUserInfoAndAuthentication', p)
    ai = json.loads(utils.rsa_decrypt(rsa_key, d['authInfo']))
    ui = json.loads(utils.rsa_decrypt(rsa_key, d['userInfo']))
    logger.info(ai)
    logger.info(ui)
    n = ui['realName']
    logger.info(f'{u} {n}')
    with open('userinfo.py', 'w+', encoding='utf-8') as f:
        f.writelines(f'USER = {u}\n')
        f.writelines(f'NAME = "{n}"\n')
        f.writelines(f'SECRET = "{se}"')
    logger.info('Login OK.')
    return u, n, se
示例#6
0
 def get_accounts(self):
     """
     From mongodb get id and password data
     :return:
     """
     account_list = []
     with MongoClient(self.host, self.port) as client:
         collection = client.math_questions.account
         cursor = collection.find()
         for account in cursor:
             phone = account['phone']
             pwd = utils.rsa_decrypt(account['password'])
             account_list.append({'phone': phone, 'password': pwd})
     return account_list