api.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. $platform_id = Dever::input('set')['platform_id'] ?? 0;
  3. if (!$platform_id) {
  4. $platform_id = Dever::input('field')['platform_id'] ?? 0;
  5. }
  6. $platform = include('platform.php');
  7. $config = [
  8. 'list' => [
  9. 'where' => ['platform_id' => $platform_id],
  10. 'field' => [
  11. //'id',
  12. 'sort' => 'input',
  13. 'name',
  14. 'uri',
  15. 'env',
  16. 'platform_id',
  17. 'status' => [
  18. 'type' => 'switch',
  19. 'show' => '{status}',
  20. 'active_value' => 1,
  21. 'inactive_value' => 2,
  22. ],
  23. ],
  24. 'data_button' => [
  25. '设置' => ['edit', ['platform_id' => $platform_id]],
  26. //'删除' => 'delete',
  27. '复制' => ['api', 'api/manage.copyApi'],
  28. ],
  29. 'button' => [
  30. '新增' => ['fastadd', ['platform_id' => $platform_id, 'field' => 'name,env,platform_id,uri']],
  31. ],
  32. 'search' => [
  33. 'platform_id' => [
  34. 'type' => 'hidden',
  35. 'default' => $platform_id,
  36. ],
  37. 'name',
  38. 'uri',
  39. 'status',
  40. ],
  41. ],
  42. 'update' => [
  43. 'end' => 'api/app.updateApi',
  44. 'desc' => $platform['update']['desc'],
  45. 'tab' => [
  46. '基本设置' => 'name,env,api/api_setting',
  47. '请求地址' => 'uri,method,post_method,api/api_path,api/api_query',
  48. '请求参数' => 'api/api_request_header,api/api_request_body',
  49. '响应参数' => 'api/api_response_header,api/api_response_body',
  50. '存储设置' => 'api/api_save',
  51. '回调设置' => 'notify,api/api_notify,api/api_notify_body,api/api_notify_code',
  52. //'价格设置' => 'spec_type,api/sku,api/sku#',
  53. //'输入输出' => 'api/api_request_input,api/api_request_output',
  54. ],
  55. 'field' => [
  56. 'name',
  57. 'env' => 'radio',
  58. 'platform_id' => [
  59. 'desc' => '【提交后不能更改】',
  60. ],
  61. 'uri',
  62. 'api/api_path' => [
  63. 'name' => '接口路径',
  64. 'where' => ['api_id' => 'id'],
  65. 'desc' => '填写接口上的路径path参数',
  66. ],
  67. 'api/api_query' => [
  68. 'name' => '接口查询参数',
  69. 'where' => ['api_id' => 'id'],
  70. 'desc' => '填写接口上的query参数',
  71. ],
  72. 'api/api_setting' => [
  73. 'name' => '基础参数',
  74. 'where' => ['api_id' => 'id'],
  75. 'desc' => '设置仅限该接口使用的参数,用于定义一些特殊的参数',
  76. ],
  77. 'method' => [
  78. 'type' => 'radio',
  79. 'control' => true,
  80. ],
  81. 'post_method' => [
  82. 'type' => 'radio',
  83. 'show' => false,
  84. ],
  85. 'api/api_request_body' => [
  86. 'name' => '请求体',
  87. 'where' => ['api_id' => 'id'],
  88. ],
  89. 'api/api_request_header' => [
  90. 'name' => '请求头',
  91. 'where' => ['api_id' => 'id'],
  92. ],
  93. 'api/api_response_body' => [
  94. 'name' => '响应体',
  95. 'desc' => '填写后,平台中的标准响应体将失效,并且只保留填写后的响应体,格式:data[].name,不是列表则为data.name',
  96. 'where' => ['api_id' => 'id'],
  97. ],
  98. 'api/api_response_header' => [
  99. 'name' => '响应头',
  100. 'desc' => '填写后,平台中的标准响应头将失效,不填写不保留响应头,格式:data[].name,不是列表则为data.name',
  101. 'where' => ['api_id' => 'id'],
  102. ],
  103. 'api/api_save' => [
  104. 'name' => '存储设置',
  105. 'desc' => '用于将响应数据保存到数据表中,该数据表最好有api_id(int)和request_id(varchar)字段,用于区分是哪个接口哪次请求,当然也可以没有',
  106. 'where' => ['api_id' => 'id'],
  107. ],
  108. 'notify' => [
  109. 'type' => 'radio',
  110. 'control' => true,
  111. ],
  112. /*
  113. #也可以这样设置
  114. 'api/api_notify#' => [
  115. 'field' => 'sign_arg',
  116. 'name' => '签名参数',
  117. 'where' => ['api_id' => 'id'],
  118. ],
  119. 'api/api_notify##' => [
  120. 'field' => 'sign_id',
  121. 'name' => '签名',
  122. 'where' => ['api_id' => 'id'],
  123. ],*/
  124. 'api/api_notify' => [
  125. 'name' => '基本设置',
  126. 'where' => ['api_id' => 'id'],
  127. 'default' => [[]],
  128. # 默认使用表格形式展示,可以改成每行展示
  129. #'type' => 'line',
  130. ],
  131. 'api/api_notify_body' => [
  132. 'name' => '参数设置',
  133. 'where' => ['api_id' => 'id'],
  134. ],
  135. 'api/api_notify_code' => [
  136. 'name' => '状态码',
  137. 'where' => ['api_id' => 'id'],
  138. ],
  139. ],
  140. 'control' => [
  141. 'post_method' => [
  142. 'method' => 2,
  143. ],
  144. 'api/api_notify' => [
  145. 'notify' => 1,
  146. ],
  147. 'api/api_notify_body' => [
  148. 'notify' => 1,
  149. ],
  150. 'api/api_notify_code' => [
  151. 'notify' => 1,
  152. ],
  153. ],
  154. ],
  155. ];
  156. $id = Dever::input('id');
  157. if (!$id) {
  158. unset($config['update']['tab']);
  159. }
  160. return $config;