123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- function SoapToXml($xml)
- {
- //api测试先关闭
- $startStr=strrpos($xml,"<![CDATA[");
- $endStr=strpos($xml,"]]>");
- $xml=substr($xml,$startStr,$endStr-$startStr);
- $xml = str_replace("<![CDATA[>","",$xml);
- $xml = str_replace("<![CDATA[","",$xml);
- $xml = str_replace("]]]]>","",$xml);
- $xml = str_replace("]]>","",$xml);
- $xml = str_replace("<ILLEGAL VALUE>","",$xml);
- return $xml;
- }
- date_default_timezone_set('PRC');
- $callback = isset($_GET['callback']) ? trim($_GET['callback']) : '';
- //==============获得前台请求==============
- $req['HospitalId'] = $_GET['hospitalId'];
- $req['startDate'] = $_GET['startDate'];
- $req['endDate'] = $_GET['endDate'];
- $req['deptId'] = $_GET['deptId'];
- if (isset($_GET['doctorId'])) {
- $req['doctorId'] = $_GET['doctorId'];
- }
- $day = $_GET['day']?$_GET['day']:1;
- $arr = array();
- $TradeCode = "1004";
- $ExtOrgCode = "南方医务通";
- $ExtUserID = "NFYWT";
- $ClientType ="";
- $HospitalId =$req['HospitalId'];
- $DeptType = "";
- $SessType = "";
- $StartDate = $req['startDate'];
- $EndDate = date('Y-m-d',(strtotime($req['startDate'])+$day*3600*24));
- $RBASSessionCode = "";
- $ServiceCode = "";
- $StopScheduleFlag = "";
- $DepartmentCode = $req['deptId'];
- $DoctorCode= empty($req['doctorId'])?'':$req['doctorId'];
- $callback = isset($_GET['callback']) ? trim($_GET['callback']) : '';
- $SearchCode = "";
- //$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>";
- //$postData = str_replace(' ','%20',$postData);
- //$wsdl = "http://yygh1.dept.nfyy.com/csp/oep/DHC.OEP.BS.OEPSTANWebService.cls?soap_method=QuerySchedule&Input=";
- //$result = file_get_contents($wsdl.$postData);
- $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>";
- //$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>";
- //print_r($url);exit;
- ini_set('memory_limit', '256M');
- set_time_limit(0);
- $curl = curl_init();
- curl_setopt_array($curl, array(
- CURLOPT_URL => $url,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_ENCODING => "",
- CURLOPT_MAXREDIRS => 10,
- CURLOPT_TIMEOUT => 30,
- CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
- CURLOPT_CUSTOMREQUEST => "GET",
- CURLOPT_HTTPHEADER => array(
- "cache-control: no-cache"
- ),
- CURLOPT_USERAGENT => "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;http://www.baidu.com)",
- ));
- $result = curl_exec($curl);
- $error = curl_error($curl);
- curl_close($curl);
- $res = SoapToXml($result);
- $res = simplexml_load_string($res);
- $res = json_encode($res);
- $res = json_decode($res,true);
- $times = array();
- for($i = $day-1; $i >=0;$i--) {
- $time = date('Y-m-d',strtotime($req['startDate'])+$i*3600*24);
- $times[$i]['time'] = $time;
- $times[$i]['count'] = 0;
- }
- if (isset($res['Schedules']['Schedule'])) {
- foreach ($res['Schedules']['Schedule'] as $k => $v ) {
- foreach ($times as $index => $time) {
- if ($time['time'] == $v ['ServiceDate']) {
- $times[$index]['count'] = intval($times[$index]['count']) + 1;
- break;
- }
- }
- }
- } else {
- $arr[0]['msg'] = '请求出错';
- $arr[0]['time'] = $StartDate;
- echo $callback . '(' . json_encode($arr) .')';exit;
- }
- foreach ($times as $k => $v) {
- if (intval($v['count']) == 0) {
- $arr[$k][$v['time']]= false;
- } else {
- $arr[$k][$v['time']]= true;
- }
- }
- echo $callback . '(' . json_encode($arr) .')';exit;
- ?>
|