Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. <?php
  2.  
  3. function access_api($url, $method, $data)
  4.  
  5. {
  6.  
  7. $api = 'http://innodev.vnetcloud.com/ParkingSystemAPI/public/'.$url;
  8. // $api = 'http://10.118.45.20/ParkingSystemAPI/public/'.$url;
  9.  
  10. $curl = curl_init();
  11. $headers = array(
  12. "content-type: multipart/form-data",
  13. // "content-type: application/x-www-form-urlencoded"
  14. );
  15. curl_setopt($curl, CURLOPT_URL, $api);
  16. curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
  17. curl_setopt($curl, CURLOPT_TIMEOUT, 30);
  18. curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
  19. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  20.  
  21. if ($method == "POST") {
  22. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
  23. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  24. } elseif ($method == "PUT") {
  25. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
  26. // curl_setopt($curl, CURLOPT_PUT, true);
  27. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  28. } elseif ($method == "DELETE") {
  29. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
  30. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  31. } else {
  32. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
  33. }
  34.  
  35. $response = curl_exec($curl);
  36. $err = curl_error($curl);
  37. curl_close($curl);
  38.  
  39. if ($err) {
  40. // return "cURL Error #:" . $err;
  41. return \Response::view('errors.500',array(),500);
  42. } else {
  43. return json_decode($response);
  44. }
  45.  
  46.  
  47. }
  48.  
  49. function replace_money($money)
  50. {
  51. $number = str_replace(' ','',str_replace('Rp', '', str_replace('.', '', $money)));
  52.  
  53. return $number;
  54. }
  55.  
  56. function generate_code($length){
  57.  
  58. $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  59. $charactersLength = strlen($characters);
  60. $randomString = '';
  61. for ($i = 0; $i < $length; $i++) {
  62. $randomString .= $characters[rand(0, $charactersLength - 1)];
  63. }
  64. return $randomString;
  65. }
  66.  
  67.  
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement