84 lines
2.6 KiB
PHP
84 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\{Order, PayLog};
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use App\Jobs\{PayOrderJob};
|
|
|
|
class NotifyController extends Controller
|
|
{
|
|
/**
|
|
* 集中处理支付回调
|
|
*
|
|
* @param $out_trade_no
|
|
* @param array $params
|
|
*/
|
|
protected function notify($out_trade_no, $params = [])
|
|
{
|
|
try {
|
|
$order = Order::where([
|
|
'order_sn'=> $out_trade_no,
|
|
'order_status'=>1,
|
|
'pay_status'=>0,
|
|
])->first();
|
|
//修改paylog的ext字段;
|
|
if($order){
|
|
PayLog::where([
|
|
'order_sn'=>$order->order_sn,
|
|
'status'=>0
|
|
])->update(['pay_ext'=>$params['pay_trade_no']]);
|
|
//支付订单;
|
|
PayOrderJob::dispatch($order);
|
|
}
|
|
} catch (\Throwable $th) {
|
|
logger()->error($th);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 微信支付异步通知
|
|
*/
|
|
public function wechatPay(Request $request){
|
|
|
|
// if (config('app.env') !== 'production') {
|
|
// $message = XML::parse(file_get_contents('php://input'));
|
|
// if (data_get($message, 'return_code') == 'SUCCESS' && data_get($message, 'result_code') == 'SUCCESS') {
|
|
// $this->notify(data_get($message, 'out_trade_no'), [
|
|
// 'pay_at' => now(),
|
|
// 'pay_trade_no' => data_get($message, 'transaction_id')
|
|
// ]);
|
|
// }
|
|
// return XML::build(['return_code' => 'SUCCESS', 'return_msg' => 'OK']);
|
|
// }
|
|
$payment = \EasyWeChat::payment();
|
|
$response = $payment->handlePaidNotify(function ($message, $fail) {
|
|
if (data_get($message, 'return_code') == 'SUCCESS' && data_get($message, 'result_code') == 'SUCCESS') {
|
|
//处理公众号支付
|
|
switch(data_get($message, 'trade_type')){
|
|
case 'JSAPI':
|
|
$this->notify(data_get($message, 'out_trade_no'), [
|
|
'pay_at' => now(),
|
|
'pay_trade_no' => data_get($message, 'transaction_id')
|
|
]);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
return true;
|
|
});
|
|
|
|
return $response;
|
|
}
|
|
|
|
// public function testToPay(){
|
|
// $this->notify('2107071121001608', [
|
|
// 'pay_at' => now(),
|
|
// 'pay_trade_no' => '123456',
|
|
// ]);
|
|
// dd(123456);
|
|
// }
|
|
} |