7 Commits

Author SHA1 Message Date
as2252258 1ff0203511 eee 2024-06-03 11:41:26 +08:00
as2252258 561b105d31 eee 2024-06-03 11:11:48 +08:00
as2252258 3d423acec2 eee 2024-06-03 11:07:46 +08:00
as2252258 d76680a7a2 eee 2024-06-03 10:53:51 +08:00
as2252258 aeb4f3d7fb eee 2024-05-07 14:42:30 +08:00
as2252258 a3aa8e8ac3 eee 2024-05-07 14:41:14 +08:00
as2252258 de4f58d3e3 eee 2024-05-07 14:38:47 +08:00
3 changed files with 38 additions and 8 deletions
+32 -2
View File
@@ -6,6 +6,29 @@ namespace wchat\wx;
use wchat\common\Result;
//if (PHP_VERSION > '8.2') {
// enum Scene
// {
//
// case SCENE_INFO;
// case SCENE_REPLY;
// case SCENE_DISCAZ;
// case SCENE_SHEJIAO;
//
//
// public function getValue(): int
// {
// return match ($this) {
// self::SCENE_INFO => 1,
// self::SCENE_REPLY => 2,
// self::SCENE_DISCAZ => 3,
// self::SCENE_SHEJIAO => 4,
// };
// }
// }
//}
/**
* Class SecCheck
* @package wchat
@@ -65,16 +88,23 @@ class SecCheck extends SmallProgram
/**
* @param string $content
* @param int $scene
* @param string $openId
* @return Result
*/
public function text(string $content): Result
public function text(string $content, int $scene, string $openId): Result
{
if (empty($content)) {
return $this->sendError('文件不存在', 404);
}
$requestUrl = $this->_msgUrl . $this->payConfig->getAccessToken();
return $this->post('api.weixin.qq.com', $requestUrl, ['content' => $content]);
return $this->post('api.weixin.qq.com', $requestUrl, json_encode([
'content' => $content,
'version' => 2,
'scene' => $scene,
'openid' => $openId
], JSON_UNESCAPED_UNICODE), 'application/json');
}
}
+5 -5
View File
@@ -54,13 +54,13 @@ class WxV3PaymentNotify extends SmallProgram
public function verify(RequestInterface $request): bool
{
$platformPublicKeyInstance = $this->rsaFrom($this->payConfig->pay->wx->mchKey, KEY_TYPE_PUBLIC);
$inWechatpaySignature = $request->getHeaderLine('Wechatpay-Signature'); // 请根据实际情况获取
$inWechatpayTimestamp = $request->getHeaderLine('Wechatpay-Timestamp'); // 请根据实际情况获取
$inWechatpayNonce = $request->getHeaderLine('Wechatpay-Nonce'); // 请根据实际情况获取
$inWechatpaySignature = $request->getHeaderLine('wechatpay-signature'); // 请根据实际情况获取
$inWechatpayTimestamp = $request->getHeaderLine('wechatpay-timestamp'); // 请根据实际情况获取
$inWechatpayNonce = $request->getHeaderLine('wechatpay-nonce'); // 请根据实际情况获取
$inBody = $request->getBody()->getContents(); // 请根据实际情况获取,例如: file_get_contents('php://input');
$timeOffsetStatus = 300 >= abs(time() - (int)$inWechatpayTimestamp);
$verifiedStatus = $this->notifyVerify(
$this->lineFeed([$inWechatpayTimestamp, $inWechatpayNonce, $inBody]),
$this->lineFeed($inWechatpayTimestamp, $inWechatpayNonce, $inBody),
$inWechatpaySignature,
$platformPublicKeyInstance);
if (!$timeOffsetStatus || !$verifiedStatus) {
@@ -111,7 +111,7 @@ class WxV3PaymentNotify extends SmallProgram
*/
protected function rsaFrom(string $thing, string $type = KEY_TYPE_PRIVATE): OpenSSLAsymmetricKey
{
$pkey = (($isPublic = $type === KEY_TYPE_PUBLIC) ? openssl_pkey_get_public(file_get_contents($thing)) : openssl_pkey_get_private(file_get_contents($thing)));
$pkey = (($isPublic = $type === KEY_TYPE_PUBLIC) ? openssl_pkey_get_public('file://' . $thing) : openssl_pkey_get_private('file://' . $thing));
if (false === $pkey) {
throw new \UnexpectedValueException(sprintf('Cannot load %s from(%s), please take care about the $thing input.', $isPublic ? 'publicKey' : 'privateKey', gettype($thing)));
}
+1 -1
View File
@@ -137,7 +137,7 @@ trait WxV3PaymentTait
{
$payConfig = $this->getPayConfig();
$mch_private_key = openssl_get_privatekey(file_get_contents($payConfig->pay->wx->mchKey));
$mch_private_key = openssl_get_privatekey(file_get_contents($payConfig->pay->wx->mchCert));
openssl_sign($body, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
return base64_encode($raw_sign);