send_refillex.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. $pThis = $this;
  26. for ($i = 0; $i < $count; $i++)
  27. {
  28. Log::record(__FUNCTION__ . " index={$i}",Log::DEBUG);
  29. go(function () use ($pThis,$time,$i) {
  30. $pThis->push_order(1092, $time, $i);
  31. });
  32. }
  33. }
  34. public function sendex()
  35. {
  36. $count = self::co_routines;
  37. $pThis = $this;
  38. for ($i = 0;$i < $count; $i++)
  39. {
  40. Log::record(__FUNCTION__ . " index={$i}",Log::DEBUG);
  41. go(function () use ($pThis,$i) {
  42. $pThis->send($i);
  43. });
  44. }
  45. }
  46. private function push_order($mchid,$time,$index)
  47. {
  48. $notify_url = "https://test.xyzshops.cn/mobile/callback/bridge_test.php";
  49. $params = [ 'mchid' => $mchid,
  50. 'amount' => 30,
  51. 'order_sn' => "{$time}" . sprintf("%'010d",$index),
  52. 'cardno' => '13911129867',
  53. "act" => "refill",
  54. "op" => "add",
  55. 'notifyurl' => $notify_url
  56. ];
  57. $proxy = new refill_proxy("210fe406954220f56085997d6a4c5b80");
  58. $resp = $proxy->send("https://test.xyzshops.cn/mobile/index.php", $params);
  59. Log::record("resp={$resp}",Log::DEBUG);
  60. }
  61. }
  62. //docker run busybox nslookup test.xyzshops.cn
  63. //$sender = new RefillSender();
  64. //$sender->send(1);
  65. Log::record("send message start",Log::DEBUG);
  66. go(function () {
  67. $sender = new RefillSender();
  68. $sender->sendex();
  69. });
  70. Log::record("send message end",Log::DEBUG);