75 lines
2.3 KiB
PHP
75 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\enum\user\UserTerminalEnum;
|
|
use app\common\logic\PaymentLogic;
|
|
use app\common\logic\WechatPayServiceMerchantPaymentLogic;
|
|
use app\common\service\pay\WeChatPayMerchantService;
|
|
use app\common\service\pay\WeChatPayService;
|
|
use think\Log;
|
|
|
|
class WechatPayServiceMerchantPayController extends BaseApiController
|
|
{
|
|
|
|
public array $notNeedLogin = ['appPrePay', 'notifyApp', 'refund', 'refundNotify'];
|
|
/**
|
|
* 微信服务商APP支付
|
|
*/
|
|
public function appPrePay()
|
|
{
|
|
$params = $this->request->param();
|
|
\think\facade\Log::info(['微信服务商APP支付接收参数', $params]);
|
|
//订单信息
|
|
$order = WechatPayServiceMerchantPaymentLogic::createPayOrder($params);
|
|
if (false === $order) {
|
|
return $this->fail('支付订单创建失败', $params);
|
|
}
|
|
//支付流程
|
|
$result = (new WeChatPayMerchantService())->wechatPayServiceMerchantAppPay($order);
|
|
|
|
if (false === $result) {
|
|
return $this->fail((new WeChatPayMerchantService())->getError(), $params);
|
|
}
|
|
return $this->success('', $result);
|
|
}
|
|
|
|
/**
|
|
* 申请退款
|
|
*/
|
|
public function refund()
|
|
{
|
|
$params = $this->request->param(); // business_order_no order_type
|
|
$refundOrder = WechatPayServiceMerchantPaymentLogic::createRefundOrder($params);
|
|
if (false === $refundOrder) {
|
|
return $this->fail('退款订单创建失败', $params);
|
|
}
|
|
//支付流程
|
|
$result = (new WeChatPayMerchantService())->refund($refundOrder);
|
|
if (false === $result) {
|
|
return $this->fail((new WeChatPayMerchantService())->getError(), $params);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @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()
|
|
{
|
|
return (new WeChatPayMerchantService())->notify();
|
|
}
|
|
|
|
/**
|
|
* 退款回调
|
|
*/
|
|
public function refundNotify()
|
|
{
|
|
return (new WeChatPayMerchantService())->refundNotify();
|
|
}
|
|
} |