HisService.class.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. if (!defined('IS_INITPHP')) exit('Access Denied!');
  3. class HisService extends BaseService{
  4. //定义每次请求全局变量,返回请求
  5. private $jsonData = array();
  6. //返回sqlData的数据
  7. private $sqlData = null;
  8. //返回sql执行后,返回boolean,默认为true
  9. private $xmlData = array();
  10. private $tempData = array();
  11. //infoString的提示语
  12. private $infoString = null;
  13. //检测请求方法,默认是要检测的
  14. private $boolCheckFun = true;
  15. //检测用户是否合法性,默认是不合法的
  16. private $boolCheckUser = false;
  17. //返回结果,如果是LIST 返回DATA不用加入[]
  18. private $resultType = null;
  19. /**
  20. * 用于在Api引擎中解析数组列表方式
  21. * @param string $funName 方式名
  22. * @param array $funOjb 数组列表
  23. * @return json
  24. */
  25. public function HisEngine($funName,$funObj) {
  26. //不用检测的方法列表
  27. $boolCheckFun = $this->checkFun($funName);
  28. if($boolCheckFun){
  29. //统一验证方式
  30. $boolCheckUser = $this->checkUser();
  31. }else{
  32. //检测方法过滤通过后进入下一步
  33. $boolCheckFun = true;
  34. $boolCheckUser = true;
  35. }
  36. //用于生成返回前台验证时间戳和用户token
  37. $jsonData = $this->getDataToken($boolCheckUser);
  38. //用于生成返回医院HisUrl和Appkey
  39. $hisApi = $this->checkHisApi();
  40. //进入流程处理
  41. if($boolCheckFun && $boolCheckUser && $hisApi){
  42. //print_r($funObj);
  43. foreach ($funObj as $key => $json) {
  44. //$json = json_decode(iconv("GB2312","UTF-8//IGNORE",$json));
  45. $json = json_decode($json);
  46. $nodeType = $json->nodeType;
  47. $parameter = $json->parameter;
  48. $sqlType = $json->sqlType;
  49. $xmlString = $json->xmlString;
  50. $resultType = $json->resultType;
  51. $dataType = $json->dataType;
  52. $sqlString = $json->sqlString;
  53. $funcName = $json->funcName;
  54. $replaceXmlData = $json->replaceXmlData;
  55. $returnXmlData = $json->returnXmlData;
  56. $infoString =$json->infoString;
  57. $isPass = $json->isPass;
  58. if($nodeType=="sql"){
  59. $sqlString= $this->getReplace($parameter,$sqlString,$sqlData,$nodeType,$boolCheckUser);
  60. $sqlData = call_user_func(array($_ENV["dbDao"],$sqlType),$sqlString,$resultType);
  61. if($isPass=="pass"){
  62. if($sqlData){
  63. $sqlData="";
  64. break;
  65. }
  66. }else{
  67. if(!$sqlData){break;}
  68. }
  69. if($dataType=="add"){
  70. $tempData[] =$sqlData;
  71. $sqlData = $tempData =array_merge($tempData, $sqlData);
  72. }
  73. }else if($nodeType=="xml"){
  74. //先生成xml,把变量转入
  75. $postData= $this->getReplace($parameter,$xmlString,$sqlData,$nodeType,$boolCheckUser);
  76. $postUrl = $this->hisApiReplace($hisApi['hisUrl'],$hisApi['appKey'],$funcName);
  77. $returnXml = call_user_func(array($_ENV["commonClass"],"sendDataByCurl"),$postUrl,$postData);
  78. //如果为空,则返回HIS的报错
  79. if(empty($returnXml)){
  80. $sqlData = "";
  81. $infoString ="服务器连接返回内容出错";
  82. }else if(strval($returnXml ->resultCode)=="1"){
  83. $sqlData = "";
  84. $infoString = strval($returnXml ->resultDesc);
  85. }else {
  86. $sqlData = $this->xmlDataReplace($returnXml,$replaceXmlData,$returnXmlData);
  87. if($dataType=="add"){
  88. $tempData[] =$sqlData;
  89. $sqlData = $tempData =array_merge($tempData, $sqlData);
  90. }
  91. }
  92. if(!$sqlData){break;}
  93. }
  94. }
  95. }
  96. //最终生成数据
  97. $jsonData= $this->getJson($jsonData,$sqlData,$infoString,0,$resultType);
  98. //封装后,返回前台json包
  99. $this->codeJson($jsonData);
  100. }
  101. }
  102. ?>