send_refillex.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. declare(strict_types=0);
  3. define('MOBILE_SERVER',true);
  4. define('USE_COROUTINE',true);
  5. define('SUPPORT_PTHREAD',false);
  6. define('APP_ID', 'sender');
  7. define('BASE_ROOT_PATH',str_replace('/server','',dirname(__FILE__)));
  8. define('BASE_PATH',BASE_ROOT_PATH . '/server');
  9. require_once(BASE_ROOT_PATH . '/global.php');
  10. require_once(BASE_ROOT_PATH . '/fooder.php');
  11. Log::record(__FILE__ . " 1",Log::DEBUG);
  12. require_once(BASE_CORE_PATH . '/framework/function/http.php');
  13. require_once(BASE_HELPER_PATH . '/refill_proxy.php');
  14. Log::record(__FILE__ . " 2",Log::DEBUG);
  15. Co::set(['hook_flags' => SWOOLE_HOOK_NATIVE_CURL|SWOOLE_HOOK_SLEEP]);
  16. Log::record(__FILE__ . " 3",Log::DEBUG);
  17. class RefillSender
  18. {
  19. const co_routines = 1000;
  20. const co_orders = 1000;
  21. public function send($index)
  22. {
  23. $count = self::co_orders;
  24. $time = time() * 1000 + $index;
  25. for ($i = 0; $i < $count; $i++)
  26. {
  27. Log::record(__FUNCTION__ . " index={$i}",Log::DEBUG);
  28. $this->push_order(1092, $time, $i);
  29. }
  30. }
  31. public function sendex()
  32. {
  33. $count = self::co_routines;
  34. $pThis = $this;
  35. for ($i = 0;$i < $count; $i++)
  36. {
  37. Log::record(__FUNCTION__ . " index={$i}",Log::DEBUG);
  38. go(function () use ($pThis,$i) {
  39. $pThis->send($i);
  40. });
  41. }
  42. }
  43. private function push_order($mchid,$time,$index)
  44. {
  45. $notify_url = "https://test.xyzshops.cn/mobile/callback/bridge_test.php";
  46. $params = [ 'mchid' => $mchid,
  47. 'amount' => 30,
  48. 'order_sn' => "{$time}" . sprintf("%'010d",$index),
  49. 'cardno' => '13911129867',
  50. "act" => "refill",
  51. "op" => "add",
  52. 'notifyurl' => $notify_url
  53. ];
  54. $proxy = new refill_proxy("210fe406954220f56085997d6a4c5b80");
  55. $resp = $proxy->send("https://test.xyzshops.cn/mobile/index.php", $params);
  56. Log::record("resp={$resp}",Log::DEBUG);
  57. }
  58. }
  59. //docker run busybox nslookup test.xyzshops.cn
  60. //$sender = new RefillSender();
  61. //$sender->send(1);
  62. Log::record("send message start",Log::DEBUG);
  63. go(function () {
  64. $sender = new RefillSender();
  65. $sender->sendex();
  66. });
  67. Log::record("send message end",Log::DEBUG);