123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- use PHPUnit\Framework\TestCase;
- 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_HELPER_PATH . '/refill/RefillFactory.php');
- require_once(BASE_HELPER_PATH . '/vendor/yifutongtax.php');
- function my_ssh_disconnect($reason, $message, $language) {
- printf("Server disconnected with reason code [%d] and message: %s\n",
- $reason, $message);
- }
- class TestSSH2 extends TestCase
- {
- public static function setUpBeforeClass(): void
- {
- Base::run_util();
- }
- public function testConnect()
- {
- $connection = ssh2_connect('121.89.223.81', 22);
- if (ssh2_auth_pubkey_file($connection, 'root',
- './ssh/id_rsa.pub',
- './ssh/id_rsa', '')) {
- echo "Public Key Authentication Successful\n";
- } else {
- die('Public Key Authentication Failed');
- }
- $sftp = ssh2_sftp($connection);
- if (!$sftp) {
- die('无法初始化 SFTP');
- }
- $remote_file = "ssh2.sftp://".intval($sftp)."/nfs/upload/yl.tar";
- $local_file = "./ssh/yl.tar";
- if (!copy($remote_file,$local_file)) {
- die('文件上传失败');
- }
- ssh2_disconnect($connection);
- }
- //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestSSH2::testConnectYFT)( .*)?$/" --test-suffix TestSSH2.php /var/www/html/test
- public function testConnectYFT()
- {
- $yft = new vendor\yifutongtax();
- $yft->handle();
- }
- private function down_file()
- {
- }
- public function tstParaseFile()
- {
- }
- public function testTime()
- {
- $cur_time = time();
- $a = strftime("%Y%m%d_000110089970029",$cur_time);
- Log::record("$a", Log::DEBUG);
- $start_date = strtotime('20241211164754');
- Log::record("$start_date", Log::DEBUG);
- $a = strftime("%Y-%m-%d %H:%M:%S",$start_date);
- }
- public function testParaseFile()
- {
- $yft = new vendor\yifutongtax();
- $file = BASE_ROOT_PATH . '/test/ssh/20241209_000110089970029.txt';
- $file = BASE_ROOT_PATH . '/test/ssh/20241211_000110089970029.txt';
- $yft->parese_file($file);
- }
- public function testModifyTime()
- {
- $yft = new vendor\yifutongtax();
- $file = BASE_ROOT_PATH . '/test/ssh/20241211_000110089970029.txt';
- $yft->modify_time($file);
- }
- //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestSSH2::testParase)( .*)?$/" --test-suffix TestSSH2.php /var/www/html/test
- public function testParase()
- {
- #卡号|订单号(唯一的)| 状态(只给成功)| 面值 |运营商流水凭证| 手机号| 创建时间|交易成功时间
- #5|3456.00
- $text = '9629980601009991|62241211164700945483|成功|938|6200945495|13391703053|20241211164725|20241211164754';
- $matcher = function ($input)
- {
- $data = explode('|', $input);
- $count = count($data);
- if ($count === 8) {
- return [
- // 'bank_card' => trim($data[0]),
- 'mch_order' => trim($data[1]),
- 'status' => 'SUCCESS',
- 'amount' => 1,
- // 'org_quality' => 2,
- // 'quality' => 2,
- 'quantity' => intval(trim($data[3])),
- 'official_sn' => trim($data[4]),
- 'card_no' => trim($data[5]),
- 'order_time' => time()
- // 'order_time' => strtotime(trim($data[6])),
- // 'finish_time' => strtotime(trim($data[7]))
- ];
- }
- elseif($count === 2) {
- return [
- 'count' => intval(trim($data[0])),
- 'total' => intval(trim($data[1]))
- ];
- }
- else {
- return false;
- }
- };
- $result = $matcher($text);
- $minfo = $this->mchinfo(1092);
- $params = array_merge($result,$minfo,['notify_url' => '']);
- $mch_order = $params['mch_order'];
- refill\util::write_yifutong_order($mch_order,$params);
- $val = refill\util::read_yifutong_order($mch_order);
- refill\util::push_add($params);
- }
- public function testGetMchinfo()
- {
- $minfo = $this->mchinfo(1092);
- }
- private function mchinfo($mchid)
- {
- $mchinfo = Model('merchant')->getMerchantInfo(['mchid' => $mchid]);
- if(empty($mchinfo)) {
- return false;
- }
- return ['mchid' =>$mchid, 'buyer_id' => intval($mchinfo['admin_id'])];
- }
- }
|