You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

106 lines
3.1 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2016/12/2
  6. * Time: 18:40
  7. */
  8. require_once __DIR__ . '/../../Utils/commonUtil.class.php';
  9. class utils extends commonUtils
  10. {
  11. static $format = "xml";
  12. static $encoding = 'utf-16';
  13. static $Language = 'CN';
  14. static $GUID = '38d28506-036c-4594-9d48-0771916ac3cc';
  15. static $Version = '1.0';
  16. //static $Url = "http://Supplier.elong.com/HotelAPI/V1.0/SouthBoundService.svc"; //正式环境
  17. static $Url = "http://test.directconnection.elong.com/HotelAPI/V1.0/SouthBoundService.svc"; //测试环境
  18. static public function setLoginToken($token)
  19. {
  20. self::$LoginToken = $token;
  21. }
  22. //生成Token
  23. static public function generateToken($UserName, $Password)
  24. {
  25. $user = array(
  26. "UserName" => $UserName,
  27. "Password" => $Password
  28. );
  29. $token = self::execute($user);
  30. self::setLoginToken($token);
  31. return $token;
  32. }
  33. static public function execute($request, $session = null)
  34. {
  35. $Url = 'http://' . str_replace(array('http://', 'https://'), '', self::$Url);
  36. $res = utils::http_post_xml($Url, $request);
  37. return $res;
  38. }
  39. /**
  40. * 组装请求艺龙接口的XML
  41. * @param $data
  42. * @param string $encoding
  43. * @param string $root
  44. * @return string
  45. */
  46. static public function xml_encode($data, $LoginToken, $root = "")
  47. {
  48. $encoding=self::$encoding;
  49. $GUID = self::$GUID;
  50. $Version = self::$Version;
  51. $xml = "<?xml version=\"1.0\" encoding=\"$encoding\"?>\n";
  52. $xml .= "<$root xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" >";
  53. $xml .= "<RequestHead><LoginToken>$LoginToken</LoginToken><GUID>$GUID</GUID><Version>$Version</Version></RequestHead>";
  54. $xml .= parent::data_to_xml($data);
  55. $xml .= "</$root>";
  56. return $xml;
  57. }
  58. /*
  59. * 验证post传递的参数是否合法
  60. * 默认提交的全是POST请求
  61. */
  62. static function validatePost()
  63. {
  64. $post = array();
  65. if (isset($_POST) && !empty($_POST)) {
  66. $post = array_merge($post, $_POST);
  67. }
  68. if (isset($_REQUEST) && !empty($_REQUEST)) {
  69. $post = array_merge($post, $_REQUEST);
  70. }
  71. if (isset($_GET) && !empty($_GET)) {
  72. $post = array_merge($post, $_GET);
  73. }
  74. if (!empty($post)) {
  75. if (isset($_POST['error']))
  76. unset($_POST['error']);
  77. foreach (array_keys($post) as $array_key) {
  78. if (!self::validateString($post[$array_key])) {
  79. return false;
  80. }
  81. }
  82. }
  83. return true;
  84. }
  85. /*
  86. * 验证参数是否合法
  87. * @return 合法:true 非法:false
  88. */
  89. static function validateString($str)
  90. {
  91. $check = 0;
  92. if (is_string($str))
  93. $check = preg_match('/select |insert |update |delete |union|into|load_file|outfile/', $str);
  94. return $check == 0 ? true : false;
  95. }
  96. }