ApiService.class.php 3.4 KB

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