ImportController.class.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * @name eolinker ams open source,eolinker开源版本
  4. * @link https://www.eolinker.com/
  5. * @package eolinker
  6. * @author www.eolinker.com 广州银云信息科技有限公司 ©2015-2018
  7. * eoLinker是目前全球领先、国内最大的在线API接口管理平台,提供自动生成API文档、API自动化测试、Mock测试、团队协作等功能,旨在解决由于前后端分离导致的开发效率低下问题。
  8. * 如在使用的过程中有任何问题,欢迎加入用户讨论群进行反馈,我们将会以最快的速度,最好的服务态度为您解决问题。
  9. *
  10. * eoLinker AMS开源版的开源协议遵循Apache License 2.0,如需获取最新的eolinker开源版以及相关资讯,请访问:https://www.eolinker.com/#/os/download
  11. *
  12. * 官方网站:https://www.eolinker.com/
  13. * 官方博客以及社区:http://blog.eolinker.com/
  14. * 使用教程以及帮助:http://help.eolinker.com/
  15. * 商务合作邮箱:market@eolinker.com
  16. * 用户讨论QQ群:284421832
  17. */
  18. class ImportController
  19. {
  20. // 返回json类型
  21. private $returnJson = array('type' => 'import');
  22. /**
  23. * 检查登录状态
  24. */
  25. public function __construct()
  26. {
  27. // 身份验证
  28. $server = new GuestModule;
  29. if (!$server->checkLogin()) {
  30. $this->returnJson['statusCode'] = '120005';
  31. exitOutput($this->returnJson);
  32. }
  33. }
  34. /**
  35. * 导入eoapi数据
  36. */
  37. public function importEoapi()
  38. {
  39. $json = quickInput('data');
  40. $data = json_decode($json, TRUE);
  41. if (!$data) {
  42. $this->returnJson['statusCode'] = '310004';
  43. exitOutput($this->returnJson);
  44. }
  45. $server = new ImportModule;
  46. $result = $server->eoapiImport($data);
  47. if ($result) {
  48. $this->returnJson['statusCode'] = '000000';
  49. } else {
  50. $this->returnJson['statusCode'] = '310005';
  51. }
  52. exitOutput($this->returnJson);
  53. }
  54. /**
  55. * 导入DHC数据
  56. */
  57. public function importDHC()
  58. {
  59. $json = quickInput('data');
  60. $data = json_decode($json, TRUE);
  61. if (!$data) {
  62. $this->returnJson['statusCode'] = '310004';
  63. exitOutput($this->returnJson);
  64. }
  65. $server = new ImportModule;
  66. $result = $server->importDHC($data);
  67. if ($result) {
  68. $this->returnJson['statusCode'] = '000000';
  69. } else {
  70. $this->returnJson['statusCode'] = '310001';
  71. }
  72. exitOutput($this->returnJson);
  73. }
  74. /**
  75. * 导入postman数据
  76. */
  77. public function importPostman()
  78. {
  79. $json = quickInput('data');
  80. $data = json_decode($json, TRUE);
  81. $version = securelyInput('version');
  82. if (!$data) {
  83. $this->returnJson['statusCode'] = '310004';
  84. exitOutput($this->returnJson);
  85. } elseif ($version != 1 and $version != 2) {
  86. $this->returnJson['statusCode'] = '310002';
  87. exitOutput($this->returnJson);
  88. }
  89. $server = new ImportModule;
  90. if ($version == 1) {
  91. $result = $server->importPostmanV1($data);
  92. } else {
  93. $result = $server->importPostmanV2($data);
  94. }
  95. if ($result) {
  96. $this->returnJson['statusCode'] = '000000';
  97. } else {
  98. $this->returnJson['statusCode'] = '310003';
  99. }
  100. exitOutput($this->returnJson);
  101. }
  102. /**
  103. * 导入swagger数据
  104. */
  105. public function importSwagger()
  106. {
  107. $data = quickInput('data');
  108. $json = json_decode($data, TRUE);
  109. if (empty($json)) {
  110. $this->returnJson['statusCode'] = '310004';
  111. exitOutput($this->returnJson);
  112. }
  113. $server = new ImportModule;
  114. $result = $server->importSwagger($data);
  115. if ($result) {
  116. $this->returnJson['statusCode'] = '000000';
  117. } else {
  118. $this->returnJson['statusCode'] = '310001';
  119. }
  120. exitOutput($this->returnJson);
  121. }
  122. /**
  123. *导入RAP
  124. */
  125. public function importRAP()
  126. {
  127. $json = quickInput('data');
  128. $data = json_decode($json, TRUE);
  129. //判断数据是否为空
  130. if (empty($data['modelJSON'])) {
  131. $this->returnJson['statusCode'] = '310001';
  132. exitOutput($this->returnJson);
  133. }
  134. $model_json = json_decode(str_replace("\'", "'", $data['modelJSON']), TRUE);
  135. //以json格式解析modelJSON失败
  136. if (empty($model_json)) {
  137. $this->returnJson['statusCode'] = '310003';
  138. exitOutput($this->returnJson);
  139. }
  140. $server = new ImportModule();
  141. $result = $server->importRAP($model_json);
  142. //验证结果
  143. if ($result) {
  144. $this->returnJson['statusCode'] = '000000';
  145. } else {
  146. $this->returnJson['statusCode'] = '310000';
  147. }
  148. exitOutput($this->returnJson);
  149. }
  150. }
  151. ?>