Advertisement
Guest User

test

a guest
Jul 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 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(){
  11. $this->curl = new Curl();
  12. $this->api_url = 'https://irvankede-smm.co.id/api/'; // API Url
  13. $this->api_key = 'XwQv50s-Qfgbhzi-ydQgpH5-9ujvKaf'; // API Key
  14. $this->postFile = $this->appPath($this->postFile);
  15. }
  16.  
  17.  
  18. public function getFirstLine(){
  19. $loadFile = file_get_contents($this->postFile);
  20. $toArray = explode("\n", $loadFile);
  21. return trim($toArray[0]);
  22. }
  23.  
  24. public function deleteFirstLine(){
  25. $loadFile = file_get_contents($this->postFile);
  26. $toArray = explode("\n", $loadFile);
  27. array_shift($toArray);
  28. file_put_contents($this->postFile, implode("\n", $toArray));
  29. }
  30.  
  31. public function writeToSleepy($file, $txt){
  32. $path = $this->appPath('sleepy/'. $file .'.txt');
  33. $openFile = fopen($path, "a");
  34.  
  35. $logSomething = '[ '. time_id(time()) .'] '. $txt;
  36.  
  37. fwrite($openFile, $logSomething."\n\n");
  38. fclose($openFile);
  39.  
  40. return $logSomething;
  41. }
  42.  
  43. public function appPath($file){
  44. return dirname(__FILE__). '/'. $file;
  45. }
  46.  
  47. public function getUrldanJumlah($firstLine){
  48. $array = explode('|', $firstLine);
  49.  
  50. if(!isset($array[0])
  51. || !isset($array[1])
  52. || $array[0] == ''
  53. || $array[1] == ''
  54. ){
  55. return null;
  56. }
  57.  
  58. return [
  59. 'url' => $array[0],
  60. 'jumlah' => $array[1],
  61. ];
  62. }
  63.  
  64. function postLikeServer1($url, $jumlah){
  65.  
  66. // always set cookies before doing anything
  67. $this->curl->setHeader('Cookie', $this->getCookie());
  68.  
  69. $service = '732';
  70. $order = $this->order(array('service' => $service, 'target' => $url, 'quantity' => $jumlah));;
  71.  
  72. if($order->status){
  73. $this->deleteFirstLine();
  74. return $this->writeToSleepy('sukses', 'Sukses bro : '. $url .' - Jumlah : '. $jumlah);
  75. }
  76.  
  77. $gagalMessage = getStr($order, 'Failed!', '<');
  78. return $this->writeToSleepy('gagal', ' !! GAGAL !! : '. $url . ' - Jumlah : '. $jumlah .' - gagalMessage : '. $gagalMessage);
  79.  
  80. }
  81.  
  82. public function order($data) {
  83. return json_decode($this->connect($this->api_url.'order', array_merge(array('api_key' => $this->api_key), $data)));
  84. }
  85.  
  86. public function status($order_id) {
  87. return json_decode($this->connect($this->api_url.'status', array('api_key' => $this->api_key, 'id' => $order_id)));
  88. }
  89.  
  90. private function connect($end_point, $post) {
  91. $_post = Array();
  92. if (is_array($post)) {
  93. foreach ($post as $name => $value) {
  94. $_post[] = $name.'='.urlencode($value);
  95. }
  96. }
  97. $ch = curl_init($end_point);
  98. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  99. curl_setopt($ch, CURLOPT_POST, 1);
  100. curl_setopt($ch, CURLOPT_HEADER, 0);
  101. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  102. if (is_array($post)) {
  103. curl_setopt($ch, CURLOPT_POSTFIELDS, join('&', $_post));
  104. }
  105. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  106. $result = curl_exec($ch);
  107. if (curl_errno($ch) != 0 && empty($result)) {
  108. $result = false;
  109. }
  110. curl_close($ch);
  111. return $result;
  112. }
  113.  
  114. public function start(){
  115. $firstLine = $this->getFirstLine();
  116.  
  117. if($firstLine == '' || $firstLine == null){
  118. return 'File kosong... isi dulu link nya di '. $this->postFile;
  119. }
  120.  
  121. $data = $this->getUrldanJumlah($firstLine);
  122.  
  123. if(!$data) {
  124. $this->deleteFirstLine();
  125. return $this->writeToSleepy('gagal', 'FORMAT SALAH - Ngisi yang bener : '. $firstLine);
  126. }
  127.  
  128. return $this->postLikeServer1($data['url'], $data['jumlah']);
  129. }
  130. }
  131.  
  132.  
  133. $api = new Cronjob();
  134.  
  135. echo $api->start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement