Advertisement
Guest User

Untitled

a guest
May 5th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. <?php
  2. class Api
  3. {
  4. public $api_url = 'http://sosmedpedia.com/api.php'; // API URL
  5.  
  6. public $api_key = ''; // Your API key
  7.  
  8. public function order($link, $type, $quantity) { // Add order
  9. return json_decode($this->connect(array(
  10. 'api' => $this->api_key,
  11. 'action' => 'tambah',
  12. 'linknya' => $link,
  13. 'hasilnya' => $type,
  14. 'quantitynya' => $quantity
  15. )));
  16. }
  17.  
  18. public function status($order_id) { // Get status, remains
  19. return json_decode($this->connect(array(
  20. 'api' => $this->api_key,
  21. 'action' => 'cekin',
  22. 'id' => $order_id
  23. )));
  24. }
  25.  
  26.  
  27. private function connect($post) {
  28. $_post = Array();
  29. if (is_array($post)) {
  30. foreach ($post as $name => $value) {
  31. $_post[] = $name.'='.urlencode($value);
  32. }
  33. }
  34. $ch = curl_init($this->api_url);
  35. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  36. curl_setopt($ch, CURLOPT_POST, 1);
  37. curl_setopt($ch, CURLOPT_HEADER, 0);
  38. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  39. if (is_array($post)) {
  40. curl_setopt($ch, CURLOPT_POSTFIELDS, join('&', $_post));
  41. }
  42. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  43. $result = curl_exec($ch);
  44. echo $result;
  45. if (curl_errno($ch) != 0 && empty($result)) {
  46. $result = false;
  47. }
  48. curl_close($ch);
  49. return $result;
  50. }
  51. }
  52.  
  53.  
  54.  
  55. require_once('db/koneksi.php');
  56.  
  57. $datanyawkwkwk = mysql_query("SELECT * FROM orders order by id DESC");
  58.  
  59. while($hasilwkwkwk= mysql_fetch_array($datanyawkwkwk)){
  60. $idbulk = $hasilwkwkwk['idbulk'];
  61. $status = $hasilwkwkwk['status'];
  62. $api = new Api();
  63.  
  64.  
  65. $status = $api->status($idbulk); // $order_id: return Order status, return Remains or Error
  66. $statuse = $status->data->statusnya;
  67. $start_countnya = $status->data->start_count;
  68. $update1212= mysql_query("update orders set status='$statuse', start_count='$start_countnya' where idbulk='$idbulk'");
  69. echo"$statuse";
  70. }
  71. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement