Core.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Main\Lib;
  3. use Dever;
  4. function callAction($send)
  5. {
  6. if (isset($send['i']) && $send['i'] > 0) {
  7. $wechat = new Wechat($send['i'], $send['a']);
  8. $param = array();
  9. if (!isset($send['p'])) {
  10. $send['p'] = false;
  11. }
  12. if ($send['s']) {
  13. $param = Dever::load($send['a'] . '/' . $send['s'], $send['p']);
  14. }
  15. if (isset($param['run_num']) && $param['run_num'] > 1) {
  16. for ($i = 1; $i <= $param['run_num']; $i++) {
  17. $result = $wechat->curl($send['t'], $param, false);
  18. if ($send['e']) {
  19. Dever::load($send['a'] . '/' . $send['e'], $send['i'], $result, $send['p']);
  20. }
  21. }
  22. if ($send['e']) {
  23. Dever::load($send['a'] . '/' . $send['e'], $send['i'], $result, $send['p'], true);
  24. }
  25. } else {
  26. $result = $wechat->curl($send['t'], $param, false);
  27. if ($send['e']) {
  28. Dever::load($send['a'] . '/' . $send['e'], $send['i'], $result, $send['p']);
  29. if (isset($param['run_num'])) {
  30. Dever::load($send['a'] . '/' . $send['e'], $send['i'], $result, $send['p'], true);
  31. }
  32. }
  33. }
  34. return $result;
  35. }
  36. return array();
  37. }
  38. class Core
  39. {
  40. static public function run($id, $method, $start, $end, $app, $param = false, $state = false)
  41. {
  42. $send = array();
  43. $send['i'] = $id;
  44. $send['t'] = $method;
  45. $send['s'] = $start;
  46. $send['e'] = $end;
  47. $send['a'] = $app;
  48. $send['p'] = $param;
  49. if ($state == false) {
  50. $result = Dever::daemon(self::url($send), 'main');
  51. } else {
  52. $result = callAction($send);
  53. }
  54. return $result;
  55. }
  56. static public function url($send)
  57. {
  58. $send = base64_encode(json_encode($send));
  59. $url = 'lib/core.call?param=' . $send;
  60. return $url;
  61. }
  62. public function call_api()
  63. {
  64. $send = json_decode(base64_decode(Dever::input('param')), true);
  65. $result = callAction($send);
  66. if (isset($result)) {
  67. print_r($result);
  68. die;
  69. }
  70. return;
  71. }
  72. }