eee
This commit is contained in:
@@ -9,10 +9,8 @@ use wchat\wx\V3\Notify\GoodsDetail;
|
|||||||
use wchat\wx\V3\Notify\NotifyModel;
|
use wchat\wx\V3\Notify\NotifyModel;
|
||||||
use wchat\wx\V3\Notify\PromotionDetail;
|
use wchat\wx\V3\Notify\PromotionDetail;
|
||||||
|
|
||||||
const KEY_LENGTH_BYTE = 32;
|
const KEY_TYPE_PUBLIC = 'public';
|
||||||
const AUTH_TAG_LENGTH_BYTE = 16;
|
const KEY_TYPE_PRIVATE = 'private';
|
||||||
const KEY_TYPE_PUBLIC = 'public';
|
|
||||||
const KEY_TYPE_PRIVATE = 'private';
|
|
||||||
|
|
||||||
const LOCAL_FILE_PROTOCOL = 'file://';
|
const LOCAL_FILE_PROTOCOL = 'file://';
|
||||||
const PKEY_PEM_NEEDLE = ' KEY-';
|
const PKEY_PEM_NEEDLE = ' KEY-';
|
||||||
@@ -22,10 +20,10 @@ const CHR_CR = "\r";
|
|||||||
const CHR_LF = "\n";
|
const CHR_LF = "\n";
|
||||||
|
|
||||||
const RULES = [
|
const RULES = [
|
||||||
'private.pkcs1' => [self::PKEY_PEM_FORMAT, 'RSA PRIVATE', 16],
|
'private.pkcs1' => [PKEY_PEM_FORMAT, 'RSA PRIVATE', 16],
|
||||||
'private.pkcs8' => [self::PKEY_PEM_FORMAT, 'PRIVATE', 16],
|
'private.pkcs8' => [PKEY_PEM_FORMAT, 'PRIVATE', 16],
|
||||||
'public.pkcs1' => [self::PKEY_PEM_FORMAT, 'RSA PUBLIC', 15],
|
'public.pkcs1' => [PKEY_PEM_FORMAT, 'RSA PUBLIC', 15],
|
||||||
'public.spki' => [self::PKEY_PEM_FORMAT, 'PUBLIC', 14],
|
'public.spki' => [PKEY_PEM_FORMAT, 'PUBLIC', 14],
|
||||||
];
|
];
|
||||||
const ASN1_OID_RSAENCRYPTION = '300d06092a864886f70d0101010500';
|
const ASN1_OID_RSAENCRYPTION = '300d06092a864886f70d0101010500';
|
||||||
const ASN1_SEQUENCE = 48;
|
const ASN1_SEQUENCE = 48;
|
||||||
@@ -87,8 +85,7 @@ class WxV3PaymentNotify extends SmallProgram
|
|||||||
if (!$timeOffsetStatus || !$verifiedStatus) {
|
if (!$timeOffsetStatus || !$verifiedStatus) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->decode();
|
return $this->decode($this->resource['ciphertext'], $this->resource['nonce'], $this->resource['associated_data']);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -133,18 +130,10 @@ class WxV3PaymentNotify extends SmallProgram
|
|||||||
*/
|
*/
|
||||||
protected function rsaFrom($thing, string $type = KEY_TYPE_PRIVATE): \OpenSSLAsymmetricKey
|
protected function rsaFrom($thing, string $type = KEY_TYPE_PRIVATE): \OpenSSLAsymmetricKey
|
||||||
{
|
{
|
||||||
$pkey = ($isPublic = $type === KEY_TYPE_PUBLIC)
|
$pkey = ($isPublic = $type === KEY_TYPE_PUBLIC) ? openssl_pkey_get_public($this->parse($thing, $type)) : openssl_pkey_get_private($this->parse($thing));
|
||||||
? openssl_pkey_get_public($this->parse($thing, $type))
|
|
||||||
: openssl_pkey_get_private($this->parse($thing));
|
|
||||||
|
|
||||||
if (false === $pkey) {
|
if (false === $pkey) {
|
||||||
throw new \UnexpectedValueException(sprintf(
|
throw new \UnexpectedValueException(sprintf('Cannot load %s from(%s), please take care about the \$thing input.', $isPublic ? 'publicKey' : 'privateKey', gettype($thing)));
|
||||||
'Cannot load %s from(%s), please take care about the \$thing input.',
|
|
||||||
$isPublic ? 'publicKey' : 'privateKey',
|
|
||||||
gettype($thing)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $pkey;
|
return $pkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,10 +146,9 @@ class WxV3PaymentNotify extends SmallProgram
|
|||||||
protected function parse($thing, string $type = KEY_TYPE_PRIVATE): mixed
|
protected function parse($thing, string $type = KEY_TYPE_PRIVATE): mixed
|
||||||
{
|
{
|
||||||
$src = $thing;
|
$src = $thing;
|
||||||
if (is_string($src) && is_int(strpos($src, PKEY_PEM_NEEDLE))
|
if (is_string($src) && is_int(strpos($src, PKEY_PEM_NEEDLE)) && $type === KEY_TYPE_PUBLIC && preg_match(PKEY_PEM_FORMAT_PATTERN, $src, $matches)) {
|
||||||
&& $type === KEY_TYPE_PUBLIC && preg_match(PKEY_PEM_FORMAT_PATTERN, $src, $matches)) {
|
|
||||||
[, $kind, $base64] = $matches;
|
[, $kind, $base64] = $matches;
|
||||||
$mapRules = (array)array_combine(array_column(RULES, 1/*column*/), array_keys(RULES));
|
$mapRules = array_combine(array_column(RULES, 1/*column*/), array_keys(RULES));
|
||||||
$protocol = $mapRules[$kind] ?? '';
|
$protocol = $mapRules[$kind] ?? '';
|
||||||
if ('public.pkcs1' === $protocol) {
|
if ('public.pkcs1' === $protocol) {
|
||||||
$src = sprintf('%s://%s', $protocol, str_replace([CHR_CR, CHR_LF], '', $base64));
|
$src = sprintf('%s://%s', $protocol, str_replace([CHR_CR, CHR_LF], '', $base64));
|
||||||
@@ -213,12 +201,14 @@ class WxV3PaymentNotify extends SmallProgram
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @param $ciphertext
|
||||||
* @throws Exception
|
* @param $nonce
|
||||||
|
* @param $associated_data
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function decode(): void
|
public function decode($ciphertext, $nonce, $associated_data): bool
|
||||||
{
|
{
|
||||||
$data = $this->decrypt($this->resource['ciphertext'], $this->resource['nonce'], $this->resource['associated_data']);
|
$data = $this->decrypt($ciphertext, $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'];
|
||||||
@@ -251,6 +241,7 @@ class WxV3PaymentNotify extends SmallProgram
|
|||||||
}
|
}
|
||||||
$this->notifyModel->promotion_detail[] = $detail;
|
$this->notifyModel->promotion_detail[] = $detail;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user