|
@@ -50,33 +50,46 @@ class WechatPay extends Api{
|
|
|
* */
|
|
|
public function notify(Custom $Custom)
|
|
|
{
|
|
|
- $post_data = request();
|
|
|
+ $content = file_get_contents("php://input");
|
|
|
+ if (!empty($content)) {
|
|
|
+ //直接json字符串
|
|
|
+ $params = $content;
|
|
|
+ } elseif (!empty($_POST)) {
|
|
|
+ //直接POST数据
|
|
|
+ $params = $_POST;
|
|
|
+ } else {
|
|
|
+ $params = [];
|
|
|
+ }
|
|
|
+ $post_data = $params;
|
|
|
Log::log('notify_wechat_pay', 'post_data:' . $post_data);
|
|
|
//获取headers参数
|
|
|
$headers = request()->header();
|
|
|
Log::log('notify_wechat_pay', '微信支付回调返回headers参数:' . json_encode($headers));
|
|
|
|
|
|
- $inWechatpaySignature = $headers['wechatpay-signature'];
|
|
|
- $inWechatpayTimestamp = $headers['wechatpay-timestamp'];
|
|
|
- $inWechatpaySerial = $headers['wechatpay-serial'];
|
|
|
- $inWechatpayNonce = $headers['wechatpay-nonce'];
|
|
|
+ $inWechatpaySignature = $headers['wechatpay-signature'][0];
|
|
|
+ $inWechatpayTimestamp = $headers['wechatpay-timestamp'][0];
|
|
|
+ $inWechatpaySerial = $headers['wechatpay-serial'][0];
|
|
|
+ $inWechatpayNonce = $headers['wechatpay-nonce'][0];
|
|
|
$inBody = $post_data;
|
|
|
-
|
|
|
- $apiv3Key = Config('wechat.APIV3');// 在商户平台上设置的APIv3密钥
|
|
|
+ Log::log('notify_wechat_pay', 'wechatpay-timestamp:' . $inWechatpayTimestamp);
|
|
|
+ $apiv3Key = Config('wechatpay.APIV3');// 在商户平台上设置的APIv3密钥
|
|
|
// 根据通知的平台证书序列号,查询本地平台证书文件,
|
|
|
- $platformCertificateFilePath = Config('wechat.platformCertificate');
|
|
|
+ $platformCertificateFilePath = Config('wechatpay.platformCertificate');
|
|
|
$platformPublicKeyInstance = Rsa::from($platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC);
|
|
|
-
|
|
|
- // 检查通知时间偏移量,允许5分钟之内的偏移
|
|
|
- $timeOffsetStatus = 300 >= abs(Formatter::timestamp() - (int)$inWechatpayTimestamp);
|
|
|
- Log::log('notify_wechat_pay', '时间偏移量:' . $timeOffsetStatus);
|
|
|
- $verifiedStatus = Rsa::verify(
|
|
|
- // 构造验签名串
|
|
|
- Formatter::joinedByLineFeed($inWechatpayTimestamp, $inWechatpayNonce, $inBody),
|
|
|
- $inWechatpaySignature,
|
|
|
- $platformPublicKeyInstance
|
|
|
- );
|
|
|
- Log::log('notify_wechat_pay', '验签:' . $verifiedStatus);
|
|
|
+ try {
|
|
|
+ // 检查通知时间偏移量,允许5分钟之内的偏移
|
|
|
+ $timeOffsetStatus = 300 >= abs(Formatter::timestamp() - (int)$inWechatpayTimestamp);
|
|
|
+ Log::log('notify_wechat_pay', '时间偏移量:' . $timeOffsetStatus);
|
|
|
+ $verifiedStatus = Rsa::verify(
|
|
|
+ // 构造验签名串
|
|
|
+ Formatter::joinedByLineFeed($inWechatpayTimestamp, $inWechatpayNonce, $inBody),
|
|
|
+ $inWechatpaySignature,
|
|
|
+ $platformPublicKeyInstance
|
|
|
+ );
|
|
|
+ }catch (\Exception $e){
|
|
|
+ Log::log('notify_wechat_pay', '错误getMessage:' . $e->getMessage());
|
|
|
+ }
|
|
|
+ Log::log('notify_wechat_pay', '验签:' . $verifiedStatus.'验签inWechatpayTimestamp:' . $inWechatpayTimestamp.'验签verifiedStatus:' . $inWechatpayNonce);
|
|
|
if ($timeOffsetStatus && $verifiedStatus) {
|
|
|
// 转换通知的JSON文本消息为PHP Array数组
|
|
|
$inBodyArray = (array)json_decode($inBody, true);
|
|
@@ -114,6 +127,9 @@ class WechatPay extends Api{
|
|
|
return json_send(['code'=>'SUCCESS']);
|
|
|
|
|
|
}
|
|
|
+ return json_send(['code'=>'SUCCESS']);
|
|
|
+ }else{
|
|
|
+ return json_send(['code'=>'FAIL']);
|
|
|
}
|
|
|
}
|
|
|
|