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(){
- $this->curl = new Curl();
- $this->api_url = 'https://irvankede-smm.co.id/api/'; // API Url
- $this->api_key = 'XwQv50s-Qfgbhzi-ydQgpH5-9ujvKaf'; // API Key
- $this->postFile = $this->appPath($this->postFile);
- }
- 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],
- ];
- }
- function postLikeServer1($url, $jumlah){
- // always set cookies before doing anything
- $this->curl->setHeader('Cookie', $this->getCookie());
- $service = '732';
- $order = $this->order(array('service' => $service, 'target' => $url, 'quantity' => $jumlah));;
- if($order->status){
- $this->deleteFirstLine();
- return $this->writeToSleepy('sukses', 'Sukses bro : '. $url .' - Jumlah : '. $jumlah);
- }
- $gagalMessage = getStr($order, 'Failed!', '<');
- return $this->writeToSleepy('gagal', ' !! GAGAL !! : '. $url . ' - Jumlah : '. $jumlah .' - gagalMessage : '. $gagalMessage);
- }
- public function order($data) {
- return json_decode($this->connect($this->api_url.'order', array_merge(array('api_key' => $this->api_key), $data)));
- }
- public function status($order_id) {
- return json_decode($this->connect($this->api_url.'status', array('api_key' => $this->api_key, 'id' => $order_id)));
- }
- 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, true);
- 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;
- }
- public function start(){
- $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->postLikeServer1($data['url'], $data['jumlah']);
- }
- }
- $api = new Cronjob();
- echo $api->start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement