No Description

Param2RequestSerializer.class.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. include_once (app_path('/libs/Umeng/').'com/alibaba/openapi/client/serialize/Serializer.php');
  3. include_once (app_path('/libs/Umeng/').'com/alibaba/openapi/client/policy/DataProtocol.class.php');
  4. include_once (app_path('/libs/Umeng/').'com/alibaba/openapi/client/entity/ByteArray.class.php');
  5. include_once (app_path('/libs/Umeng/').'com/alibaba/openapi/client/entity/SDKDomain.class.php');
  6. include_once (app_path('/libs/Umeng/').'com/alibaba/openapi/client/util/SDKDomainUtil.class.php');
  7. class Param2RequestSerializer implements Serializer {
  8. public function supportedContentType() {
  9. return DataProtocol::param2;
  10. }
  11. public function serialize($serializer) {
  12. $serializedResult = array ();
  13. if($serializer==null){
  14. return $serializedResult;
  15. }
  16. $ref = new ReflectionObject ( $serializer );
  17. $sdkStdResultArray = null;
  18. foreach ( $ref->getMethods () as $tempMethod ) {
  19. $methodName = $tempMethod->name;
  20. if ("getSdkStdResult" == $methodName) {
  21. $sdkStdResultArray = $tempMethod->invoke ( $serializer );
  22. }
  23. }
  24. if ($sdkStdResultArray == null) {
  25. foreach ( $ref->getMethods () as $tempMethod ) {
  26. $methodName = $tempMethod->name;
  27. if (strpos ( $methodName, "get" ) === 0 && "getSdkStdResult" != $methodName) {
  28. $propertyName = substr ( $methodName, 3 );
  29. $propertyName = lcfirst ( $propertyName );
  30. $resultValue = $tempMethod->invoke ( $serializer );
  31. if (($resultValue instanceof DateTime)) {
  32. $timeValue =$resultValue->getTimestamp();
  33. $strTime = DateUtil::parseToString ($timeValue );
  34. $serializedResult [$propertyName] = $strTime;
  35. } else if (($resultValue instanceof ByteArray)) {
  36. $tempValue = base64_encode ( $resultValue->getByteValue () );
  37. $serializedResult [$propertyName] = $tempValue;
  38. } else if (($resultValue instanceof SDKDomain)) {
  39. $sdkDomainUtil = new SDKDomainUtil ();
  40. $tempArray = $sdkDomainUtil->generateSDKDomainArray ( $resultValue );
  41. $resultJsonValue = json_encode ( $tempArray );
  42. $serializedResult [$propertyName] = $resultJsonValue;
  43. } else if (is_array ( $resultValue )) {
  44. $resultJsonValue = json_encode ( $resultValue );
  45. $serializedResult [$propertyName] = $resultJsonValue;
  46. } else {
  47. $serializedResult [$propertyName] = $resultValue;
  48. }
  49. }
  50. }
  51. } else {
  52. foreach ( $sdkStdResultArray as $k => $v ) {
  53. $resultValue = $v;
  54. if (($resultValue instanceof DateTime)) {
  55. $timeValue =$resultValue->getTimestamp();
  56. $strTime = DateUtil::parseToString ($timeValue );
  57. $serializedResult [$k] = $strTime;
  58. } else if (($resultValue instanceof ByteArray)) {
  59. $tempValue = base64_encode ( $resultValue->getByteValue () );
  60. $serializedResult [$k] = $tempValue;
  61. } else if (($resultValue instanceof SDKDomain)) {
  62. $sdkDomainUtil = new SDKDomainUtil ();
  63. $tempArray = $sdkDomainUtil->generateSDKDomainArray ( $resultValue );
  64. $resultJsonValue = json_encode ( $tempArray );
  65. $serializedResult [$k] = $resultJsonValue;
  66. } else if (is_array ( $resultValue )) {
  67. $resultJsonValue = json_encode ( $resultValue );
  68. $serializedResult [$k] = $resultJsonValue;
  69. } else {
  70. $serializedResult [$k] = $resultValue;
  71. }
  72. }
  73. }
  74. return $serializedResult;
  75. }
  76. }
  77. ?>