No Description

Example.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. include_once ('com/alibaba/china/openapi/client/example/ExampleFacade.class.php');
  3. include_once ('com/alibaba/china/openapi/client/example/param/apiexample/ExampleFamilyGetParam.class.php');
  4. include_once ('com/alibaba/china/openapi/client/example/param/apiexample/ExampleFamilyPostParam.class.php');
  5. include_once ('com/alibaba/china/openapi/client/example/param/apiexample/ExampleFamilyGetResult.class.php');
  6. include_once ('com/alibaba/china/openapi/client/example/param/apiexample/ExampleFamilyPostResult.class.php');
  7. include_once ('com/alibaba/openapi/client/entity/ByteArray.class.php');
  8. include_once ('com/alibaba/openapi/client/util/DateUtil.class.php');
  9. $exampleFacade = new ExampleFacade ();
  10. $exampleFacade->setAppKey ( "Your appKey" );
  11. $exampleFacade->setSecKey ( "Your appSecret" );
  12. $exampleFacade->setServerHost ( "server host" );
  13. //you need change this refresh token when you run this example.
  14. $testRefreshToken ="6291ea7b-8658-4cea-9e45-b880d66e2d11";
  15. try {
  16. // --------------------------first example starting----------------------------------
  17. $param = new ExampleFamilyGetParam ();
  18. $param->setFamilyNumber ( 1 );
  19. $exampleFamilyGetResult = new ExampleFamilyGetResult ();
  20. $exampleFacade->exampleFamilyGet ( $param, $exampleFamilyGetResult );
  21. $exampleFamily = $exampleFamilyGetResult->getResult ();
  22. echo "ExampleFamilyGet call get the result, the familyNumber is ";
  23. echo $exampleFamilyGetResult->getResult ()->getFamilyNumber ();
  24. echo " and the name of father is ";
  25. echo $exampleFamilyGetResult->getResult ()->getFather ()->getName ();
  26. echo ", the birthday of fanther is ";
  27. echo $exampleFamilyGetResult->getResult ()->getFather ()->getBirthday ();
  28. echo "<br/>";
  29. // ----------------------------first example end-------------------------------------
  30. // --------------------------second example starting----------------------------------
  31. $exampleFamilyPostParam = new ExampleFamilyPostParam ();
  32. // set the simple parameter
  33. $exampleFamilyPostParam->setComments ( "SDK Example" );
  34. // set a complex domain as parameter
  35. $exampleFamily = new ExampleFamily ();
  36. $exampleFamily->setFamilyNumber ( 12 );
  37. $exampleFather = new ExamplePerson ();
  38. $exampleFather->setAge ( 31 );
  39. $exampleFather->setBirthday ( "19780312101010000" );
  40. $exampleFather->setName ( "John" );
  41. $exampleFamily->setFather ( $exampleFather );
  42. $exampleFamilyPostParam->setFamily ( $exampleFamily );
  43. // simulate the feature of upload image.
  44. $fileContent = file_get_contents ( "example.png" );
  45. $houseImg = new ByteArray ();
  46. $houseImg->setBytesValue ( $fileContent );
  47. $exampleFamilyPostParam->setHouseImg ( $houseImg );
  48. $authorizationToken = $exampleFacade->refreshToken($testRefreshToken);
  49. echo "refresh token:";
  50. echo $authorizationToken->getAccessToken();
  51. echo "<br/>";
  52. $exampleFamilyPostResult = new ExampleFamilyPostResult ();
  53. $exampleFacade->exampleFamilyPost ( $exampleFamilyPostParam, $authorizationToken->getAccessToken(), $exampleFamilyPostResult );
  54. echo "ExampleFamilyPost call get the result, the descriptin of result is ";
  55. echo $exampleFamilyPostResult->getResultDesc ();
  56. echo "<br/>";
  57. echo "ExampleFamilyPost call get the result, the father name upset is ";
  58. echo $exampleFamilyPostResult->getResult ()->getFather ()->getName ();
  59. // --------------------------second example starting----------------------------------
  60. } catch ( OceanException $ex ) {
  61. echo "Exception occured with code[";
  62. echo $ex->getErrorCode ();
  63. echo "] message [";
  64. echo $ex->getMessage ();
  65. echo "].";
  66. }
  67. ?>