Skip to content

Commit c80f6de

Browse files
author
Yang Guoshuai
committed
fix callback 静态实例
1 parent 8516c07 commit c80f6de

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

docs/WxPay.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
------
33

44
# 使用说明
5-
在使用前,请先参考微信支付商户的普通商户的[开发文档][1],具体的接口说明,以微信的文档为准。
5+
在使用前,请先参考微信支付商户的普通商户的[开发文档][1],具体的接口说明,以微信的文档为准。
66

77
# WxPay为你提供了:
88
* 自动处理`开发者``微信服务器`请求的请求/响应格式
@@ -43,7 +43,7 @@ APP支付需要单独申请(申请见[微信开放平台][2]),与公众号
4343
# 后台对接
4444

4545
* 配置注入实例
46-
在yii2的web配置中,加入如下的配置,推荐放入至common的`main-local.php`中,如 `common/config/main-local.php`中。
46+
在yii2的web配置中,加入如下的配置,推荐放入至common的`main-local.php`中,如 `common/config/main-local.php`中。
4747

4848
```php
4949
return [
@@ -87,9 +87,9 @@ return [
8787
Yii::$app->wechat->setOptional('out_trade_no', 'foo|bar|123')->orderquery();
8888
Yii::$app->wechat->setOptional('transaction_id', '12312321212')->orderquery();
8989
```
90-
90+
9191
如果每个可选参数都没有提供,将会抛出异常。
92-
92+
9393
## 统一下单
9494
```php
9595
public function unifiedorder($body, $tradeNo, $totalFee, array $params = [])
@@ -207,8 +207,8 @@ return [
207207
public function actions()
208208
{
209209
return [
210-
'bar' => [
211-
'class' => Yii::$app->wxpay->callbackAction(function ($post) {
210+
'bar' => Yii::$app->wxpay->callbackAction(
211+
function ($post) {
212212
if(isset($post['refund_id'])) {
213213
$result = Baz::processAfterRefund($post);
214214
} else {
@@ -224,7 +224,8 @@ return [
224224
'return_code' => 'FAIL',
225225
'return_msg' => '处理错误',
226226
];
227-
],
227+
}
228+
),
228229
];
229230
}
230231
}

src/WxPay.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ private function setCert()
257257
return $this;
258258
}
259259

260-
public function callbackAction(Closure $processData): string
260+
public function callbackAction(Closure $processData): array
261261
{
262262
$callback = new class('', '', []) extends Action {
263-
public static $checkSign;
264-
public static $processData;
263+
public $checkSign;
264+
public $processData;
265265

266266
public function init()
267267
{
@@ -270,10 +270,10 @@ public function init()
270270
}
271271
parent::init();
272272
$this->controller->enableCsrfValidation = false;
273-
if (empty(self::$processData)) {
273+
if (empty($this->processData)) {
274274
throw new InvalidConfigException('请配置处理函数');
275275
}
276-
if (!(self::$processData instanceof Closure)) {
276+
if (!($this->processData instanceof Closure)) {
277277
throw new InvalidConfigException('处理函数必须是Closure');
278278
}
279279
//自动处理xml,将rawBody中的xml直接转换为Yii::$app->request->post()
@@ -298,18 +298,20 @@ public function init()
298298
public function run()
299299
{
300300
$post = Yii::$app->request->post();
301-
if (call_user_func_array(self::$checkSign, [&$post])) {
302-
return call_user_func(self::$processData, $post);
301+
if (call_user_func_array($this->checkSign, [&$post])) {
302+
return call_user_func($this->processData, $post);
303303
}
304304
return [
305305
'return_code' => 'FAIL',
306306
'return_msg' => '签名失败',
307307
];
308308
}
309309
};
310-
$callback::$checkSign = Closure::fromCallable([$this, 'checkDecodeSign']);
311-
$callback::$processData = $processData;
312-
return get_class($callback);
310+
return [
311+
'class' => get_class($callback),
312+
'checkSign' => Closure::fromCallable([$this, 'checkDecodeSign']),
313+
'processData' => $processData,
314+
];
313315
}
314316

315317
private function checkDecodeSign(array &$data, $signKey = 'sign'): bool

0 commit comments

Comments
 (0)