12 Commits

Author SHA1 Message Date
as2252258 24655a4644 eee 2025-02-18 09:09:32 +08:00
as2252258 4ca64c8205 eee 2025-02-17 16:26:32 +08:00
as2252258 d9dbfb3ca6 eee 2024-06-03 11:58:53 +08:00
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
as2252258 76bf8cc2fc eee 2024-02-09 17:01:54 +08:00
as2252258 d9713d00e7 eee 2024-02-09 17:00:41 +08:00
5 changed files with 68 additions and 26 deletions
+1 -1
View File
@@ -20,7 +20,7 @@
},
"require": {
"php": ">= 8.0",
"game-worker/kiri-client": "~v2.8",
"game-worker/kiri-client": "~v2.0",
"psr/container": "*"
},
"require-dev": {
+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');
}
}
+16 -13
View File
@@ -11,12 +11,13 @@ class TransferBatches extends SmallProgram
/**
* @param string $transfer_scene_id
* @param array $transfer_scene_report_infos
* @param TransferDetail $detail
* @return array
* @throws
*/
#[ArrayShape([])]
public function transfer(TransferDetail $detail): array
public function transfer(string $transfer_scene_id ,array $transfer_scene_report_infos ,TransferDetail $detail): array
{
$payConfig = $this->getPayConfig();
$body = [];
@@ -25,23 +26,25 @@ class TransferBatches extends SmallProgram
} else {
$body['appid'] = $payConfig->appId;
}
$body['out_batch_no'] = $detail->out_detail_no;
$body["batch_name"] = $payConfig->getBody();
$body["body"] = $payConfig->getBody();
$body["batch_remark"] = $payConfig->getBody();
$body["total_amount"] = $detail->transfer_amount;
$body["total_num"] = 1;
$body["transfer_detail_list"] = [$detail->toArray()];
$body['out_batch_no'] = $detail->out_detail_no;
$body["batch_name"] = $payConfig->getBody();
$body["body"] = $payConfig->getBody();
$body["batch_remark"] = $payConfig->getBody();
$body["total_amount"] = $detail->transfer_amount;
$body["total_num"] = 1;
$body["transfer_scene_id"] = $transfer_scene_id;
$body["transfer_scene_report_infos"] = $transfer_scene_report_infos;
$body["transfer_detail_list"] = [$detail->toArray()];
$sign = $this->signature('POST', '/v3/transfer/batches', $json = json_encode($body, JSON_UNESCAPED_UNICODE));
$sign = $this->signature('POST' ,'/v3/transfer/batches' ,$json = json_encode($body ,JSON_UNESCAPED_UNICODE));
$client = $this->createClient($sign, $json);
$client = $this->createClient($sign ,$json);
$client->post('/v3/transfer/batches');
$client->close();
$data = json_decode($client->getBody(), TRUE);
$data = json_decode($client->getBody() ,TRUE);
if (json_last_error() != JSON_ERROR_NONE) {
return ['code' => $client->getStatusCode(), 'message' => $client->getBody()];
return ['code' => $client->getStatusCode() ,'message' => $client->getBody()];
} else {
return $data;
}
+18 -9
View File
@@ -54,19 +54,23 @@ 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);
$this->decode($this->resource['ciphertext'], $this->resource['nonce'], $this->resource['associated_data']);
if (!$timeOffsetStatus || !$verifiedStatus) {
return false;
} else {
return true;
}
return $this->decode($this->resource['ciphertext'], $this->resource['nonce'], $this->resource['associated_data']);
}
@@ -111,7 +115,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)));
}
@@ -142,6 +146,9 @@ class WxV3PaymentNotify extends SmallProgram
$this->notifyModel->attach = $data['attach'];
$this->notifyModel->success_time = $data['success_time'];
$this->notifyModel->promotion_detail = [];
if (!isset($data['promotion_detail'])) {
return true;
}
foreach ($data['promotion_detail'] as $datum) {
$detail = new PromotionDetail();
$detail->amount = $datum['amount'];
@@ -154,8 +161,10 @@ class WxV3PaymentNotify extends SmallProgram
$detail->currency = $datum['currency'];
$detail->stock_id = $datum['stock_id'];
$detail->goods_detail = [];
foreach ($datum['goods_detail'] as $value) {
$detail->goods_detail[] = new GoodsDetail($value);
if (isset($data['goods_detail'])) {
foreach ($datum['goods_detail'] as $value) {
$detail->goods_detail[] = new GoodsDetail($value);
}
}
$this->notifyModel->promotion_detail[] = $detail;
}
@@ -163,4 +172,4 @@ class WxV3PaymentNotify extends SmallProgram
}
}
}
+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);