eee
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace wchat\common;
|
||||||
|
|
||||||
|
use JetBrains\PhpStorm\ArrayShape;
|
||||||
|
|
||||||
|
class AppConfig
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected string $appId = '';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected string $appSecret = '';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var PayConfig
|
||||||
|
*/
|
||||||
|
protected PayConfig $payConfig;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected int $type;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array|string[]
|
||||||
|
*/
|
||||||
|
#[ArrayShape(['token' => 'string', 'secret' => 'string', 'unionId' => 'string'])]
|
||||||
|
protected array $notice = ['token' => '', 'secret' => '', 'unionId' => ''];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param object $app
|
||||||
|
* @return static
|
||||||
|
*/
|
||||||
|
public static function instance(object $app): static
|
||||||
|
{
|
||||||
|
$model = new static();
|
||||||
|
$model->appId = $app->appId;
|
||||||
|
$model->appSecret = $app->appSecret;
|
||||||
|
$model->type = $app->type;
|
||||||
|
$model->payConfig = PayConfig::parse($app->pay);
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function typeIsApp(): bool
|
||||||
|
{
|
||||||
|
return $this->type === 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,6 +22,12 @@ abstract class Multiprogramming implements Progaram
|
|||||||
protected string $errorMsg = '';
|
protected string $errorMsg = '';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var PayConfig
|
||||||
|
*/
|
||||||
|
protected PayConfig $payConfig;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $message
|
* @param $message
|
||||||
* @param int $code
|
* @param int $code
|
||||||
@@ -74,6 +80,22 @@ abstract class Multiprogramming implements Progaram
|
|||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return PayConfig
|
||||||
|
*/
|
||||||
|
public function getPayConfig(): PayConfig
|
||||||
|
{
|
||||||
|
return $this->payConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PayConfig $payConfig
|
||||||
|
*/
|
||||||
|
public function setPayConfig(PayConfig $payConfig): void
|
||||||
|
{
|
||||||
|
$this->payConfig = $payConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \wchat\common\Config
|
* @return \wchat\common\Config
|
||||||
|
|||||||
+12
-63
@@ -2,81 +2,30 @@
|
|||||||
|
|
||||||
namespace wchat\common;
|
namespace wchat\common;
|
||||||
|
|
||||||
use JetBrains\PhpStorm\ArrayShape;
|
use wchat\common\libs\Aliyun;
|
||||||
|
use wchat\common\libs\Qq;
|
||||||
|
use wchat\common\libs\Wx;
|
||||||
|
|
||||||
class PayConfig
|
class PayConfig
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array|string[]
|
* @var Qq
|
||||||
*/
|
*/
|
||||||
#[ArrayShape(["appId" => "string", "mchCa" => "string", "mchId" => "string", "mchKey" => "string", "mchCert" => "string", "appSecret" => "string", "mchSecret" => "string"])]
|
public Qq $qq;
|
||||||
protected array $qq = ["appId" => "", "mchCa" => "", "mchId" => "", "mchKey" => "", "mchCert" => "", "appSecret" => "", "mchSecret" => ""];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array|string[]
|
* @var Wx
|
||||||
*/
|
*/
|
||||||
#[ArrayShape(["appId" => "string", "mchId" => "string", "schema" => "string", "mchKey" => "string", "secret" => "string", "mchCert" => "string", "appSecret" => "string", "SerialNumber" => "string"])]
|
public Wx $wx;
|
||||||
protected array $wx = ["appId" => "", "mchId" => "", "schema" => "", "mchKey" => "", "secret" => "", "mchCert" => "", "appSecret" => "", "SerialNumber" => ""];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array|string[]
|
* @var Aliyun
|
||||||
*/
|
*/
|
||||||
#[ArrayShape(["appId" => "string", "appKey" => "string", "appSecret" => "string", "aliPubSecret" => "string", "appPubSecret" => "string", "aliRootSecret" => "string", "openFileState" => "string"])]
|
public Aliyun $ali;
|
||||||
protected array $ali = ["appId" => "", "appKey" => "", "appSecret" => "", "aliPubSecret" => "", "appPubSecret" => "", "aliRootSecret" => "", "openFileState" => "0"];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array|string[]
|
|
||||||
*/
|
|
||||||
#[ArrayShape(["appId" => "string", "mchCa" => "string", "mchId" => "string", "mchKey" => "string", "mchCert" => "string", "appSecret" => "string", "mchSecret" => "string"])] public function getQq(): array
|
|
||||||
{
|
|
||||||
return $this->qq;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array|string[] $qq
|
|
||||||
*/
|
|
||||||
public function setQq(array $qq): void
|
|
||||||
{
|
|
||||||
$this->qq = $qq;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array|string[]
|
|
||||||
*/
|
|
||||||
#[ArrayShape(["appId" => "string", "mchId" => "string", "schema" => "string", "mchKey" => "string", "secret" => "string", "mchCert" => "string", "appSecret" => "string", "SerialNumber" => "string"])] public function getWx(): array
|
|
||||||
{
|
|
||||||
return $this->wx;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array|string[] $wx
|
|
||||||
*/
|
|
||||||
public function setWx(array $wx): void
|
|
||||||
{
|
|
||||||
$this->wx = $wx;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array|string[]
|
|
||||||
*/
|
|
||||||
#[ArrayShape(["appId" => "string", "appKey" => "string", "appSecret" => "string", "aliPubSecret" => "string", "appPubSecret" => "string", "aliRootSecret" => "string", "openFileState" => "string"])]
|
|
||||||
public function getAli(): array
|
|
||||||
{
|
|
||||||
return $this->ali;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array|string[] $ali
|
|
||||||
*/
|
|
||||||
public function setAli(array $ali): void
|
|
||||||
{
|
|
||||||
$this->ali = $ali;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,9 +38,9 @@ class PayConfig
|
|||||||
$pay = json_decode($pay, true);
|
$pay = json_decode($pay, true);
|
||||||
}
|
}
|
||||||
$model = new static();
|
$model = new static();
|
||||||
foreach ($pay as $key => $value) {
|
$model->ali = \Kiri::configure(new Aliyun(), $pay['ali']);
|
||||||
$model->$key = $value;
|
$model->qq = \Kiri::configure(new Qq(), $pay['qq']);
|
||||||
}
|
$model->wx = \Kiri::configure(new Wx(), $pay['wx']);
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace wchat\common\libs;
|
||||||
|
|
||||||
|
class Aliyun
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $appId;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $mchCa;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $mchId;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $mchKey;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $mchCert;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $appSecret;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $mchSecret;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace wchat\common\libs;
|
||||||
|
|
||||||
|
class Qq
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $appId;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $mchCa;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $mchId;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $mchKey;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $mchCert;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $appSecret;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $mchSecret;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace wchat\common\libs;
|
||||||
|
|
||||||
|
class Wx
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $appId;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $mchId;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $schema;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $mchKey;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $secret;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $mchCert;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $appSecret;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public string $serialNumber;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ namespace wchat\wx\V3;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use OpenSSLAsymmetricKey;
|
use OpenSSLAsymmetricKey;
|
||||||
use Psr\Http\Message\RequestInterface;
|
use Psr\Http\Message\RequestInterface;
|
||||||
|
use wchat\common\PayConfig;
|
||||||
use wchat\wx\SmallProgram;
|
use wchat\wx\SmallProgram;
|
||||||
use wchat\wx\V3\Notify\GoodsDetail;
|
use wchat\wx\V3\Notify\GoodsDetail;
|
||||||
use wchat\wx\V3\Notify\NotifyModel;
|
use wchat\wx\V3\Notify\NotifyModel;
|
||||||
@@ -13,25 +14,6 @@ use wchat\wx\V3\Notify\PromotionDetail;
|
|||||||
const KEY_TYPE_PUBLIC = 'public';
|
const KEY_TYPE_PUBLIC = 'public';
|
||||||
const KEY_TYPE_PRIVATE = 'private';
|
const KEY_TYPE_PRIVATE = 'private';
|
||||||
|
|
||||||
const LOCAL_FILE_PROTOCOL = 'file://';
|
|
||||||
const PKEY_PEM_NEEDLE = ' KEY-';
|
|
||||||
const PKEY_PEM_FORMAT = "-----BEGIN %1\$s KEY-----\n%2\$s\n-----END %1\$s KEY-----";
|
|
||||||
const PKEY_PEM_FORMAT_PATTERN = '#-{5}BEGIN ((?:RSA )?(?:PUBLIC|PRIVATE)) KEY-{5}\r?\n([^-]+)\r?\n-{5}END \1 KEY-{5}#';
|
|
||||||
const CHR_CR = "\r";
|
|
||||||
const CHR_LF = "\n";
|
|
||||||
|
|
||||||
const RULES = [
|
|
||||||
'private.pkcs1' => [PKEY_PEM_FORMAT, 'RSA PRIVATE', 16],
|
|
||||||
'private.pkcs8' => [PKEY_PEM_FORMAT, 'PRIVATE', 16],
|
|
||||||
'public.pkcs1' => [PKEY_PEM_FORMAT, 'RSA PUBLIC', 15],
|
|
||||||
'public.spki' => [PKEY_PEM_FORMAT, 'PUBLIC', 14],
|
|
||||||
];
|
|
||||||
const ASN1_OID_RSAENCRYPTION = '300d06092a864886f70d0101010500';
|
|
||||||
const ASN1_SEQUENCE = 48;
|
|
||||||
const CHR_NUL = "\0";
|
|
||||||
const CHR_ETX = "\3";
|
|
||||||
|
|
||||||
|
|
||||||
class WxV3PaymentNotify extends SmallProgram
|
class WxV3PaymentNotify extends SmallProgram
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -46,7 +28,6 @@ class WxV3PaymentNotify extends SmallProgram
|
|||||||
* @param string $event_type
|
* @param string $event_type
|
||||||
* @param string $summary
|
* @param string $summary
|
||||||
* @param array $resource
|
* @param array $resource
|
||||||
* @param string $publicKey
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $id = "EV-2018022511223320873",
|
public string $id = "EV-2018022511223320873",
|
||||||
@@ -54,8 +35,7 @@ class WxV3PaymentNotify extends SmallProgram
|
|||||||
public string $resource_type = "encrypt-resource",
|
public string $resource_type = "encrypt-resource",
|
||||||
public string $event_type = "TRANSACTION.SUCCESS",
|
public string $event_type = "TRANSACTION.SUCCESS",
|
||||||
public string $summary = "支付成功",
|
public string $summary = "支付成功",
|
||||||
public array $resource = [],
|
public array $resource = []
|
||||||
public string $publicKey = ''
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -74,7 +54,7 @@ class WxV3PaymentNotify extends SmallProgram
|
|||||||
*/
|
*/
|
||||||
public function verify(RequestInterface $request): bool
|
public function verify(RequestInterface $request): bool
|
||||||
{
|
{
|
||||||
$platformPublicKeyInstance = $this->rsaFrom($this->publicKey, KEY_TYPE_PUBLIC);
|
$platformPublicKeyInstance = $this->rsaFrom($this->payConfig->wx->mchKey, KEY_TYPE_PUBLIC);
|
||||||
$inWechatpaySignature = $request->getHeaderLine('Wechatpay-Signature'); // 请根据实际情况获取
|
$inWechatpaySignature = $request->getHeaderLine('Wechatpay-Signature'); // 请根据实际情况获取
|
||||||
$inWechatpayTimestamp = $request->getHeaderLine('Wechatpay-Timestamp'); // 请根据实际情况获取
|
$inWechatpayTimestamp = $request->getHeaderLine('Wechatpay-Timestamp'); // 请根据实际情况获取
|
||||||
$inWechatpayNonce = $request->getHeaderLine('Wechatpay-Nonce'); // 请根据实际情况获取
|
$inWechatpayNonce = $request->getHeaderLine('Wechatpay-Nonce'); // 请根据实际情况获取
|
||||||
@@ -147,7 +127,7 @@ class WxV3PaymentNotify extends SmallProgram
|
|||||||
*/
|
*/
|
||||||
public function decode($ciphertext, $nonce, $associated_data): bool
|
public function decode($ciphertext, $nonce, $associated_data): bool
|
||||||
{
|
{
|
||||||
$data = $this->decrypt($ciphertext, $this->getConfig()->getMchKey(), $nonce, $associated_data);
|
$data = $this->decrypt($ciphertext, $this->payConfig->wx->secret, $nonce, $associated_data);
|
||||||
$this->notifyModel = new NotifyModel();
|
$this->notifyModel = new NotifyModel();
|
||||||
$this->notifyModel->amount = $data['amount'];
|
$this->notifyModel->amount = $data['amount'];
|
||||||
$this->notifyModel->payer = $data['payer'];
|
$this->notifyModel->payer = $data['payer'];
|
||||||
|
|||||||
Reference in New Issue
Block a user