kukkjanos / ewelink

EWeLink Smart Home API Methods
27 stars 12 forks source link

params is incomplete #3

Open inpq opened 4 years ago

inpq commented 4 years ago

Suddenly, the api returns this message array [ "code" => 400 "error" => "params is incomplete" ] Sometimes it still works, but a lot returns this.

Is it because of some change in the ewelink servers?

Thanks

oroszgergely commented 4 years ago

got this error as well here is a discussion about it: https://github.com/skydiver/ewelink-api/issues/21 @kukkjanos can you give some help on it?

oroszgergely commented 4 years ago

ok, success with this changes Api\EWeApi.php

public function getDevices() { $params = [ 'headers' => $this->getAuthHeader(), 'query' => [ 'lang' => 'en', 'apiKey' => $this->cache['user']['apikey'], 'getTags' => '1', 'version' => '6', time(), 'appid' => 'oeVkj2lYFGnJu5XUtWisfW4utiN4u9Mq', 'imei' => 'DF7425A0-' . rand(1000, 9999) . '-' . rand(1000, 9999) . '-9F5E-3BC9179E48FB', 'os' => 'android', 'model' => '', 'romVersion' => '', 'appVersion' => '3.12.0', ] ];

    $response = $this->EWeAPI->request(
        'GET',
        'https://' . $this->cache['region'] . '-api.coolkit.cc:8080/api/user/device',
        $params
    );

    return json_decode($response->getBody(), true);
}

public function getDevice($deviceId)
{
    $params = [
        'headers' => $this->getAuthHeader(),
        'query'   => [
            'lang'       => 'en',
            'apiKey'     => $this->cache['user']['apikey'],
            'getTags'    => '1',
            'version'    => '6',
            time(),
            'appid'      => 'oeVkj2lYFGnJu5XUtWisfW4utiN4u9Mq',
            'imei'       => 'DF7425A0-' . rand(1000, 9999) . '-' . rand(1000, 9999) . '-9F5E-3BC9179E48FB',
            'os'         => 'android',
            'model'      => '',
            'romVersion' => '',
            'appVersion' => '3.12.0',
        ]
    ];

    $response = $this->EWeAPI->request(
        'GET',
        'https://' . $this->cache['region'] . '-api.coolkit.cc:8080/api/user/device/' . $deviceId,
        $params
    );

    return json_decode($response->getBody(), true);
}
inpq commented 4 years ago

I have modified the code, but the error remains in my case.

oroszgergely commented 4 years ago

try with this, sometimes it returns error, dont know why:

public function getDevice($deviceId) { do { $params = [ 'headers' => $this->getAuthHeader(), 'query' => [ 'lang' => 'en', 'apiKey' => $this->cache['user']['apikey'], 'getTags' => '1', 'version' => '6', time(), 'appid' => 'oeVkj2lYFGnJu5XUtWisfW4utiN4u9Mq', 'imei' => 'DF7425A0-' . rand(1000, 9999) . '-' . rand(1000, 9999) . '-9F5E-3BC9179E48FB', 'os' => 'android', 'model' => '', 'romVersion' => '', 'appVersion' => '3.12.0', ] ];

        $response = $this->EWeAPI->request(
            'GET',
            'https://' . $this->cache['region'] . '-api.coolkit.cc:8080/api/user/device/' . $deviceId,
            $params
        );
        $data = json_decode($response->getBody(), true);
    } while (isset($data['code']));
    return $data;
}
oroszgergely commented 4 years ago

after playing this, i found, that the best is not to use the getdevice function, instead use the data from the getdevices array, which contains all your devices in the 'devicelist' array if you use laravel, as i do, you can replace the function with this, otherwise you need to get the specified device from the array in other way, not with collect -> where

usage: ->getDevices('yourId');

public function getDevices($deviceId = null)
{
    $params = [
        'headers' => $this->getAuthHeader(),
        'query'   => [
            'lang'       => 'en',
            'apiKey'     => $this->cache['user']['apikey'],
            'getTags'    => '1',
            'version'    => '6',
            time(),
            'appid'      => 'oeVkj2lYFGnJu5XUtWisfW4utiN4u9Mq',
            'imei'       => 'DF7425A0-' . rand(1000, 9999) . '-' . rand(1000, 9999) . '-9F5E-3BC9179E48FB',
            'os'         => 'android',
            'model'      => '',
            'romVersion' => '',
            'appVersion' => '3.12.0',
        ]
    ];

    $response = $this->EWeAPI->request(
        'GET',
        'https://' . $this->cache['region'] . '-api.coolkit.cc:8080/api/user/device',
        $params
    );

    $data = json_decode($response->getBody(), true);

    if ( isset($data['devicelist'])) {
        $data = collect($data['devicelist'])->keyBy('deviceid');
        if ( $deviceId !== null ) {
            return $data->where('deviceid',$deviceId)->first();
        }
    }
    return $data;
}
inpq commented 4 years ago

I agree. With getDevices () it seems that there is no error. I do not use Laravel. I have left my code like this:

public function getDevices($deviceId = false) { $params = [ 'headers' => $this->getAuthHeader(), 'query' => [ 'lang' => 'en', 'apiKey' => $this->cache['user']['apikey'], 'getTags' => '1', 'version' => '6', time(), 'appid' => 'oeVkj2lYFGnJu5XUtWisfW4utiN4u9Mq', 'imei' => 'DF7425A0-' . rand(1000, 9999) . '-' . rand(1000, 9999) . '-9F5E-3BC9179E48FB', 'os' => 'android', 'model' => '', 'romVersion' => '', 'appVersion' => '3.12.0', ] ]; }

public function getDevice($deviceId) { return $this->getDevices($deviceId); }

cctalma commented 4 years ago

This commit fixed it for me https://github.com/kukkjanos/ewelink/pull/6/commits/375c1c240cfec4c13cbd0f1984194818c31b8890