123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- use PHPUnit\Framework\TestCase;
- use const mtopcard\SinopecCard;
- define('APP_ID', 'test');
- define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
- require_once(BASE_ROOT_PATH . '/global.php');
- require_once(BASE_CORE_PATH . '/lrlz.php');
- require_once(BASE_ROOT_PATH . '/fooder.php');
- require_once(BASE_CORE_PATH . '/framework/function/http.php');
- require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
- require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
- const LocalTest = 1;
- const NetTest = 2;
- const CurrentTest = LocalTest;
- class TestAccRefill extends TestCase
- {
- private $mReqHost;
- private $mKey;
- private $mMchid;
- public function __construct(?string $name = null, array $data = [], $dataName = '')
- {
- parent::__construct($name, $data, $dataName);
- if (CurrentTest == LocalTest) {
- $this->mReqHost = 'http://host.docker.internal';//BASE_SITE_URL;
- $this->mMchid = 1;
- $this->mKey = '1ff02223b771c0414468c8892151c602';
- } else {
- $this->mReqHost = 'http://121.89.212.167';
- $this->mMchid = 1092;
- $this->mKey = '210fe406954220f56085997d6a4c5b80';
- }
- }
- public static function setUpBeforeClass(): void
- {
- Base::run_util();
- }
- public function testAddoil()
- {
- $url = $this->mReqHost . "/racc/index.php";
- // $url = 'https://www.baidu.com.cn';
- for ($i = 0; $i < 10; $i++)
- {
- $params = $this->make_order();
- $resp = $this->send_md5($url, $params);
- }
- }
- public function testRequest()
- {
- $resp = http_request('https://www.baidu.com.cn');
- }
- private function make_order()
- {
- $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
- $params = ['mchid' => $this->mMchid,
- 'cardno' => '13911129867',
- 'amount' => "30",
- "act" => "refill",
- "op" => "add",
- 'order_sn' => $this->make_sn(),
- 'notifyurl' => $notifyurl];
- return $params;
- }
- private function send_md5($url, $params)
- {
- $body = $this->body($params);
- $body .= "&key={$this->mKey}";
- $params['sign'] = md5($body);
- $resp = http_request($url, $params);
- Log::record("resp:{$resp}", Log::DEBUG);
- return $resp;
- }
- private function body($params)
- {
- ksort($params);
- $body = "";
- $i = 0;
- foreach ($params as $k => $v) {
- if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) {
- if ($i == 0) {
- $body .= "{$k}" . "=" . urlencode($v);
- } else {
- $body .= "&" . "{$k}" . "=" . urlencode($v);
- }
- $i++;
- }
- }
- return $body;
- }
- private function checkEmpty($value)
- {
- if (!isset($value))
- return true;
- if ($value === null)
- return true;
- if (trim($value) === "")
- return true;
- return false;
- }
- public function testFactory()
- {
- $providers = refill\RefillFactory::instance();
- }
- private function make_sn()
- {
- return mt_rand(1000, 9999)
- . sprintf('%010d', time())
- . sprintf('%06d', (float)microtime() * 1000000);
- }
- }
- //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
- //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
|