Files
ProxyPanel/app/Http/Controllers/Gateway/PayJs.php
兔姬桑 759cbe58d3 BUG修复
1. 修复Coupon添加失败问题;
2. 修复众多支付渠道无法区别异步回调的问题;
3. 码支付 可以使用在生成环境中;
4.更新Logs
2020-08-05 03:20:32 +08:00

71 lines
1.7 KiB
PHP

<?php
namespace App\Http\Controllers\Gateway;
use App\Http\Models\Payment;
use Auth;
use Log;
use Response;
use Xhat\Payjs\Payjs as Pay;
class PayJs extends AbstractPayment
{
public function purchase($request)
{
$payment = new Payment();
$payment->sn = self::generateGuid();
$payment->user_id = Auth::user()->id;
$payment->oid = $request->input('oid');
$payment->amount = $request->input('amount');
$payment->save();
$result = (new Pay($this->createGateway()))->native([
'body' => parent::$systemConfig['subject_name']? : parent::$systemConfig['website_name'],
'total_fee' => $payment->amount*100,
'out_trade_no' => $payment->sn,
'attach' => '',
'notify_url' => (parent::$systemConfig['website_callback_url']? : parent::$systemConfig['website_url']).'/callback/notify?method=payjs',
]);
if(!$result->return_code){
Log::error('PayJs '.$result->return_msg);
}
$payment->qr_code = $result->qrcode;// 获取收款二维码内容
$payment->save();
return Response::json(['status' => 'success', 'data' => $payment->sn, 'message' => '创建订单成功!']);
}
private function createGateway()
{
return $config = [
'mchid' => self::$systemConfig['payjs_mch_id'], // 配置商户号
'key' => self::$systemConfig['payjs_key'], // 配置通信密钥
];
}
public function notify($request)
{
$data = (new Pay($this->createGateway()))->notify();
if($data['return_code'] == 1){
$this->postPayment($data['out_trade_no'], 6);
exit("success");
}
exit("fail");
}
public function getReturnHTML($request)
{
// TODO: Implement getReturnHTML() method.
}
public function getPurchaseHTML()
{
// TODO: Implement getReturnHTML() method.
}
}