Notify.php 1.3 KB
<?php

namespace app\api\controller;

use addons\epay\library\Service;
use app\common\controller\Api;

/**
 * @ApiInternal
 * 支付回调接口
 */
class Notify extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 微信支付回调
     */
    public function service()
    {
        $type = $this->request->param('type');
        $pay  = Service::checkNotify($type);
        if (!$pay) {
            return '签名错误';
        }
        $time = time();
        $data = $pay->verify();
        $data = json_decode($data, true);
        //输出返回的参数
        $orderModel = new \app\api\model\order\Order();
        if ($data['return_code'] == 'SUCCESS') {

            if ($data['result_code'] == 'SUCCESS') {
                $update_data = [
                    'transaction_id' => $data['transaction_id'],
                    'payment_json'   => json_encode($data),
                    'paytime'       => $time,
                    'status'         => '1',
//                    'pay_price'      => $data['total_fee'],
                ];
                //更新订单信息
                $orderModel->where('order_sn', $data['out_trade_no'])->update($update_data);
            }
        }
        return $pay->success()->send();
    }


}