Beispiel #1
0
def init(app_id: str, app_secret: str, pool_size: int = 10, version: str = __version__) -> bool:
    http(version=version, pool_size=pool_size)
    if not download_library():
        return False
    json_data = binding().decrypt(app_id, app_secret)
    d = loads(json_data)
    dict_im_config(d['im'] if 'im' in d.keys() else {})
    dict_rtc_config(d['rtc'] if 'rtc' in d.keys() else {})
    dict_live_config(d['sensor'] if 'sensor' in d.keys() else {})
    return True
Beispiel #2
0
    def getGoldByLiveOpenID(live_open_id: str) -> dict:

        nonce = genRandomString()
        params = {
            'nonce_str': nonce,
            'app_id': config().app_key,
            'uid': live_open_id,
        }
        params['sign'] = genSign(params, config().app_secret)

        uri = config().url + '/open/finanv0/getUserTokens'
        err_result = ''
        i = 0
        while i < 3:

            response = http().get(uri=uri, params=params)
            if response.status != 200:
                return {
                    'status': False,
                    'error': 'httpStatusCode(%d) != 200' % response.status,
                }

            result = json.loads(str(response.data, encoding='utf8'))
            if int(result['status']) == 200:
                return {
                    'status': True,
                    'golds': int(result['data']['tokens']),
                }

            if int(result['status']) == 500:
                err_result = 'message(%s)' % result['msg']
                i += 1
                time.sleep(waitTime)
                continue

            return {
                'status': False,
                'error': 'message(%s)' % result['msg'],
            }

        return {
            'status': False,
            'error': err_result,
        }
Beispiel #3
0
    def getTokenByThirdUID(third_uid: str,
                           a_id: str,
                           user_name: str = '',
                           sex: int = SexTypeUnknown,
                           portrait_uri: str = '',
                           user_email: str = '',
                           country_code: str = '',
                           birthday: str = '') -> dict:

        nonce = genRandomString()
        params = {
            'nonce_str': nonce,
            'app_id': config().app_key,
            'userId': third_uid,
            'aid': a_id,
        }
        if len(user_name) > 0:
            params['name'] = user_name

        if len(portrait_uri) > 0:
            params['portraitUri'] = portrait_uri

        if len(user_email) > 0:
            params['email'] = user_email

        if len(country_code) > 0:
            params['countryCode'] = country_code

        if len(birthday) > 0:
            params['birthday'] = birthday

        if sex != SexTypeUnknown:
            params['sex'] = str(sex)

        params['sign'] = genSign(params, config().app_secret)

        uri = config().url + '/open/v0/thGetToken'

        err_result = ''
        i = 0
        while i < 3:
            response = http().post(uri=uri, params=params)

            if response.status != 200:
                return {
                    'status': False,
                    'error': 'httpStatusCode(%d) != 200' % response.status,
                }

            result = json.loads(str(response.data, encoding='utf8'))
            if int(result['status']) == 200:
                return {
                    'status': True,
                    'live_token': result['data']['token'],
                    'live_open_id': result['data']['openId'],
                }

            if int(result['status']) == 500:
                err_result = 'message(%s)' % result['msg']
                i += 1
                time.sleep(waitTime)
                continue

            return {
                'status': False,
                'error': 'message(%s)' % result['msg'],
            }

        return {
            'status': False,
            'error': err_result,
        }
Beispiel #4
0
    def changeGoldByLiveOpenID(live_open_id: str,
                               order_type: int,
                               gold: int,
                               expr: int,
                               optional_reason: str = '') -> dict:

        nonce = genRandomString()
        params = {
            'nonce_str': nonce,
            'app_id': config().app_key,
            'uid': live_open_id,
            'request_id': genUniqueIDString(config().app_key),
            'type': str(order_type),
            'value': str(gold),
        }
        if expr > 0:
            params['expriation'] = str(
                time.mktime(datetime.now().timetuple()) + expr * 86400)

        if len(optional_reason) > 0:
            params['reason'] = optional_reason

        params['sign'] = genSign(params, config().app_secret)

        uri = config().url + '/open/finanv0/changeGold'
        err_result = ''
        i = 0
        while i < 3:

            response = http().post(uri=uri, params=params)

            if response.status != 200:
                return {
                    'status': False,
                    'error': 'httpStatusCode(%d) != 200' % response.status,
                }

            result = json.loads(str(response.data, encoding='utf8'))

            if int(result['status']) == 200:
                return {
                    'status': True,
                    'ok': True,
                }

            if int(result['status']) == 500:
                err_result = 'message(%s)' % result['msg']
                i += 1
                time.sleep(waitTime)
                continue

            return {
                'status': True,
                'ok': False,
                'msg': 'message(%s)' % result['msg'],
            }

        return {
            'status': False,
            'error': err_result,
        }
Beispiel #5
0
    def successOrderByLiveOpenID(live_open_id: str, order_type: int, gold: int,
                                 money: int, expr: int, platform_type: str,
                                 order_id: str) -> dict:

        nonce = genRandomString()
        params = {
            'nonce_str':
            nonce,
            'app_id':
            config().app_key,
            'uid':
            live_open_id,
            'request_id':
            genUniqueIDString(config().app_key),
            'type':
            str(order_type),
            'value':
            str(gold),
            'money':
            str(money),
            'expriation':
            str(time.mktime(datetime.now().timetuple()) + expr * 86400),
            'channel':
            config().alias,
            'platform':
            platform_type,
        }

        if len(order_id) > 0:
            params['order_id'] = order_id

        params['sign'] = genSign(params, config().app_secret)

        uri = config().url + '/open/finanv0/orderSuccess'

        err_result = ''
        i = 0
        while i < 3:

            response = http().post(uri=uri, params=params)
            if response.status != 200:
                return {
                    'status': False,
                    'error': 'httpStatusCode(%d) != 200' % response.status,
                }

            result = json.loads(str(response.data, encoding='utf8'))
            if int(result['status']) == 200:
                return {
                    'status': True,
                    'golds': int(result['data']['tokens']),
                }

            if int(result['status']) == 500:
                err_result = 'message(%s)' % result['msg']
                i += 1
                time.sleep(waitTime)
                continue

            return {
                'status': False,
                'error': 'message(%s)' % result['msg'],
            }
        return {
            'status': False,
            'error': err_result,
        }