Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1ff0203511 | |||
| 561b105d31 | |||
| 3d423acec2 | |||
| d76680a7a2 | |||
| aeb4f3d7fb | |||
| a3aa8e8ac3 | |||
| de4f58d3e3 |
+32
-2
@@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user