diff --git a/README.md b/README.md index 1f621d0..1e753c0 100644 --- a/README.md +++ b/README.md @@ -480,13 +480,13 @@ $response = $alipay->post('alipay.user.info.share', [], [ ```php use We\Config\AlipayPaymentConfig; -$pay = $client->alipayPayment(AlipayPaymentConfig::fromArray([ +$payment = $client->alipayPayment(AlipayPaymentConfig::fromArray([ 'appid' => 'app_id', 'private_key' => file_get_contents(__DIR__ . '/merchant_private_key.pem'), 'alipay_public_key' => file_get_contents(__DIR__ . '/alipay_public_key.pem'), ])); -$page = $pay->post('page', [ +$page = $payment->post('page', [ 'out_trade_no' => 'P202605020001', 'total_amount' => '0.01', 'subject' => 'Test Order', @@ -566,7 +566,7 @@ $order = $payment->post('v3/pay/transactions/jsapi', [ 'mchid' => 'mch_id', 'description' => '测试订单', 'out_trade_no' => 'T202605020001', - 'notify_url' => 'https://example.com/wechat-pay/notify', + 'notify_url' => 'https://example.com/wechat-payment/notify', 'amount' => ['total' => 1, 'currency' => 'CNY'], 'payer' => ['openid' => 'openid'], ]); @@ -577,7 +577,7 @@ $order = $payment->post('v3/pay/transactions/jsapi', [ ### 支付宝:电脑网站支付与退款 ```php -$page = $pay->post('page', [ +$page = $payment->post('page', [ 'out_trade_no' => 'P202605020001', 'total_amount' => '0.01', 'subject' => '测试订单', @@ -587,7 +587,7 @@ $page = $pay->post('page', [ 'notify_url' => 'https://example.com/alipay/notify', ]); -$refund = $pay->post('refund', [ +$refund = $payment->post('refund', [ 'out_trade_no' => 'P202605020001', 'refund_amount' => '0.01', 'refund_reason' => '用户退款', @@ -597,7 +597,7 @@ $refund = $pay->post('refund', [ 支付宝异步通知验签: ```php -if (!$pay->verifyNotify($_POST)) { +if (!$payment->verifyNotify($_POST)) { throw new RuntimeException('支付宝通知验签失败'); } diff --git a/composer.json b/composer.json index 9cc9d7c..2623dec 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "homepage": "https://github.com/zoujingli/WeChatDeveloper", "keywords": [ "wechat", - "wechat-pay", + "wechat-payment", "alipay", "sdk", "php" diff --git a/src/Platform/Wechat/PaymentClient.php b/src/Platform/Wechat/PaymentClient.php index e1742a6..e858130 100644 --- a/src/Platform/Wechat/PaymentClient.php +++ b/src/Platform/Wechat/PaymentClient.php @@ -9,7 +9,7 @@ use We\Config\WechatPaymentConfig; use We\Exception\SignatureException; use We\Exception\WechatException; use We\Support\JsonClient; -use We\Support\PayCrypto; +use We\Support\PaymentCrypto; use We\Support\Signature; final class PaymentClient @@ -66,7 +66,7 @@ final class PaymentClient /** @var array{ciphertext:string,nonce:string,associated_data?:string} $resource */ $resource = $payload['resource'] ?? []; - return PayCrypto::decryptResource($this->config->apiV3Key, $resource); + return PaymentCrypto::decryptResource($this->config->apiV3Key, $resource); } /** @@ -120,7 +120,7 @@ final class PaymentClient private function authorization(string $method, string $uri, string $timestamp, string $nonce, string $body): string { $message = strtoupper($method) . "\n{$uri}\n{$timestamp}\n{$nonce}\n{$body}\n"; - $signature = Signature::payV3Sign($this->config->merchantPrivateKey, $message); + $signature = Signature::paymentV3Sign($this->config->merchantPrivateKey, $message); $schema = 'WECHATPAY2-SHA256-RSA2048'; $fields = [ 'mchid' => $this->config->mchId, @@ -147,7 +147,7 @@ final class PaymentClient if ($publicKey === '') { throw new SignatureException('微信支付平台公钥或证书不能为空'); } - if (!Signature::verifyPayV3($publicKey, $message, $signature)) { + if (!Signature::verifyPaymentV3($publicKey, $message, $signature)) { throw new SignatureException('微信支付回调验签失败'); } } diff --git a/src/Support/PayCrypto.php b/src/Support/PaymentCrypto.php similarity index 98% rename from src/Support/PayCrypto.php rename to src/Support/PaymentCrypto.php index 21172c1..699d6cd 100644 --- a/src/Support/PayCrypto.php +++ b/src/Support/PaymentCrypto.php @@ -6,7 +6,7 @@ namespace We\Support; use We\Exception\WechatException; -final class PayCrypto +final class PaymentCrypto { /** * @param array{ciphertext:string,nonce:string,associated_data?:string} $resource diff --git a/src/Support/Signature.php b/src/Support/Signature.php index 6291f79..18f15a4 100644 --- a/src/Support/Signature.php +++ b/src/Support/Signature.php @@ -31,7 +31,7 @@ final class Signature } } - public static function payV3Sign(string $privateKey, string $message): string + public static function paymentV3Sign(string $privateKey, string $message): string { $key = openssl_pkey_get_private($privateKey); if ($key === false) { @@ -44,7 +44,7 @@ final class Signature return base64_encode($signature); } - public static function verifyPayV3(string $publicKey, string $message, string $signature): bool + public static function verifyPaymentV3(string $publicKey, string $message, string $signature): bool { $key = openssl_pkey_get_public($publicKey); if ($key === false) { diff --git a/src/Tests/PaymentClientTest.php b/src/Tests/PaymentClientTest.php index 9b7577a..7a3971c 100644 --- a/src/Tests/PaymentClientTest.php +++ b/src/Tests/PaymentClientTest.php @@ -31,7 +31,7 @@ final class PaymentClientTest extends TestCase 'Wechatpay-Timestamp' => $timestamp, 'Wechatpay-Nonce' => $notifyNonce, 'Wechatpay-Serial' => 'platform-serial', - 'Wechatpay-Signature' => Signature::payV3Sign($platformPrivateKey, "{$timestamp}\n{$notifyNonce}\n{$rawBody}\n"), + 'Wechatpay-Signature' => Signature::paymentV3Sign($platformPrivateKey, "{$timestamp}\n{$notifyNonce}\n{$rawBody}\n"), ]; $client = new PaymentClient(new WechatPaymentConfig( 'wx_app', @@ -60,7 +60,7 @@ final class PaymentClientTest extends TestCase 'Wechatpay-Timestamp' => $timestamp, 'Wechatpay-Nonce' => $notifyNonce, 'Wechatpay-Serial' => 'other-serial', - 'Wechatpay-Signature' => Signature::payV3Sign($platformPrivateKey, "{$timestamp}\n{$notifyNonce}\n{$rawBody}\n"), + 'Wechatpay-Signature' => Signature::paymentV3Sign($platformPrivateKey, "{$timestamp}\n{$notifyNonce}\n{$rawBody}\n"), ]; $client = new PaymentClient(new WechatPaymentConfig( 'wx_app', diff --git a/src/Tests/PayCryptoTest.php b/src/Tests/PaymentCryptoTest.php similarity index 81% rename from src/Tests/PayCryptoTest.php rename to src/Tests/PaymentCryptoTest.php index 0ea344c..a65fba6 100644 --- a/src/Tests/PayCryptoTest.php +++ b/src/Tests/PaymentCryptoTest.php @@ -6,10 +6,10 @@ namespace We\Tests; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -use We\Support\PayCrypto; +use We\Support\PaymentCrypto; -#[CoversClass(PayCrypto::class)] -final class PayCryptoTest extends TestCase +#[CoversClass(PaymentCrypto::class)] +final class PaymentCryptoTest extends TestCase { public function testDecryptResource(): void { @@ -19,7 +19,7 @@ final class PayCryptoTest extends TestCase $plain = '{"out_trade_no":"T202605010001","trade_state":"SUCCESS"}'; $cipher = openssl_encrypt($plain, 'aes-256-gcm', $key, OPENSSL_RAW_DATA, $nonce, $tag, $aad); - $data = PayCrypto::decryptResource($key, [ + $data = PaymentCrypto::decryptResource($key, [ 'ciphertext' => base64_encode($cipher . $tag), 'nonce' => $nonce, 'associated_data' => $aad,