示例#1
0
文件: kiaif.py 项目: snaptec/openWB
def getStatusCached(vehicleId):
    soclogging.logDebug(2, "Receiving cached status")
    
    statusDict = {
    }
    
    url = parameters.getParameter('baseUrl') + '/api/v2/spa/vehicles/' + vehicleId + '/status/latest'
    headers = {
        'Authorization': parameters.getParameter('controlToken'),
        'ccsp-device-id': parameters.getParameter('deviceId'),
        'Content-Type': 'application/json',
        'Stamp': stamps.getStamp()}
    
    try:
        response = kiahttp.getHTTP(url = url, headers = headers, timeout = parameters.getParameter('reqTimeout'))
    except:
        raise 

    try:
        responseDict = json.loads(response)
        statusDict['time'] = timeToStamp(responseDict['resMsg']['vehicleStatusInfo']['vehicleStatus']['time'])
        statusDict['socev'] = int(responseDict['resMsg']['vehicleStatusInfo']['vehicleStatus']['evStatus']['batteryStatus'])
        statusDict['soc12v'] = int(responseDict['resMsg']['vehicleStatusInfo']['vehicleStatus']['battery']['batSoc'])
        statusDict['vehicleLocation'] = responseDict['resMsg']['vehicleStatusInfo']['vehicleLocation']
        statusDict['vehicleStatus'] = responseDict['resMsg']['vehicleStatusInfo']['vehicleStatus']
        statusDict['odometer'] = responseDict['resMsg']['vehicleStatusInfo']['odometer']
    except:
        soclogging.logDebug(1, "Receiving cached status failed, invalid response")
        soclogging.logDebug(2, response)
        raise

    return statusDict
示例#2
0
def getVehicleId(vin):
    soclogging.logDebug(2, "Requesting vehicle list")

    url = parameters.getParameter('baseUrl') + '/api/v1/spa/vehicles'
    headers = {
        'Authorization':
        parameters.getParameter('tokenType') + ' ' +
        parameters.getParameter('accessToken'),
        'ccsp-device-id':
        parameters.getParameter('deviceId'),
        'ccsp-application-id':
        parameters.getParameter('appId'),
        'offset':
        '1',
        'Host':
        parameters.getParameter('host'),
        'Connection':
        'close',
        'Accept-Encoding':
        'gzip, deflate',
        'User-Agent':
        'okhttp/3.10.0',
        'Stamp':
        stamps.getStamp()
    }

    try:
        response = kiahttp.getHTTP(
            url=url,
            headers=headers,
            timeout=parameters.getParameter('reqTimeout'))
    except:
        raise

    vehicleId = ''
    try:
        responseDict = json.loads(response)
        for vehicle in responseDict['resMsg']['vehicles']:
            if vehicle['vin'] == vin:
                vehicleId = vehicle['vehicleId']
    except:
        soclogging.logDebug(1, "Vehicle request failed, invalid response")
        soclogging.logDebug(2, response)
        raise

    if vehicleId == '':
        soclogging.logDebug(1, "VIN " + vin + " unknown")
        raise

    soclogging.logDebug(2, "VehicleId = " + vehicleId)

    return vehicleId
示例#3
0
def getAuthCode(cookies):
    soclogging.logDebug(2, "Sending username/password")

    url = parameters.getParameter('baseUrl') + '/api/v1/user/integrationinfo'
    headers = {'Content-type': 'application/json'}

    try:
        response = kiahttp.getHTTP(
            url=url,
            headers=headers,
            cookies=cookies,
            timeout=parameters.getParameter('reqTimeout'))
    except:
        raise

    try:
        responseDict = json.loads(response)
        userId = responseDict['userId']
        serviceId = responseDict['serviceId']
        soclogging.logDebug(2, "UserId = " + userId)
        soclogging.logDebug(2, "ServiceId = " + serviceId)
    except:
        soclogging.logDebug(0, "Login failed, invalid response")
        soclogging.logDebug(2, response)
        raise

    url = 'https://eu-account.' + parameters.getParameter(
        'brand'
    ) + '.com/auth/realms/eu' + parameters.getParameter(
        'brand'
    ) + 'idm/protocol/openid-connect/auth?client_id=' + parameters.getParameter(
        'authClientId'
    ) + '&scope=openid%20profile%20email%20phone&response_type=code&hkid_session_reset=true&redirect_uri=' + parameters.getParameter(
        'baseUrl'
    ) + '/api/v1/user/integration/redirect/login&ui_locales=en&state=' + serviceId + ':' + userId
    headers = {}

    try:
        response = kiahttp.getHTTP(
            url=url,
            headers=headers,
            cookies=cookies,
            timeout=parameters.getParameter('reqTimeout'))
    except:
        raise

    left = response.find('action="') + 8
    right = response.find('"', left)
    url = response[left:right].replace('&', '&')
    data = urlparse.urlencode({
        'username':
        parameters.getParameter('accountName'),
        'password':
        parameters.getParameter('accountPassword'),
        'credentialId':
        '',
        'rememberMe':
        'on'
    })
    headers = {
        'Content-type':
        'application/x-www-form-urlencoded',
        'User-Agent':
        'Mozilla/5.0 (iPhone; CPU iPhone OS 11_1 like Mac OS X) AppleWebKit/604.3.5 (KHTML, like Gecko) Version/11.0 Mobile/15B92 Safari/604.1'
    }
    cookiesForm = {'AUTH_SESSION_ID': kiahttp.lastCookies['AUTH_SESSION_ID']}

    try:
        response = kiahttp.postHTTP(
            url=url,
            data=data,
            headers=headers,
            cookies=cookiesForm,
            timeout=parameters.getParameter('reqTimeout'))
        parsed = urlparse.urlparse(kiahttp.lastUrl)
        intUserId = ''.join(parse_qs(parsed.query)['intUserId'])
        soclogging.logDebug(2, "intUserId = " + intUserId)
    except:
        soclogging.logDebug(0, "Login failed, invalid response")
        soclogging.logDebug(2, response)
        raise

    url = parameters.getParameter('baseUrl') + '/api/v1/user/silentsignin'
    headers = {'Content-type': 'application/json'}
    data = {'intUserId': intUserId}

    try:
        response = kiahttp.postHTTP(
            url=url,
            data=data,
            headers=headers,
            cookies=cookies,
            timeout=parameters.getParameter('reqTimeout'),
            allow_redirects=False)
        responseDict = json.loads(response)
        responseUrl = responseDict['redirectUrl']
        parsed = urlparse.urlparse(responseUrl)
        authCode = ''.join(parse_qs(parsed.query)['code'])
    except:
        soclogging.logDebug(0, "Login failed, invalid response")
        soclogging.logDebug(2, response)
        raise

    soclogging.logDebug(2, "AuthCode = " + authCode)

    return authCode