TestAccRefill.php 3.7 KB

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