123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?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'] = '930664641391799632';
- $params['orderNumber'] = 'GYFL1611297392856576';
- $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'] = '950664986520404793';
- $params['orderNumber'] = 'GYFL1611642520980625';
- $params['message'] = '充值成功';
- $params['status'] = 101;
- $params["voucher"] = "2421012614280402";
- $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 testBuildQuery()
- {
- $post = function ()
- {
- $data = [
- 'appKey' => '2023434',
- 'number' => '1231232',
- 'orderId' => '2324',
- 'mobile' => '2343244',
- 'reason' => '',
- 'amount' => 100,
- 'actualAmount' => 100,
- 'createdAt' => '2134r32',
- 'status' => 'WAIT',
- ];
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_VERBOSE, true);
- curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
- curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
- curl_setopt($ch , CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch , CURLOPT_URL, 'http://192.168.1.220/mobile/signature.php');
- $response = curl_exec($ch);
- curl_close( $ch );
- return $response;
- };
- $x = $post();
- }
- }
- //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
|