ZimuPayServiceTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace Tests\Unit;
  3. use App\Services\Payment\ZimuPayService;
  4. use PHPUnit\Framework\TestCase;
  5. class ZimuPayServiceTest extends TestCase
  6. {
  7. public function test_signature_uses_ascii_sorted_non_empty_fields(): void
  8. {
  9. $signature = ZimuPayService::signature([
  10. 'appId' => 'APP123',
  11. 'nonce' => 'abcdef',
  12. 'mchOrderNo' => 'PO1',
  13. 'amount' => '40.00',
  14. 'member' => 'user1',
  15. 'notifyUrl' => 'https://example.com/api/pay/harvest',
  16. 'extParam' => '',
  17. 'timestamp' => '1697253582897',
  18. ], 'secret');
  19. $this->assertSame('3C5D52F6411F9153ED34FEC1DAFA74C0', $signature);
  20. }
  21. public function test_channel_helpers_match_zimu_channels(): void
  22. {
  23. $this->assertTrue(ZimuPayService::isRechargeChannel(ZimuPayService::CHANNEL_RECHARGE));
  24. $this->assertTrue(ZimuPayService::isWithdrawChannel(ZimuPayService::CHANNEL_WITHDRAW));
  25. $this->assertTrue(ZimuPayService::isCashChannel(ZimuPayService::CHANNEL_CASH));
  26. $this->assertTrue(ZimuPayService::isPayoutChannel(ZimuPayService::CHANNEL_WITHDRAW));
  27. $this->assertTrue(ZimuPayService::isPayoutChannel(ZimuPayService::CHANNEL_CASH));
  28. }
  29. public function test_cash_pay_method_matches_bank_name(): void
  30. {
  31. $this->assertSame('1', ZimuPayService::cashPayMethod('中国建设银行'));
  32. $this->assertSame('2', ZimuPayService::cashPayMethod('微信'));
  33. $this->assertSame('3', ZimuPayService::cashPayMethod('支付宝'));
  34. $this->assertSame('4', ZimuPayService::cashPayMethod('数字人民币'));
  35. }
  36. }