getEnableTime.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. function SoapToXml($xml)
  3. {
  4. //api测试先关闭
  5. $startStr=strrpos($xml,"<![CDATA[");
  6. $endStr=strpos($xml,"]]>");
  7. $xml=substr($xml,$startStr,$endStr-$startStr);
  8. $xml = str_replace("<![CDATA[>","",$xml);
  9. $xml = str_replace("<![CDATA[","",$xml);
  10. $xml = str_replace("]]]]>","",$xml);
  11. $xml = str_replace("]]>","",$xml);
  12. $xml = str_replace("<ILLEGAL VALUE>","",$xml);
  13. return $xml;
  14. }
  15. date_default_timezone_set('PRC');
  16. $callback = isset($_GET['callback']) ? trim($_GET['callback']) : '';
  17. //==============获得前台请求==============
  18. $req['HospitalId'] = $_GET['hospitalId'];
  19. $req['startDate'] = $_GET['startDate'];
  20. $req['endDate'] = $_GET['endDate'];
  21. $req['deptId'] = $_GET['deptId'];
  22. if (isset($_GET['doctorId'])) {
  23. $req['doctorId'] = $_GET['doctorId'];
  24. }
  25. $day = $_GET['day']?$_GET['day']:1;
  26. $arr = array();
  27. $TradeCode = "1004";
  28. $ExtOrgCode = "南方医务通";
  29. $ExtUserID = "NFYWT";
  30. $ClientType ="";
  31. $HospitalId =$req['HospitalId'];
  32. $DeptType = "";
  33. $SessType = "";
  34. $StartDate = $req['startDate'];
  35. $EndDate = date('Y-m-d',(strtotime($req['startDate'])+$day*3600*24));
  36. $RBASSessionCode = "";
  37. $ServiceCode = "";
  38. $StopScheduleFlag = "";
  39. $DepartmentCode = $req['deptId'];
  40. $DoctorCode= empty($req['doctorId'])?'':$req['doctorId'];
  41. $callback = isset($_GET['callback']) ? trim($_GET['callback']) : '';
  42. $SearchCode = "";
  43. //$postData = "<Request><HospitalId>$HospitalId</HospitalId><ExtOrgCode>$ExtOrgCode</ExtOrgCode><ExtUserID>$ExtUserID</ExtUserID><ClientType>$ClientType</ClientType><TradeCode>$TradeCode</TradeCode><DeptType>$DeptType</DeptType><DoctorCode>$DoctorCode</DoctorCode><SessType>$SessType</SessType><StartDate>$StartDate</StartDate><EndDate>$EndDate</EndDate><RBASSessionCode>$RBASSessionCode</RBASSessionCode><ServiceCode>$ServiceCode</ServiceCode><StopScheduleFlag>$StopScheduleFlag</StopScheduleFlag><DepartmentCode>$DepartmentCode</DepartmentCode><SearchCode>$SearchCode</SearchCode></Request>";
  44. //$postData = str_replace(' ','%20',$postData);
  45. //$wsdl = "http://yygh1.dept.nfyy.com/csp/oep/DHC.OEP.BS.OEPSTANWebService.cls?soap_method=QuerySchedule&Input=";
  46. //$result = file_get_contents($wsdl.$postData);
  47. $url = "http://yygh1.dept.nfyy.com/csp/oep/DHC.OEP.BS.OEPSTANWebService.cls?soap_method=QuerySchedule&Input=<Request><HospitalId>$HospitalId</HospitalId><ExtOrgCode>$ExtOrgCode</ExtOrgCode><ExtUserID>$ExtUserID</ExtUserID><ClientType>$ClientType</ClientType><TradeCode>$TradeCode</TradeCode><DeptType>$DeptType</DeptType><DoctorCode>$DoctorCode</DoctorCode><SessType>$SessType</SessType><StartDate>$StartDate</StartDate><EndDate>$EndDate</EndDate><RBASSessionCode>$RBASSessionCode</RBASSessionCode><ServiceCode>$ServiceCode</ServiceCode><StopScheduleFlag>$StopScheduleFlag</StopScheduleFlag><DepartmentCode>$DepartmentCode</DepartmentCode><SearchCode>$SearchCode</SearchCode></Request>";
  48. //$url = "http://yygh1.dept.nfyy.com/csp/oep/DHC.OEP.BS.OEPSTANWebService.cls?soap_method=QuerySchedule&Input=<Request><HospitalId>$HospitalId</HospitalId><ExtOrgCode>南方医务通</ExtOrgCode><ExtUserID>NFYWT</ExtUserID><ClientType></ClientType><TradeCode>1004</TradeCode><DeptType></DeptType><DoctorCode>$DoctorCode</DoctorCode><SessType></SessType><StartDate>$StartDate</StartDate><EndDate>$EndDate</EndDate><RBASSessionCode></RBASSessionCode><ServiceCode></ServiceCode><StopScheduleFlag></StopScheduleFlag><DepartmentCode></DepartmentCode><SearchCode></SearchCode></Request>";
  49. //print_r($url);exit;
  50. ini_set('memory_limit', '256M');
  51. set_time_limit(0);
  52. $curl = curl_init();
  53. curl_setopt_array($curl, array(
  54. CURLOPT_URL => $url,
  55. CURLOPT_RETURNTRANSFER => true,
  56. CURLOPT_ENCODING => "",
  57. CURLOPT_MAXREDIRS => 10,
  58. CURLOPT_TIMEOUT => 30,
  59. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  60. CURLOPT_CUSTOMREQUEST => "GET",
  61. CURLOPT_HTTPHEADER => array(
  62. "cache-control: no-cache"
  63. ),
  64. CURLOPT_USERAGENT => "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;http://www.baidu.com)",
  65. ));
  66. $result = curl_exec($curl);
  67. $error = curl_error($curl);
  68. curl_close($curl);
  69. $res = SoapToXml($result);
  70. $res = simplexml_load_string($res);
  71. $res = json_encode($res);
  72. $res = json_decode($res,true);
  73. $times = array();
  74. for($i = $day-1; $i >=0;$i--) {
  75. $time = date('Y-m-d',strtotime($req['startDate'])+$i*3600*24);
  76. $times[$i]['time'] = $time;
  77. $times[$i]['count'] = 0;
  78. }
  79. if (isset($res['Schedules']['Schedule'])) {
  80. foreach ($res['Schedules']['Schedule'] as $k => $v ) {
  81. foreach ($times as $index => $time) {
  82. if ($time['time'] == $v ['ServiceDate']) {
  83. $times[$index]['count'] = intval($times[$index]['count']) + 1;
  84. break;
  85. }
  86. }
  87. }
  88. } else {
  89. $arr[0]['msg'] = '请求出错';
  90. $arr[0]['time'] = $StartDate;
  91. echo $callback . '(' . json_encode($arr) .')';exit;
  92. }
  93. foreach ($times as $k => $v) {
  94. if (intval($v['count']) == 0) {
  95. $arr[$k][$v['time']]= false;
  96. } else {
  97. $arr[$k][$v['time']]= true;
  98. }
  99. }
  100. echo $callback . '(' . json_encode($arr) .')';exit;
  101. ?>