function getPoint($data) { $res = apiConnector::execAPI($data, 'points.php'); //error_log($res); return $res; }
function smsProcess($msisdn, $sms) { if (strlen($sms) > 0) { $data = array(); $msg = explode(' ', $sms); $command = $msg[0]; $message = trim(str_replace($command, '', $sms)); if ($comm = $this->dat->getCommand($command)) { if ($comm->command_code == '001') { //lapor list($data['jenisSentra'], $data['namaSentra'], $data['kodePos'], $data['namaKomoditas'], $data['jenisKomoditas'], $data['kuantitas'], $data['satuan'], $data['harga']) = explode('#', $message); $data['hp'] = $msisdn; $api = new apiConnector($this->config); $url = $api->sendData($data); $status = json_decode($url); if ($status->status_code = '000') { $reply = array('command' => '001', 'msisdn' => $msisdn, 'code' => '100', 'status' => 'sukses'); } else { $reply = array('command' => '001', 'msisdn' => $msisdn, 'code' => '901', 'status' => 'error'); } } elseif ($comm->command_code == '002') { //cari list($data['jenisSentra'], $data['namaKomoditas'], $data['jenisKomoditas'], $data['kodePos']) = explode('#', $message); $data['hp'] = $msisdn; $api = new apiConnector($this->config); $url = $api->getData($data); $status = json_decode($url); if ($status->status_code = '000') { if (isset($status->komoditas) && is_array($status->komoditas) && count($status->komoditas) > 0) { $pesan = "Harga " . $status->nama_komoditas . " " . $status->jenis_komoditas . " per " . date('d/m/Y') . ":\r\n"; $x = 1; foreach ($status->komoditas as $key => $val) { $pesan .= $x . ". " . $val->nama_sentra . " Rp. " . number_format($val->harga, 0, ",", ".") . "\r\n"; $x++; } $reply = array('command' => '002', 'msisdn' => $msisdn, 'code' => '200', 'status' => 'sukses', 'replacement' => array('{MESSAGE}' => $pesan)); } else { $reply = array('command' => '002', 'msisdn' => $msisdn, 'code' => '902', 'status' => 'sukses'); } } else { $reply = array('command' => '002', 'msisdn' => $msisdn, 'code' => '902', 'status' => 'error'); } } elseif ($comm->command_code == '003') { // point $api = new apiConnector($this->config); $data['hp'] = $msisdn; $url = $api->getPoint($data); $status = json_decode($url); if ($status->status_code = '000') { if (isset($status->point)) { $reply = array('command' => '003', 'msisdn' => $msisdn, 'code' => '300', 'status' => 'sukses', 'replacement' => array('{POINT}' => $status->point)); } else { $reply = array('command' => '003', 'msisdn' => $msisdn, 'code' => '903', 'status' => 'sukses'); } } else { $reply = array('command' => '003', 'msisdn' => $msisdn, 'code' => '902', 'status' => 'error'); } } elseif ($comm->command_code == '004') { // help $reply = array('command' => '004', 'msisdn' => $msisdn, 'code' => '400', 'status' => 'sukses'); } } else { $reply = array('command' => '000', 'msisdn' => $msisdn, 'code' => '900', 'status' => 'error'); } //return $this->sendMessage($reply); } else { $reply = array('command' => '000', 'msisdn' => $msisdn, 'code' => '909', 'status' => 'error'); } return json_encode($reply); }