Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.74 KB | None | 0 0
  1. <?php
  2. include dirname(__FILE__).'/../vendor/autoload.php';
  3.  
  4. use Curl\Curl;
  5.  
  6. class Cronjob
  7. {
  8. protected $postFile = 'Post.txt';
  9.  
  10. public function __construct($serviceId, $url, $api, $apiId)
  11. {
  12. $this->curl = new Curl();
  13. $this->postFile = $this->appPath($this->postFile);
  14. $this->lastOrderIdFile = dirname(__FILE__).'/LastOrderId.txt';
  15.  
  16. // IRVAN-KEDE CREDENTIALS
  17. $this->irvUrl = $url;
  18. $this->irvApi = $api;
  19. $this->irvApiId = $apiId;
  20. $this->serviceId = $serviceId;
  21. }
  22.  
  23. public function getFirstLine()
  24. {
  25. $loadFile = file_get_contents($this->postFile);
  26. $toArray = explode("\n", $loadFile);
  27.  
  28. return trim($toArray[0]);
  29. }
  30.  
  31. public function deleteFirstLine()
  32. {
  33. $loadFile = file_get_contents($this->postFile);
  34. $toArray = explode("\n", $loadFile);
  35. array_shift($toArray);
  36. file_put_contents($this->postFile, implode("\n", $toArray));
  37. }
  38.  
  39. public function writeToSleepy($file, $txt)
  40. {
  41. $path = $this->appPath('sleepy/'. $file .'.txt');
  42. $openFile = fopen($path, "a");
  43.  
  44. $logSomething = '[ '. time_id(time()) .'] '. $txt;
  45.  
  46. fwrite($openFile, $logSomething."\n\n");
  47. fclose($openFile);
  48.  
  49. return $logSomething;
  50. }
  51.  
  52. public function appPath($file)
  53. {
  54. return dirname(__FILE__). '/'. $file;
  55. }
  56.  
  57. public function getUrldanJumlah($firstLine)
  58. {
  59. $array = explode('|', $firstLine);
  60.  
  61. if ( ! isset($array[0])
  62. || ! isset($array[1])
  63. || $array[0] == ''
  64. || $array[1] == ''
  65. ) {
  66. return null;
  67. }
  68.  
  69. return [
  70. 'url' => $array[0],
  71. 'jumlah' => $array[1],
  72. ];
  73. }
  74.  
  75. public function putLastOrderId($orderId, $startLikes, $url)
  76. {
  77. $format = $orderId.'|'.$startLikes.'|'.$url;
  78.  
  79. return file_put_contents($this->lastOrderIdFile, $format);
  80. }
  81.  
  82. public function submitKeIrvSMM($url, $jumlah)
  83. {
  84. $json = $this->proccessSubmitKeIrvan($url, $jumlah);
  85.  
  86. // If successfully
  87. if ($json->status == 1) {
  88. // $this->deleteFirstLine();
  89. $orderId = $json->data->id;
  90. $startLikes = $this->checkLikesInstagramPost($url);
  91.  
  92. $this->putLastOrderId($orderId, $startLikes, $url);
  93.  
  94. return $this->writeToSleepy(
  95. 'sukses',
  96. 'Sukses bro : '. $url .' - Jumlah : '. $jumlah .' - With OrderID : '. $orderId
  97. );
  98. }
  99.  
  100. // If Failed
  101. $gagalMessage = json_encode($json);
  102.  
  103. return $this->writeToSleepy(
  104. 'gagal',
  105. ' !! GAGAL !! : '. $url . ' - Jumlah : '. $jumlah .' - gagalMessage : '. $gagalMessage
  106. );
  107. }
  108.  
  109. public function selectTextAndSubmit()
  110. {
  111. $firstLine = $this->getFirstLine();
  112.  
  113. if ($firstLine == '' || $firstLine == null) {
  114. return 'File kosong... isi dulu link nya di '. $this->postFile;
  115. }
  116.  
  117. $data = $this->getUrldanJumlah($firstLine);
  118.  
  119. if ( ! $data) {
  120. $this->deleteFirstLine();
  121.  
  122. return $this->writeToSleepy(
  123. 'gagal',
  124. 'FORMAT SALAH - Ngisi yang bener : '. $firstLine
  125. );
  126. }
  127.  
  128. return $this->submitKeIrvSMM($data['url'], $data['jumlah']);
  129. }
  130.  
  131. public function start()
  132. {
  133. $lastOrderId = file_get_contents($this->lastOrderIdFile);
  134. $rawId = explode('|', $lastOrderId);
  135. $rawJson = $this->status($lastOrderId = $rawId[0]);
  136. $lastOrderStatus = $rawJson->data->status;
  137. $rawLikes = $rawId[1] + 75;
  138. $checkLikes = $this->checkLikesInstagramPost($rawId[2]);
  139.  
  140. if ($checkLikes <= $rawLikes) {
  141. if ($lastOrderStatus == 'Pending' || $lastOrderStatus == 'Processing') {
  142. print_r($this->getUrldanJumlah($this->getFirstLine()));
  143. echo '<hr>';
  144. print_r($rawJson);
  145. echo '<hr>';
  146. echo "LIKES ON POST : ". $checkLikes;
  147. echo '<hr>';
  148.  
  149. return 'Still waiting orderId : <b>'. $lastOrderId .'</b> to be successfull.';
  150. }
  151. }
  152.  
  153. if ($checkLikes > $rawLikes) {
  154. $this->deleteFirstLine();
  155. }
  156.  
  157. // Re-submit
  158. if ($lastOrderStatus == 'Partial') {
  159. return $this->selectTextAndSubmit();
  160. }
  161.  
  162. if ($lastOrderStatus == 'Success') {
  163. $this->deleteFirstLine();
  164. }
  165.  
  166. return $this->selectTextAndSubmit();
  167. }
  168.  
  169. // FROM EXAMPLE IRVAN-KEDE API
  170. public function order($data)
  171. {
  172. return json_decode($this->connect($this->irvUrl.'order', array_merge(array('api_id' => $this->irvApiId, 'api_key' => $this->irvApi), $data)));
  173. }
  174.  
  175. public function status($order_id)
  176. {
  177. return json_decode($this->connect($this->irvUrl.'status', array('api_id' => $this->irvApiId, 'api_key' => $this->irvApi, 'id' => $order_id)));
  178. }
  179.  
  180. protected function checkLikesInstagramPost($url)
  181. {
  182. $url = str_finish($url, '/');
  183. $postPage = httpGet($url);
  184. // $likes = getStr($postPage, 'property="og:description" content="', ' Likes,');
  185. $likes = getStr($postPage, '"userInteractionCount":"', '"');
  186.  
  187. return $likes;
  188. }
  189.  
  190. protected function proccessSubmitKeIrvan($url, $jumlah)
  191. {
  192. // URL : instagram post url
  193. return $this->order(array(
  194. 'service' => $this->serviceId, // id layanan
  195. 'target' => $url, // target pesanan
  196. 'quantity' => $jumlah // jumlah pesan
  197. ));
  198. }
  199.  
  200. private function connect($end_point, $post)
  201. {
  202. $_post = array();
  203. if (is_array($post)) {
  204. foreach ($post as $name => $value) {
  205. $_post[] = $name.'='.urlencode($value);
  206. }
  207. }
  208. $ch = curl_init($end_point);
  209. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  210. curl_setopt($ch, CURLOPT_POST, 1);
  211. curl_setopt($ch, CURLOPT_HEADER, 0);
  212. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  213. if (is_array($post)) {
  214. curl_setopt($ch, CURLOPT_POSTFIELDS, join('&', $_post));
  215. }
  216. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  217. $result = curl_exec($ch);
  218. if (curl_errno($ch) != 0 && empty($result)) {
  219. $result = false;
  220. }
  221. curl_close($ch);
  222.  
  223. return $result;
  224. }
  225. }
  226.  
  227. $cron = new Cronjob(
  228. getConfig('IRV_SERVICE'),
  229. getConfig('IRV_URL'),
  230. getConfig('IRV_API'),
  231. getConfig('IRV_APIID')
  232. );
  233.  
  234. echo $cron->start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement