Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]API
szymon202
post
Post #1





Grupa: Zarejestrowani
Postów: 152
Pomógł: 0
Dołączył: 13.08.2013

Ostrzeżenie: (0%)
-----


Kod do odbierania statusu:
  1. <?php
  2. if (isset($_POST['check_code']) && isset($_POST['code'])) {
  3.  
  4. $code = $_POST['code'];
  5.  
  6. $api = @file_get_contents("http://xxx.net/api/api.php?code=$code");
  7.  
  8. if(isset($api)) {
  9. $api = json_decode($api);
  10.  
  11. if(isset($api->error) && $api->error) {
  12. echo $api->error;
  13. } else {
  14. if($api->status=="OK") {
  15. echo 'Poprawny kod. Doładowuję '.$api->cash.' zł';
  16. } else {
  17. echo 'Błędny kod';
  18. }
  19. }
  20. } else {
  21. echo 'Brak połączenia z API';
  22. }
  23. }
  24.  
  25. ?>
  26.  
  27. <form method="post">
  28. <h4>Kod SMS</h4>
  29. <input class="form-control" type="text" name="code" class="text" size="15" value="" /><br>
  30. <input name="check_code" type="submit" value="Sprawdz" />
  31. </form>


Kod API:
  1. <?php
  2. $settings['userid'] = 1;
  3. $settings['serviceid'] = 1;
  4. $code = $_GET['code'];
  5.  
  6. $microsms[] = array("netto" => 0.50,"number" => 7055,"product" => "kawamintai");
  7. $handle = fopen("http://xxx.xxx.xxx/check_multi.php?userid=" . $settings['userid'] . "&code=" . $code . '&serviceid=' . $settings['serviceid'], 'r');
  8. $check = fgetcsv($handle, 1024);
  9. fclose($handle);
  10.  
  11. header("Content-Type:application/json");
  12. if(!empty($_GET['code'])) {
  13. $code=$_GET['code'];
  14. $ok = $check[0] == 1;
  15. if($code == $ok) {
  16. deliver_response("OK","1.23","OK_CODE");
  17. } else {
  18. deliver_response("FAIL",NULL,"BAD_CODE");
  19. }
  20. }
  21.  
  22. function deliver_response($status, $cash, $error) {
  23. header("HTTP/1.1 $status $cash");
  24.  
  25. $response['status']=$status;
  26. $response['cash']=$cash;
  27. $response['error']=$error;
  28.  
  29. $json_response=json_encode($response);
  30. echo $json_response;
  31. }
  32. ?>


Za każdym razem w formularzu zwraca błędny kod, a wchodząc przez link z API jest dobrze i zwraca OK.
Dodam, że kod zużywa, ale pisze Błędny kod.

@ref

Ten post edytował szymon202 18.03.2015, 17:10:36
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 23:57