demo.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. require_once dirname(__FILE__) . '/PhalApiClient.php';
  3. $client = PhalApiClient::create()
  4. ->withHost('http://demo.phalapi.net/');
  5. $rs = $client->reset()
  6. ->withService('Default.Index')
  7. ->withParams('username', 'dogstar')
  8. ->withTimeout(3000)
  9. ->request();
  10. var_dump($rs->getRet());
  11. echo "\n";
  12. var_dump($rs->getData());
  13. echo "\n";
  14. var_dump($rs->getMsg());
  15. /**
  16. int(200)
  17. array(4) {
  18. ["title"]=>
  19. string(12) "Hello World!"
  20. ["content"]=>
  21. string(36) "dogstar您好,欢迎使用PhalApi!"
  22. ["version"]=>
  23. string(5) "1.2.1"
  24. ["time"]=>
  25. int(1444925238)
  26. }
  27. string(0) ""
  28. */
  29. echo "\n--------------------\n";
  30. //one more time
  31. $rs = $client->reset()
  32. ->withService("User.GetBaseInfo")
  33. ->withParams("user_id", "1")
  34. ->request();
  35. var_dump($rs->getRet());
  36. echo "\n";
  37. var_dump($rs->getData());
  38. echo "\n";
  39. var_dump($rs->getMsg());
  40. echo "\n--------------------\n";
  41. //illegal request
  42. $rs = $client->reset()
  43. ->withService("XXX.XXXXX")
  44. ->withParams("user_id", "1")
  45. ->request();
  46. var_dump($rs->getRet());
  47. echo "\n";
  48. var_dump($rs->getData());
  49. echo "\n";
  50. var_dump($rs->getMsg());