swool.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. define('APP_ID', 'test');
  3. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  4. require_once(BASE_ROOT_PATH . '/global.php');
  5. require_once(BASE_CORE_PATH . '/lrlz.php');
  6. require_once(BASE_ROOT_PATH . '/fooder.php');
  7. require_once(BASE_ROOT_PATH . '/core/framework/function/http.php');
  8. require_once(BASE_CORE_PATH . '/framework/function/http.php');
  9. require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
  10. const LocalTest = 1;
  11. const NetTest = 2;
  12. const CurrentTest = NetTest;
  13. Co::set(['hook_flags' => SWOOLE_HOOK_ALL | SWOOLE_HOOK_NATIVE_CURL ]);
  14. class acc
  15. {
  16. private $mReqHost;
  17. private $mKey;
  18. private $mMchid;
  19. public function __construct()
  20. {
  21. if (CurrentTest == LocalTest) {
  22. $this->mReqHost = 'http://host.docker.internal';//BASE_SITE_URL;
  23. $this->mMchid = 1;
  24. $this->mKey = '1ff02223b771c0414468c8892151c602';
  25. } else {
  26. $this->mReqHost = 'http://121.89.212.167';
  27. $this->mMchid = 1092;
  28. $this->mKey = '210fe406954220f56085997d6a4c5b80';
  29. }
  30. }
  31. public static function setUpBeforeClass(): void
  32. {
  33. Base::run_util();
  34. }
  35. public function testAddoil()
  36. {
  37. $url = $this->mReqHost . "/racc/index.php";
  38. // for ($i = 0; $i < 1000; $i++)
  39. {
  40. $params = $this->make_order();
  41. $resp = $this->send_md5($url, $params);
  42. }
  43. }
  44. private function make_order()
  45. {
  46. $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
  47. $params = ['mchid' => $this->mMchid,
  48. 'cardno' => '13911129867',
  49. 'amount' => "30",
  50. "act" => "refill",
  51. "op" => "add",
  52. 'order_sn' => $this->make_sn(),
  53. 'notifyurl' => $notifyurl];
  54. return $params;
  55. }
  56. private function send_md5($url, $params)
  57. {
  58. $body = $this->body($params);
  59. $body .= "&key={$this->mKey}";
  60. $params['sign'] = md5($body);
  61. $resp = http_request($url, $params);
  62. Log::record("resp:{$resp}", Log::DEBUG);
  63. return $resp;
  64. }
  65. private function body($params)
  66. {
  67. ksort($params);
  68. $body = "";
  69. $i = 0;
  70. foreach ($params as $k => $v) {
  71. if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) {
  72. if ($i == 0) {
  73. $body .= "{$k}" . "=" . urlencode($v);
  74. } else {
  75. $body .= "&" . "{$k}" . "=" . urlencode($v);
  76. }
  77. $i++;
  78. }
  79. }
  80. return $body;
  81. }
  82. private function checkEmpty($value)
  83. {
  84. if (!isset($value))
  85. return true;
  86. if ($value === null)
  87. return true;
  88. if (trim($value) === "")
  89. return true;
  90. return false;
  91. }
  92. private function make_sn()
  93. {
  94. return mt_rand(1000, 9999)
  95. . sprintf('%010d', time())
  96. . sprintf('%06d', (float)microtime() * 1000000);
  97. }
  98. }
  99. go(function ()
  100. {
  101. $n = 5000;
  102. $i = 0;
  103. Log::record("start {$i}", Log::DEBUG);
  104. $acc = new acc();
  105. while ($n--) {
  106. go(function () use ($i,$acc) {
  107. $acc->testAddoil();
  108. });
  109. $i++;
  110. }
  111. });