Advertisement
Guest User

Untitled

a guest
Oct 4th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. <?php
  2.  
  3. namespace PollyCodes\Load4wrd;
  4.  
  5. use Illuminate\Http\Request;
  6. use App\Http\Requests;
  7. use App\Http\Controllers\Controller;
  8. use Illuminate\Support\Facades\Config;
  9.  
  10. class Loading extends Controller
  11. {
  12. public function Balance() {
  13. $response = $this->curl(null, "balance");
  14. return $response;
  15. }
  16.  
  17. public function Product_Codes($network = null) {
  18. $data = null;
  19. if($network != null) {
  20. $data = array(
  21. "network" => $network
  22. );
  23. }
  24. $response = $this->curl($data, "product-codes");
  25. return $response;
  26. }
  27.  
  28. public function Check_Product_Code($code) {
  29. $data = array(
  30. "code" => $code
  31. );
  32. $response = $this->curl($data, "check-product-code");
  33. return $response;
  34. }
  35.  
  36. public function Send($target, $code) {
  37. $data = array(
  38. "target" => $target,
  39. "code" => $code
  40. );
  41. $response = $this->curl($data, "load");
  42. return $response;
  43. }
  44.  
  45. public function curl($data, $command) {
  46. $services = Config::get("services")["load4wrd"];
  47. $username = $services["username"];
  48. $password = $services["password"];
  49. $authorization = base64_encode($username . ":" . $password);
  50.  
  51. switch ($command) {
  52. case 'load':
  53. $url = "https://load4wrd.kpa.ph/api/v1/load";
  54. break;
  55.  
  56. case 'product-codes':
  57. $url = "https://load4wrd.kpa.ph/api/v1/product-codes";
  58. break;
  59.  
  60. case 'check-product-code':
  61. $url = "https://load4wrd.kpa.ph/api/v1/check-product-code";
  62. break;
  63.  
  64. default:
  65. $url = "https://load4wrd.kpa.ph/api/v1/balance";
  66. break;
  67. }
  68.  
  69. // to json
  70. $to_json = json_encode($data);
  71.  
  72. // Added JSON Header
  73. $headers = array(
  74. "Authorization: Basic ". $authorization,
  75. "Content-Type: application/json"
  76. );
  77.  
  78. $ch = curl_init($url);
  79. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
  80. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  81. curl_setopt($ch, CURLOPT_POSTFIELDS, $to_json);
  82. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  83. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  84. $result = json_decode(curl_exec($ch), true);
  85. curl_close($ch);
  86.  
  87. return $result;
  88. }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement