2023-07-15 10:16:32 +08:00
|
|
|
|
<?php
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
|
|
|
|
// | 开源版本可自由商用,可去除界面版权logo
|
|
|
|
|
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
|
|
|
|
// | github下载:https://github.com/likeshop-github/likeadmin
|
|
|
|
|
// | 访问官网:https://www.likeadmin.cn
|
|
|
|
|
// | likeadmin团队 版权所有 拥有最终解释权
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | author: likeadminTeam
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use app\api\validate\PayValidate;
|
2023-11-20 10:48:44 +08:00
|
|
|
|
use app\common\enum\PayEnum;
|
2023-07-15 10:16:32 +08:00
|
|
|
|
use app\common\enum\user\UserTerminalEnum;
|
|
|
|
|
use app\common\logic\PaymentLogic;
|
2023-11-20 10:48:44 +08:00
|
|
|
|
use app\common\logic\PayRequestLogic;
|
|
|
|
|
use app\common\model\Company;
|
2023-07-15 10:16:32 +08:00
|
|
|
|
use app\common\service\pay\WeChatPayService;
|
2023-07-24 14:11:43 +08:00
|
|
|
|
use think\facade\Log;
|
2023-07-15 10:16:32 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 支付
|
|
|
|
|
* Class PayController
|
|
|
|
|
* @package app\api\controller
|
|
|
|
|
*/
|
|
|
|
|
class PayController extends BaseApiController
|
|
|
|
|
{
|
|
|
|
|
|
2023-07-24 14:11:43 +08:00
|
|
|
|
public array $notNeedLogin = ['notifyMnp', 'notifyOa', 'notifyApp'];
|
2023-07-15 10:16:32 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 支付方式
|
|
|
|
|
* @return \think\response\Json
|
|
|
|
|
* @author 段誉
|
|
|
|
|
* @date 2023/2/24 17:54
|
|
|
|
|
*/
|
|
|
|
|
public function payWay()
|
|
|
|
|
{
|
|
|
|
|
$params = (new PayValidate())->goCheck('payway');
|
|
|
|
|
$result = PaymentLogic::getPayWay($this->userId, $this->userInfo['terminal'], $params);
|
|
|
|
|
if ($result === false) {
|
|
|
|
|
return $this->fail(PaymentLogic::getError());
|
|
|
|
|
}
|
|
|
|
|
return $this->data($result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 预支付
|
|
|
|
|
* @return \think\response\Json
|
|
|
|
|
* @author 段誉
|
|
|
|
|
* @date 2023/2/28 14:21
|
|
|
|
|
*/
|
|
|
|
|
public function prepay()
|
|
|
|
|
{
|
|
|
|
|
$params = (new PayValidate())->post()->goCheck();
|
|
|
|
|
//订单信息
|
|
|
|
|
$order = PaymentLogic::getPayOrderInfo($params);
|
|
|
|
|
if (false === $order) {
|
|
|
|
|
return $this->fail(PaymentLogic::getError(), $params);
|
|
|
|
|
}
|
2023-11-20 10:48:44 +08:00
|
|
|
|
// 请求支付系统
|
2023-11-20 10:58:44 +08:00
|
|
|
|
$companyInfo = Company::where(['id' => $this->userInfo['company_id']])->find();
|
2023-11-20 10:48:44 +08:00
|
|
|
|
$requestData = [
|
|
|
|
|
'street' => $companyInfo['street'],
|
|
|
|
|
'order_from' => 12,
|
|
|
|
|
'order_type' => 101,
|
|
|
|
|
'pay_user_role' => $this->userInfo['group_id'],
|
|
|
|
|
'pay_user_info' => $this->userInfo,
|
2023-11-20 12:06:19 +08:00
|
|
|
|
'business_order_no' => $order['sn'],
|
2023-11-20 14:21:07 +08:00
|
|
|
|
'total_fee' => intval(bcmul($order['order_amount'], 100)),
|
2023-11-20 10:48:44 +08:00
|
|
|
|
'business_callback_url' => (string)url('pay/notifyApp', [], false, true)
|
|
|
|
|
];
|
2023-11-20 12:06:19 +08:00
|
|
|
|
$result = PayRequestLogic::getPrePayId($requestData);
|
2023-07-15 10:16:32 +08:00
|
|
|
|
if (false === $result) {
|
|
|
|
|
return $this->fail(PaymentLogic::getError(), $params);
|
|
|
|
|
}
|
2023-11-20 12:06:19 +08:00
|
|
|
|
return $this->success('', $result['data']);
|
2023-07-15 10:16:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 获取支付状态
|
|
|
|
|
* @return \think\response\Json
|
|
|
|
|
* @author 段誉
|
|
|
|
|
* @date 2023/3/1 16:23
|
|
|
|
|
*/
|
|
|
|
|
public function payStatus()
|
|
|
|
|
{
|
|
|
|
|
$params = (new PayValidate())->goCheck('status', ['user_id' => $this->userId]);
|
|
|
|
|
$result = PaymentLogic::getPayStatus($params);
|
|
|
|
|
if ($result === false) {
|
|
|
|
|
return $this->fail(PaymentLogic::getError());
|
|
|
|
|
}
|
|
|
|
|
return $this->data($result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 小程序支付回调
|
|
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
|
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
|
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
|
|
|
|
|
* @throws \ReflectionException
|
|
|
|
|
* @throws \Throwable
|
|
|
|
|
* @author 段誉
|
|
|
|
|
* @date 2023/2/28 14:21
|
|
|
|
|
*/
|
|
|
|
|
public function notifyMnp()
|
|
|
|
|
{
|
|
|
|
|
return (new WeChatPayService(UserTerminalEnum::WECHAT_MMP))->notify();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 公众号支付回调
|
|
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
|
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
|
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
|
|
|
|
|
* @throws \ReflectionException
|
|
|
|
|
* @throws \Throwable
|
|
|
|
|
* @author 段誉
|
|
|
|
|
* @date 2023/2/28 14:21
|
|
|
|
|
*/
|
|
|
|
|
public function notifyOa()
|
|
|
|
|
{
|
|
|
|
|
return (new WeChatPayService(UserTerminalEnum::WECHAT_OA))->notify();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-07-24 13:38:45 +08:00
|
|
|
|
/**
|
|
|
|
|
* @notes app支付回调
|
|
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
|
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
|
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
|
|
|
|
|
* @throws \ReflectionException
|
|
|
|
|
* @throws \Throwable
|
|
|
|
|
* @date 2023/2/28 14:21
|
|
|
|
|
*/
|
|
|
|
|
public function notifyApp()
|
|
|
|
|
{
|
2023-11-21 10:40:34 +08:00
|
|
|
|
try {
|
|
|
|
|
$param = $this->request->param();
|
|
|
|
|
Log::info(['支付系统回调', $param])
|
|
|
|
|
(new WeChatPayService(UserTerminalEnum::ANDROID))->notify($param);
|
|
|
|
|
return $this->success('ok');
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return $this->fail($e->getMessage());
|
|
|
|
|
}
|
2023-07-24 13:38:45 +08:00
|
|
|
|
}
|
2023-07-15 10:16:32 +08:00
|
|
|
|
}
|