plugin = new StartPlugin(); } public function testNormal() { $rocket = new Rocket(); $rocket->setParams([]); $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); $payload = $result->getPayload(); self::assertEquals('e90dd23a37c5c7b616e003970817ff82', $payload->get('app_cert_sn')); self::assertEquals('687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6', $payload->get('alipay_root_cert_sn')); } public function testGlobalBcscale() { bcscale(2); $rocket = new Rocket(); $rocket->setParams([]); $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); self::assertEquals('687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6', $result->getPayload()->get('alipay_root_cert_sn')); } public function testCustomizedReturnUrl() { $rocket = new Rocket(); $rocket->setParams([ '_return_url' => 'https://yansongda.cna', ]); $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); self::assertEquals('https://yansongda.cna', $result->getPayload()->get('return_url')); } public function testCustomizedNotifyUrl() { $rocket = new Rocket(); $rocket->setParams([ '_notify_url' => 'https://yansongda.cna', ]); $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); self::assertEquals('https://yansongda.cna', $result->getPayload()->get('notify_url')); } public function testCustomizedReturnNotifyUrl() { $rocket = new Rocket(); $rocket->setParams([ '_return_url' => 'https://yansongda.cn', '_notify_url' => 'https://yansongda.cn', ]); $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); self::assertEquals('https://yansongda.cn', $result->getPayload()->get('return_url')); self::assertEquals('https://yansongda.cn', $result->getPayload()->get('notify_url')); } public function testCustomizedAppAuthToken() { $rocket = new Rocket(); $rocket->setParams([ '_app_auth_token' => 'yansongda.cn', ]); $result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); self::assertEquals('yansongda.cn', $result->getPayload()->get('app_auth_token')); } public function testMissingAppPublicCertPath() { $rocket = new Rocket(); Pay::set(ConfigInterface::class, new Config()); self::expectException(InvalidConfigException::class); self::expectExceptionCode(Exception::CONFIG_ALIPAY_INVALID); self::expectExceptionMessage('配置异常: 缺少支付宝配置 -- [app_public_cert_path]'); $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); } public function testWrongAppPublicCertPath() { $rocket = new Rocket(); $config = Pay::get(ConfigInterface::class); $config->set('alipay.default.app_public_cert_path', __DIR__.'/../../Cert/foo'); Pay::set(ConfigInterface::class, $config); self::expectException(InvalidConfigException::class); self::expectExceptionCode(Exception::CONFIG_ALIPAY_INVALID); self::expectExceptionMessage('配置异常: 解析 `app_public_cert_path` 失败'); $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); } public function testMissingAlipayRootPath() { $rocket = new Rocket(); $config = Pay::get(ConfigInterface::class); $config->set('alipay.default.alipay_root_cert_path', null); self::expectException(InvalidConfigException::class); self::expectExceptionCode(Exception::CONFIG_ALIPAY_INVALID); self::expectExceptionMessage('配置异常: 缺少支付宝配置 -- [alipay_root_cert_path]'); $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); } public function testWrongAlipayRootPath() { $rocket = new Rocket(); $config = Pay::get(ConfigInterface::class); $config->set('alipay.default.alipay_root_cert_path', __DIR__.'/../../../Cert/foo'); self::expectException(InvalidConfigException::class); self::expectExceptionCode(Exception::CONFIG_ALIPAY_INVALID); self::expectExceptionMessage('配置异常: 解析 `alipay_root_cert` 失败'); $this->plugin->assembly($rocket, function ($rocket) { return $rocket; }); } public function testAppCertSnCached() { $result = $this->plugin->assembly(new Rocket(), function ($rocket) { return $rocket; }); $payload = $result->getPayload(); self::assertEquals('e90dd23a37c5c7b616e003970817ff82', $payload->get('app_cert_sn')); $config = Pay::get(ConfigInterface::class); $config->set('alipay.default.app_public_cert_path', null); $result = $this->plugin->assembly(new Rocket(), function ($rocket) { return $rocket; }); $payload = $result->getPayload(); self::assertEquals('e90dd23a37c5c7b616e003970817ff82', $payload->get('app_cert_sn')); } public function testAlipayRootCertSnCached() { $result = $this->plugin->assembly(new Rocket(), function ($rocket) { return $rocket; }); $payload = $result->getPayload(); self::assertEquals('687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6', $payload->get('alipay_root_cert_sn')); $config = Pay::get(ConfigInterface::class); $config->set('alipay.default.alipay_root_cert_path', null); $result = $this->plugin->assembly(new Rocket(), function ($rocket) { return $rocket; }); $payload = $result->getPayload(); self::assertEquals('687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6', $payload->get('alipay_root_cert_sn')); } public function testAlipayRootCertSnString() { $config = Pay::get(ConfigInterface::class); $config->set('alipay.default.alipay_root_cert_path', '-----BEGIN CERTIFICATE----- MIIBszCCAVegAwIBAgIIaeL+wBcKxnswDAYIKoEcz1UBg3UFADAuMQswCQYDVQQG EwJDTjEOMAwGA1UECgwFTlJDQUMxDzANBgNVBAMMBlJPT1RDQTAeFw0xMjA3MTQw MzExNTlaFw00MjA3MDcwMzExNTlaMC4xCzAJBgNVBAYTAkNOMQ4wDAYDVQQKDAVO UkNBQzEPMA0GA1UEAwwGUk9PVENBMFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE MPCca6pmgcchsTf2UnBeL9rtp4nw+itk1Kzrmbnqo05lUwkwlWK+4OIrtFdAqnRT V7Q9v1htkv42TsIutzd126NdMFswHwYDVR0jBBgwFoAUTDKxl9kzG8SmBcHG5Yti W/CXdlgwDAYDVR0TBAUwAwEB/zALBgNVHQ8EBAMCAQYwHQYDVR0OBBYEFEwysZfZ MxvEpgXBxuWLYlvwl3ZYMAwGCCqBHM9VAYN1BQADSAAwRQIgG1bSLeOXp3oB8H7b 53W+CKOPl2PknmWEq/lMhtn25HkCIQDaHDgWxWFtnCrBjH16/W3Ezn7/U/Vjo5xI pDoiVhsLwg== -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- MIIF0zCCA7ugAwIBAgIIH8+hjWpIDREwDQYJKoZIhvcNAQELBQAwejELMAkGA1UE BhMCQ04xFjAUBgNVBAoMDUFudCBGaW5hbmNpYWwxIDAeBgN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AyIFJv b3QgQ0EgLSBHMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOPPShpV nJbMqqCw6Bz1kehnoPst9pkr0V9idOwU2oyS47/HjJXk9Rd5a9xfwkPO88trUpz5 4GmmwspDXjVFu9L0eFaRuH3KMha1Ak01citbF7cQLJlS7XI+tpkTGHEY5pt3EsQg wykfZl/A1jrnSkspMS997r2Gim54cwz+mTMgDRhZsKK/lbOeBPpWtcFizjXYCqhw WktvQfZBYi6o4sHCshnOswi4yV1p+LuFcQ2ciYdWvULh1eZhLxHbGXyznYHi0dGN z+I9H8aXxqAQfHVhbdHNzi77hCxFjOy+hHrGsyzjrd2swVQ2iUWP8BfEQqGLqM1g KgWKYfcTGdbPB1MCAwEAAaNjMGEwHQYDVR0OBBYEFG/oAMxTVe7y0+408CTAK8hA uTyRMB8GA1UdIwQYMBaAFG/oAMxTVe7y0+408CTAK8hAuTyRMA8GA1UdEwEB/wQF MAMBAf8wDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3DQEBBQUAA4IBAQBLnUTfW7hp emMbuUGCk7RBswzOT83bDM6824EkUnf+X0iKS95SUNGeeSWK2o/3ALJo5hi7GZr3 U8eLaWAcYizfO99UXMRBPw5PRR+gXGEronGUugLpxsjuynoLQu8GQAeysSXKbN1I UugDo9u8igJORYA+5ms0s5sCUySqbQ2R5z/GoceyI9LdxIVa1RjVX8pYOj8JFwtn DJN3ftSFvNMYwRuILKuqUYSHc2GPYiHVflDh5nDymCMOQFcFG3WsEuB+EYQPFgIU 1DHmdZcz7Llx8UOZXX2JupWCYzK1XhJb+r4hK5ncf/w8qGtYlmyJpxk3hr1TfUJX Yf4Zr0fJsGuv -----END CERTIFICATE-----'); $result = $this->plugin->assembly(new Rocket(), function ($rocket) { return $rocket; }); $payload = $result->getPayload(); self::assertEquals('687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6', $payload->get('alipay_root_cert_sn')); } }