Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include dirname(__FILE__).'/../vendor/autoload.php';
- use Curl\Curl;
- class Cronjob
- {
- protected $postFile = 'Post.txt';
- public function __construct($serviceId, $url, $api, $apiId)
- {
- $this->curl = new Curl();
- $this->postFile = $this->appPath($this->postFile);
- $this->lastOrderIdFile = dirname(__FILE__).'/LastOrderId.txt';
- // IRVAN-KEDE CREDENTIALS
- $this->irvUrl = $url;
- $this->irvApi = $api;
- $this->irvApiId = $apiId;
- $this->serviceId = $serviceId;
- }
- public function getFirstLine()
- {
- $loadFile = file_get_contents($this->postFile);
- $toArray = explode("\n", $loadFile);
- return trim($toArray[0]);
- }
- public function deleteFirstLine()
- {
- $loadFile = file_get_contents($this->postFile);
- $toArray = explode("\n", $loadFile);
- array_shift($toArray);
- file_put_contents($this->postFile, implode("\n", $toArray));
- }
- public function writeToSleepy($file, $txt)
- {
- $path = $this->appPath('sleepy/'. $file .'.txt');
- $openFile = fopen($path, "a");
- $logSomething = '[ '. time_id(time()) .'] '. $txt;
- fwrite($openFile, $logSomething."\n\n");
- fclose($openFile);
- return $logSomething;
- }
- public function appPath($file)
- {
- return dirname(__FILE__). '/'. $file;
- }
- public function getUrldanJumlah($firstLine)
- {
- $array = explode('|', $firstLine);
- if ( ! isset($array[0])
- || ! isset($array[1])
- || $array[0] == ''
- || $array[1] == ''
- ) {
- return null;
- }
- return [
- 'url' => $array[0],
- 'jumlah' => $array[1],
- ];
- }
- public function putLastOrderId($orderId, $startLikes, $url)
- {
- $format = $orderId.'|'.$startLikes.'|'.$url;
- return file_put_contents($this->lastOrderIdFile, $format);
- }
- public function submitKeIrvSMM($url, $jumlah)
- {
- $json = $this->proccessSubmitKeIrvan($url, $jumlah);
- // If successfully
- if ($json->status == 1) {
- // $this->deleteFirstLine();
- $orderId = $json->data->id;
- $startLikes = $this->checkLikesInstagramPost($url);
- $this->putLastOrderId($orderId, $startLikes, $url);
- return $this->writeToSleepy(
- 'sukses',
- 'Sukses bro : '. $url .' - Jumlah : '. $jumlah .' - With OrderID : '. $orderId
- );
- }
- // If Failed
- $gagalMessage = json_encode($json);
- return $this->writeToSleepy(
- 'gagal',
- ' !! GAGAL !! : '. $url . ' - Jumlah : '. $jumlah .' - gagalMessage : '. $gagalMessage
- );
- }
- public function selectTextAndSubmit()
- {
- $firstLine = $this->getFirstLine();
- if ($firstLine == '' || $firstLine == null) {
- return 'File kosong... isi dulu link nya di '. $this->postFile;
- }
- $data = $this->getUrldanJumlah($firstLine);
- if ( ! $data) {
- $this->deleteFirstLine();
- return $this->writeToSleepy(
- 'gagal',
- 'FORMAT SALAH - Ngisi yang bener : '. $firstLine
- );
- }
- return $this->submitKeIrvSMM($data['url'], $data['jumlah']);
- }
- public function start()
- {
- $lastOrderId = file_get_contents($this->lastOrderIdFile);
- $rawId = explode('|', $lastOrderId);
- $rawJson = $this->status($lastOrderId = $rawId[0]);
- $lastOrderStatus = $rawJson->data->status;
- $rawLikes = $rawId[1] + 75;
- $checkLikes = $this->checkLikesInstagramPost($rawId[2]);
- if ($checkLikes <= $rawLikes) {
- if ($lastOrderStatus == 'Pending' || $lastOrderStatus == 'Processing') {
- print_r($this->getUrldanJumlah($this->getFirstLine()));
- echo '<hr>';
- print_r($rawJson);
- echo '<hr>';
- echo "LIKES ON POST : ". $checkLikes;
- echo '<hr>';
- return 'Still waiting orderId : <b>'. $lastOrderId .'</b> to be successfull.';
- }
- }
- if ($checkLikes > $rawLikes) {
- $this->deleteFirstLine();
- }
- // Re-submit
- if ($lastOrderStatus == 'Partial') {
- return $this->selectTextAndSubmit();
- }
- if ($lastOrderStatus == 'Success') {
- $this->deleteFirstLine();
- }
- return $this->selectTextAndSubmit();
- }
- // FROM EXAMPLE IRVAN-KEDE API
- public function order($data)
- {
- return json_decode($this->connect($this->irvUrl.'order', array_merge(array('api_id' => $this->irvApiId, 'api_key' => $this->irvApi), $data)));
- }
- public function status($order_id)
- {
- return json_decode($this->connect($this->irvUrl.'status', array('api_id' => $this->irvApiId, 'api_key' => $this->irvApi, 'id' => $order_id)));
- }
- protected function checkLikesInstagramPost($url)
- {
- $url = str_finish($url, '/');
- $postPage = httpGet($url);
- // $likes = getStr($postPage, 'property="og:description" content="', ' Likes,');
- $likes = getStr($postPage, '"userInteractionCount":"', '"');
- return $likes;
- }
- protected function proccessSubmitKeIrvan($url, $jumlah)
- {
- // URL : instagram post url
- return $this->order(array(
- 'service' => $this->serviceId, // id layanan
- 'target' => $url, // target pesanan
- 'quantity' => $jumlah // jumlah pesan
- ));
- }
- private function connect($end_point, $post)
- {
- $_post = array();
- if (is_array($post)) {
- foreach ($post as $name => $value) {
- $_post[] = $name.'='.urlencode($value);
- }
- }
- $ch = curl_init($end_point);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- if (is_array($post)) {
- curl_setopt($ch, CURLOPT_POSTFIELDS, join('&', $_post));
- }
- curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
- $result = curl_exec($ch);
- if (curl_errno($ch) != 0 && empty($result)) {
- $result = false;
- }
- curl_close($ch);
- return $result;
- }
- }
- $cron = new Cronjob(
- getConfig('IRV_SERVICE'),
- getConfig('IRV_URL'),
- getConfig('IRV_API'),
- getConfig('IRV_APIID')
- );
- echo $cron->start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement