mirror of
https://gitee.com/zoujingli/WeChatDeveloper.git
synced 2026-09-04 15:04:32 +08:00
命名: Pay 缩写改为 Payment
This commit is contained in:
parent
1e1f0d231b
commit
41e5265e08
12
README.md
12
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('支付宝通知验签失败');
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
"homepage": "https://github.com/zoujingli/WeChatDeveloper",
|
||||
"keywords": [
|
||||
"wechat",
|
||||
"wechat-pay",
|
||||
"wechat-payment",
|
||||
"alipay",
|
||||
"sdk",
|
||||
"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('微信支付回调验签失败');
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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) {
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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,
|
||||
Loading…
x
Reference in New Issue
Block a user