Core.php 1.8 KB

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