赞
踩
- // 支付回调接收
- public function notify()
- {
- $inWechatpaySignature = $this->request->getHeaderLine('Wechatpay-Signature'); // 请根据实际情况获取
- $inWechatpayTimestamp = $this->request->getHeaderLine('Wechatpay-Timestamp'); // 请根据实际情况获取
- $inWechatpaySerial = $this->request->getHeaderLine('Wechatpay-Serial'); // 请根据实际情况获取
- $inWechatpayNonce = $this->request->getHeaderLine('Wechatpay-Nonce'); // 请根据实际情况获取
- $inBody = $this->request->getBody()->getContents(); // 请根据实际情况获取,例如: file_get_contents('php://input');
-
- $params = [
- 'inWechatpaySignature' => $inWechatpaySignature,
- 'inWechatpayTimestamp' => $inWechatpayTimestamp,
- 'inWechatpaySerial' => $inWechatpaySerial,
- 'inWechatpayNonce' => $inWechatpayNonce,
- 'inBody' => $inBody,
- ];
-
- try {
- $res = $this->wxAppPayNotifyVerify($params, self::class, 'callbackNotify');
- } catch (\Exception $e) {
- var_dump($e->getMessage());
- return $this->response->withStatus(500)->json([
- 'code' => 'FAIL',
- 'message' => '失败',
- ]);
- }
- if ($res) {
- return $this->response->json([
- 'code' => 'SUCCESS',
- 'message' => '成功',
- ]);
- } else {
- return $this->response->withStatus(500)->json([
- 'code' => 'FAIL',
- 'message' => '失败',
- ]);
- }
-
- }
-
-
-
-
-
-
- // 支付回调执行方法
- public function callbackNotify(array $params = [])
- {
- // 获取附加消息
- $attach = isset($params['attach']) ? json_decode($params['attach'], true) : [];
- if (!$attach) return false;
-
- // 校验附加消息
- $id = $attach['id'] ?? '';
- if (!$id) return false;
-
-
- // 业务处理
-
- return true;
- }
-
-
-
-
-
-
-
-
-
-
-
-
- /**
- * 微信小程序支付回调
- * wxAppPayNotifyVerify($params, self::class, 'callbackNotify');
- *
- * @authors: Msy
- * @Created-Time: 2023/2/9 13:28
- * @param array $notifyData 回调返回的参数数组
- * @param $class 回调所在的类
- * @param $method 回调方法名
- * @return false|mixed|void
- * @throws \ReflectionException
- */
- public function wxAppPayNotifyVerify(array $notifyData, $class, $method)
- {
-
-
-
- // start
- 这里执行支付回调解密 , 自行查看官方文档
- https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_5.shtml
- // end
-
-
-
- // 反射类执行回调
- $classObj = new \ReflectionClass($class);
- $class_instantce = $classObj->newInstance(); // 通过反射对象创建类的实例
- $method = $classObj->getMethod($method);
- // 下两行注释也可达到同样效果 , 方法参数名需要对应 , 由于我的方法只有一个参数,所以直接用invoke了
- // $params = ['方法参数名' => $inBodyResourceArray];
- // return $method->invokeArgs($class_instantce, $params);
- return $method->invoke($class_instantce, $inBodyResourceArray);
-
- }
-
-
-
-
-
-
-
-
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。