Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4ca64c8205 | |||
| d9dbfb3ca6 | |||
| 1ff0203511 | |||
| 561b105d31 | |||
| 3d423acec2 | |||
| d76680a7a2 | |||
| aeb4f3d7fb | |||
| a3aa8e8ac3 | |||
| de4f58d3e3 | |||
| 76bf8cc2fc | |||
| d9713d00e7 |
+1
-1
@@ -20,7 +20,7 @@
|
|||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">= 8.0",
|
"php": ">= 8.0",
|
||||||
"game-worker/kiri-client": "~v2.8",
|
"game-worker/kiri-client": "~v2.0",
|
||||||
"psr/container": "*"
|
"psr/container": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
|||||||
+32
-2
@@ -6,6 +6,29 @@ namespace wchat\wx;
|
|||||||
|
|
||||||
use wchat\common\Result;
|
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
|
* Class SecCheck
|
||||||
* @package wchat
|
* @package wchat
|
||||||
@@ -65,16 +88,23 @@ class SecCheck extends SmallProgram
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $content
|
* @param string $content
|
||||||
|
* @param int $scene
|
||||||
|
* @param string $openId
|
||||||
* @return Result
|
* @return Result
|
||||||
*/
|
*/
|
||||||
public function text(string $content): Result
|
public function text(string $content, int $scene, string $openId): Result
|
||||||
{
|
{
|
||||||
if (empty($content)) {
|
if (empty($content)) {
|
||||||
return $this->sendError('文件不存在', 404);
|
return $this->sendError('文件不存在', 404);
|
||||||
}
|
}
|
||||||
$requestUrl = $this->_msgUrl . $this->payConfig->getAccessToken();
|
$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
@@ -11,12 +11,13 @@ class TransferBatches extends SmallProgram
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param string $transfer_scene_id
|
||||||
|
* @param array $transfer_scene_report_infos
|
||||||
* @param TransferDetail $detail
|
* @param TransferDetail $detail
|
||||||
* @return array
|
* @return array
|
||||||
* @throws
|
|
||||||
*/
|
*/
|
||||||
#[ArrayShape([])]
|
#[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();
|
$payConfig = $this->getPayConfig();
|
||||||
$body = [];
|
$body = [];
|
||||||
@@ -25,23 +26,25 @@ class TransferBatches extends SmallProgram
|
|||||||
} else {
|
} else {
|
||||||
$body['appid'] = $payConfig->appId;
|
$body['appid'] = $payConfig->appId;
|
||||||
}
|
}
|
||||||
$body['out_batch_no'] = $detail->out_detail_no;
|
$body['out_batch_no'] = $detail->out_detail_no;
|
||||||
$body["batch_name"] = $payConfig->getBody();
|
$body["batch_name"] = $payConfig->getBody();
|
||||||
$body["body"] = $payConfig->getBody();
|
$body["body"] = $payConfig->getBody();
|
||||||
$body["batch_remark"] = $payConfig->getBody();
|
$body["batch_remark"] = $payConfig->getBody();
|
||||||
$body["total_amount"] = $detail->transfer_amount;
|
$body["total_amount"] = $detail->transfer_amount;
|
||||||
$body["total_num"] = 1;
|
$body["total_num"] = 1;
|
||||||
$body["transfer_detail_list"] = [$detail->toArray()];
|
$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->post('/v3/transfer/batches');
|
||||||
$client->close();
|
$client->close();
|
||||||
|
|
||||||
$data = json_decode($client->getBody(), TRUE);
|
$data = json_decode($client->getBody() ,TRUE);
|
||||||
if (json_last_error() != JSON_ERROR_NONE) {
|
if (json_last_error() != JSON_ERROR_NONE) {
|
||||||
return ['code' => $client->getStatusCode(), 'message' => $client->getBody()];
|
return ['code' => $client->getStatusCode() ,'message' => $client->getBody()];
|
||||||
} else {
|
} else {
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,13 +54,13 @@ class WxV3PaymentNotify extends SmallProgram
|
|||||||
public function verify(RequestInterface $request): bool
|
public function verify(RequestInterface $request): bool
|
||||||
{
|
{
|
||||||
$platformPublicKeyInstance = $this->rsaFrom($this->payConfig->pay->wx->mchKey, KEY_TYPE_PUBLIC);
|
$platformPublicKeyInstance = $this->rsaFrom($this->payConfig->pay->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'); // 请根据实际情况获取
|
||||||
$inBody = $request->getBody()->getContents(); // 请根据实际情况获取,例如: file_get_contents('php://input');
|
$inBody = $request->getBody()->getContents(); // 请根据实际情况获取,例如: file_get_contents('php://input');
|
||||||
$timeOffsetStatus = 300 >= abs(time() - (int)$inWechatpayTimestamp);
|
$timeOffsetStatus = 300 >= abs(time() - (int)$inWechatpayTimestamp);
|
||||||
$verifiedStatus = $this->notifyVerify(
|
$verifiedStatus = $this->notifyVerify(
|
||||||
$this->lineFeed([$inWechatpayTimestamp, $inWechatpayNonce, $inBody]),
|
$this->lineFeed($inWechatpayTimestamp, $inWechatpayNonce, $inBody),
|
||||||
$inWechatpaySignature,
|
$inWechatpaySignature,
|
||||||
$platformPublicKeyInstance);
|
$platformPublicKeyInstance);
|
||||||
if (!$timeOffsetStatus || !$verifiedStatus) {
|
if (!$timeOffsetStatus || !$verifiedStatus) {
|
||||||
@@ -111,7 +111,7 @@ class WxV3PaymentNotify extends SmallProgram
|
|||||||
*/
|
*/
|
||||||
protected function rsaFrom(string $thing, string $type = KEY_TYPE_PRIVATE): OpenSSLAsymmetricKey
|
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) {
|
if (false === $pkey) {
|
||||||
throw new \UnexpectedValueException(sprintf('Cannot load %s from(%s), please take care about the $thing input.', $isPublic ? 'publicKey' : 'privateKey', gettype($thing)));
|
throw new \UnexpectedValueException(sprintf('Cannot load %s from(%s), please take care about the $thing input.', $isPublic ? 'publicKey' : 'privateKey', gettype($thing)));
|
||||||
}
|
}
|
||||||
@@ -142,6 +142,9 @@ class WxV3PaymentNotify extends SmallProgram
|
|||||||
$this->notifyModel->attach = $data['attach'];
|
$this->notifyModel->attach = $data['attach'];
|
||||||
$this->notifyModel->success_time = $data['success_time'];
|
$this->notifyModel->success_time = $data['success_time'];
|
||||||
$this->notifyModel->promotion_detail = [];
|
$this->notifyModel->promotion_detail = [];
|
||||||
|
if (!isset($data['promotion_detail'])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
foreach ($data['promotion_detail'] as $datum) {
|
foreach ($data['promotion_detail'] as $datum) {
|
||||||
$detail = new PromotionDetail();
|
$detail = new PromotionDetail();
|
||||||
$detail->amount = $datum['amount'];
|
$detail->amount = $datum['amount'];
|
||||||
@@ -154,8 +157,10 @@ class WxV3PaymentNotify extends SmallProgram
|
|||||||
$detail->currency = $datum['currency'];
|
$detail->currency = $datum['currency'];
|
||||||
$detail->stock_id = $datum['stock_id'];
|
$detail->stock_id = $datum['stock_id'];
|
||||||
$detail->goods_detail = [];
|
$detail->goods_detail = [];
|
||||||
foreach ($datum['goods_detail'] as $value) {
|
if (isset($data['goods_detail'])) {
|
||||||
$detail->goods_detail[] = new GoodsDetail($value);
|
foreach ($datum['goods_detail'] as $value) {
|
||||||
|
$detail->goods_detail[] = new GoodsDetail($value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->notifyModel->promotion_detail[] = $detail;
|
$this->notifyModel->promotion_detail[] = $detail;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ trait WxV3PaymentTait
|
|||||||
{
|
{
|
||||||
$payConfig = $this->getPayConfig();
|
$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');
|
openssl_sign($body, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
|
||||||
return base64_encode($raw_sign);
|
return base64_encode($raw_sign);
|
||||||
|
|||||||
Reference in New Issue
Block a user