143 lines
3.4 KiB
PHP
143 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace XuanChen\WoUnicom;
|
|
|
|
use App\Models\Payment;
|
|
use Carbon\Carbon;
|
|
use XuanChen\WoUnicom\Action\Init;
|
|
use XuanChen\WoUnicom\Action\Order;
|
|
use XuanChen\WoUnicom\Action\Query;
|
|
use XuanChen\WoUnicom\Action\Refund;
|
|
use XuanChen\WoUnicom\Action\Sign;
|
|
|
|
/**
|
|
* 沃钱包支付
|
|
*/
|
|
class WoUnicom
|
|
{
|
|
|
|
/**
|
|
* Notes: 下单
|
|
* @Author: 玄尘
|
|
* @Date : 2021/4/30 9:36
|
|
* @return \XuanChen\WoUnicom\Action\Order
|
|
*/
|
|
public function order()
|
|
{
|
|
$action = new Order();
|
|
$action->setConfig();
|
|
|
|
return $action;
|
|
|
|
}
|
|
|
|
/**
|
|
* Notes: 查询订单
|
|
* @Author: 玄尘
|
|
* @Date : 2021/4/30 9:39
|
|
* @return \XuanChen\WoUnicom\Action\Query
|
|
*/
|
|
public function query()
|
|
{
|
|
return (new Query());
|
|
}
|
|
|
|
/**
|
|
* Notes: 退款
|
|
* @Author: 玄尘
|
|
* @Date : 2021/4/30 9:37
|
|
*/
|
|
public function refund()
|
|
{
|
|
$action = new Refund();
|
|
$action->setConfig();
|
|
|
|
return $action;
|
|
|
|
}
|
|
|
|
/**
|
|
* Notes: 验签
|
|
* @Author: 玄尘
|
|
* @Date : 2021/5/11 11:51
|
|
* @param $params
|
|
*/
|
|
public function sign()
|
|
{
|
|
$action = new Sign();
|
|
$action->setConfig();
|
|
|
|
return $action;
|
|
}
|
|
|
|
/**
|
|
* Notes: 回调数据
|
|
* @Author: 玄尘
|
|
* @Date : 2021/5/11 15:54
|
|
* @param $params
|
|
*/
|
|
public function callback($inputs)
|
|
{
|
|
if (empty($inputs)) {
|
|
return '缺少必要参数';
|
|
}
|
|
|
|
$params = str_replace('$', '&', $inputs);
|
|
parse_str($params, $data);
|
|
|
|
//验签
|
|
$res = $this->sign()->setParams($data)->start();
|
|
|
|
//日志
|
|
$this->unicomLog($data, $res);
|
|
|
|
//验签成功
|
|
if ($res === true) {
|
|
|
|
$order = \App\Models\Order::where('orderid', $data['orderid'])->first();
|
|
if ($order && $order->state == 'UNPAY') {
|
|
$payment = \App\Models\Payment::where('orderable_type', get_class($order))
|
|
->where('orderable_id', $order->id)
|
|
->latest()
|
|
->first();
|
|
|
|
$payment->state = 'SUCCESS';
|
|
$payment->out_trade_no = $data['payfloodid'];
|
|
$payment->type = 'UNICOM';
|
|
$payment->paid_at = Carbon::now();
|
|
$payment->save();
|
|
$order->paid();
|
|
}
|
|
|
|
return 'SUCCESS';
|
|
} else {
|
|
return '验签失败';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Notes: 输入日志
|
|
* @Author: 玄尘
|
|
* @Date : 2021/5/11 15:58
|
|
* @param $data
|
|
*/
|
|
public function unicomLog($data, $str)
|
|
{
|
|
$inputData = [
|
|
'orderId' => $data['orderid'],
|
|
'payFloodId' => $data['payfloodid'],
|
|
'payResult' => $data['payresult'],
|
|
'payBalance' => $data['paybalance'],
|
|
'paymentBalanceDetail' => $data['paymentbalancedetail'],
|
|
'respTime' => $data['resptime'],
|
|
'source' => [
|
|
'data' => $data,
|
|
'check_sign' => $str,
|
|
],
|
|
];
|
|
|
|
return \App\Models\Wounicom::create($inputData);
|
|
}
|
|
|
|
}
|