Example #1
0
function service($nik)
{
    $default = ['wilayah_id' => '0', 'g-recaptcha-response' => '000', 'cmd' => 'Cari.', 'page' => '', 'nik_global' => $nik];
    $params = $default;
    $client = new GuzzleHttp\Client();
    $res = $client->request('POST', 'http://data.kpu.go.id/ss8.php', ['form_params' => $params]);
    $html = $res->getBody();
    $startsAt = strpos($html, '<body onload="loadPage()">') + strlen('<body onload="loadPage()">');
    $endsAt = strpos($html, '</body>', $startsAt);
    $result = substr($html, $startsAt, $endsAt - $startsAt);
    // return $html;
    $dom = phpQuery::newDocumentHTML($result);
    // return $dom;
    $result = [];
    foreach (pq('div.form') as $content) {
        $key = snake(preg_replace('/[\\x00-\\x1F\\x80-\\xFF]/', '', rtrim(trim(pq($content)->find('.label')->eq(0)->html()), ':')));
        $value = preg_replace('/[\\x00-\\x1F\\x80-\\xFF]/', '', rtrim(trim(pq($content)->find('.field')->eq(0)->html()), ':'));
        if (empty($key)) {
            continue;
        }
        $result[$key] = $value;
    }
    if (!empty($result)) {
        echo json_encode(['success' => true, 'message' => 'Success', 'data' => $result]);
    } else {
        http_response_code(400);
        echo json_encode(['success' => false, 'message' => 'Data tidak ditemukan']);
    }
}
Example #2
0
 /**
  * Provides dynamic calls.
  *
  * @param $name
  * @param array $arguments
  * @throws \PragmaRX\ZipCode\Exceptions\PropertyDoesNotExists
  * @return mixed
  */
 public function __call($name, array $arguments)
 {
     if (substr($name, 0, 3) == 'get') {
         $property = substr($name, 3);
         $possibleNames = [$property, snake($property), studly($property), camel($property)];
         foreach ($possibleNames as $name) {
             if (isset($this->publicProperties[$name])) {
                 return $this->publicProperties[$name];
             }
         }
     }
     throw new PropertyDoesNotExists("Property '{$name}' does not exists in Result object.");
 }