|
@@ -0,0 +1,135 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+use PHPUnit\Framework\TestCase;
|
|
|
+use refill\gftd\config;
|
|
|
+
|
|
|
+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 = NetTest;
|
|
|
+
|
|
|
+
|
|
|
+class Gftd
|
|
|
+{
|
|
|
+ const APP_ID = 'CAE45C97727DECDF';
|
|
|
+ const APP_SECRET = '4023D6F779324C21BF8D8FC10A21CFD4';
|
|
|
+
|
|
|
+ public function params($params)
|
|
|
+ {
|
|
|
+ $params['appid'] = config::APP_ID;
|
|
|
+ $params['ts'] = time();
|
|
|
+ $params['signature'] = $this->sign($params);
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function sign($params)
|
|
|
+ {
|
|
|
+ $body = $this->body($params);
|
|
|
+ $body .= Gftd::APP_SECRET;
|
|
|
+
|
|
|
+ return md5($body);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function check_empty($value)
|
|
|
+ {
|
|
|
+ if (!isset($value))
|
|
|
+ return true;
|
|
|
+ if ($value === null)
|
|
|
+ return true;
|
|
|
+ if (trim($value) === "")
|
|
|
+ return true;
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function body($params)
|
|
|
+ {
|
|
|
+ ksort($params);
|
|
|
+ $body = "";
|
|
|
+ $i = 0;
|
|
|
+ foreach ($params as $k => $v)
|
|
|
+ {
|
|
|
+ if (false === $this->check_empty($v) && "@" != substr($v, 0, 1))
|
|
|
+ {
|
|
|
+ if ($i == 0) {
|
|
|
+ $body .= "{$k}" . "=" . $v;
|
|
|
+ } else {
|
|
|
+ $body .= "&" . "{$k}" . "=" . $v;
|
|
|
+ }
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $body;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class TestRefillCancel 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 = BASE_SITE_URL;
|
|
|
+ $this->mMchid = 1;
|
|
|
+ $this->mKey = '1ff02223b771c0414468c8892151c602';
|
|
|
+ } else {
|
|
|
+ $this->mReqHost = 'https://www.xyzshops.cn';
|
|
|
+ $this->mMchid = 1092;
|
|
|
+ $this->mKey = '210fe406954220f56085997d6a4c5b80';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testGFTDCancel()
|
|
|
+ {
|
|
|
+ $params['channelOrderNumber'] = '600664387134838632';
|
|
|
+ $params['orderNumber'] = 'GYFL1611043135784640';
|
|
|
+ $params['message'] = '只能给绑定正确手机号的油卡充值或只能给主卡充值';
|
|
|
+ $params['status'] = 109;
|
|
|
+
|
|
|
+ $prov = new Gftd();
|
|
|
+ $result = $prov->params($params);
|
|
|
+ $resp = http_post_data("https://www.xyzshops.cn/mobile/refill_gftd.php",json_encode($result,JSON_UNESCAPED_UNICODE),config::ExtHeaders);
|
|
|
+ Log::record($resp,Log::DEBUG);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testGFTDSuccess()
|
|
|
+ {
|
|
|
+ #{"channelOrderNumber":"750664483985964632",
|
|
|
+ #"orderNumber":"GYFL1611139986728407",
|
|
|
+ #"message":"充值成功",
|
|
|
+ #"signature":"f0eec4d0ccc1a0b6ec06003a648fd9b4",
|
|
|
+ #"voucher":"2421012018536345",
|
|
|
+ #"status":101}
|
|
|
+ $params['channelOrderNumber'] = '390664474809855793';
|
|
|
+ $params['orderNumber'] = 'GYFL1611130810782129';
|
|
|
+ $params['message'] = '充值成功';
|
|
|
+ $params['status'] = 101;
|
|
|
+ $params["voucher"] = "2421012018536345";
|
|
|
+
|
|
|
+ $prov = new Gftd();
|
|
|
+ $result = $prov->params($params);
|
|
|
+ $resp = http_post_data("https://www.xyzshops.cn/mobile/refill_gftd.php",json_encode($result,JSON_UNESCAPED_UNICODE),config::ExtHeaders);
|
|
|
+ Log::record($resp,Log::DEBUG);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCall)( .*)?$/" --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
|