| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Models\PaymentLogModel;
- use App\Services\PayService;
- use Illuminate\Support\Facades\Log;
- use PHPUnit\Util\Exception;
- use Yansongda\Pay\Pay;
- class PayNotifyController extends Controller
- {
- /**
- * 微信支付回调
- */
- public function wx_notify(){
- $wxpay = Pay::wechat(PayService::wx_config());
- try{
- $data = $wxpay->verify();
- Log::info($data);
- $order_no = $data->out_trade_no;
- $this->order_do_sth($order_no);
- Log::debug('Wechat notify', $data->all());
- } catch (\Exception $e) {
- Log::info($e->getMessage());
- }
- return $wxpay->success();
- }
- /**
- * 支付宝支付回调
- */
- public function ali_notify(){
- $alipay = Pay::alipay(PayService::ali_config());
- try{
- $data = $alipay->verify();
- Log::info($data);
- $order_no = $data->out_trade_no;
- $this->order_do_sth($order_no);
- Log::debug('Wechat notify', $data->all());
- } catch (\Exception $e) {
- Log::info($e->getMessage());
- }
- return $alipay->success();
- }
- /**
- * 支付回调业务处理
- */
- public function order_do_sth($order_no){
- $order = PaymentLogModel::query()->where(['order_no'=>$order_no])->first();
- if(!$order){
- throw new Exception("订单不存在");
- }
- if($order['status']==1){
- return true;
- }
- }
- }
|