113 lines
3.8 KiB
PHP
113 lines
3.8 KiB
PHP
<?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\common\logic;
|
||
|
||
|
||
use app\common\enum\PayEnum;
|
||
use app\common\service\pay\WeChatPayService;
|
||
use Webman\Config;
|
||
use Yansongda\Pay\Pay;
|
||
use app\common\model\user\UserAuth;
|
||
use GuzzleHttp\Command\Guzzle\GuzzleClient;
|
||
use Symfony\Component\HttpClient\HttpClient;
|
||
use Yansongda\Artful\Contract\HttpClientInterface;
|
||
|
||
/**
|
||
* 支付逻辑
|
||
* Class PaymentLogic
|
||
* @package app\common\logic
|
||
*/
|
||
class PaymentLogic extends BaseLogic
|
||
{
|
||
|
||
/**
|
||
* @notes 支付
|
||
* @param $payWay
|
||
* @param $from
|
||
* @param $order
|
||
* @param $terminal
|
||
* @param $redirectUrl
|
||
* @return array|false|mixed|string
|
||
* @author 段誉
|
||
* @date 2023/2/28 12:15
|
||
*/
|
||
public static function pay($payWay, $from, $order, $terminal, $redirectUrl)
|
||
{
|
||
// 支付编号-仅为微信支付预置(同一商户号下不同客户端支付需使用唯一订单号)
|
||
$paySn = $order['number'];
|
||
// if ($payWay == PayEnum::WECHAT_PAY) {
|
||
// $paySn = self::formatOrderSn($order['sn'], $terminal);
|
||
// }
|
||
|
||
|
||
if ($order['actual'] == 0) {
|
||
PayNotifyLogic::handle($from, $order['number']);
|
||
return ['pay_way' => PayEnum::BALANCE_PAY];
|
||
}
|
||
switch ($payWay) {
|
||
case PayEnum::WECHAT_PAY:
|
||
// $payService = (new WeChatPayService($terminal, $order['uid'] ?? null));
|
||
// $order['pay_sn'] = $paySn;
|
||
// $order['redirect_url'] = $redirectUrl;
|
||
// $result = $payService->pay($from, $order);
|
||
$auth = UserAuth::where(['user_id' => $order['uid'], 'terminal' => $terminal])->findOrEmpty();
|
||
$order = [
|
||
'out_trade_no' => $paySn,
|
||
'description' => '商品',
|
||
'amount' => [
|
||
'total' => intval($order['actual'] * 100),
|
||
'currency' => 'CNY',
|
||
],
|
||
"payer" => [
|
||
"openid" => $auth['openid'] ?? 0
|
||
],
|
||
'attach' => $from
|
||
];
|
||
|
||
$config = Config::get('payment');
|
||
Pay::config($config);
|
||
$result = Pay::wechat()->mini($order)->toArray();
|
||
break;
|
||
default:
|
||
self::$error = '订单异常';
|
||
$result = false;
|
||
}
|
||
|
||
// if (false === $result && !self::hasError()) {
|
||
// d($payService->getError());
|
||
// self::setError($payService->getError());
|
||
// }
|
||
return $result;
|
||
}
|
||
|
||
|
||
|
||
|
||
/**
|
||
* @notes 设置订单号 支付回调时截取前面的单号 18个
|
||
* @param $orderSn
|
||
* @param $terminal
|
||
* @return string
|
||
* @author 段誉
|
||
* @date 2023/3/1 16:31
|
||
* @remark 回调时使用了不同的回调地址,导致跨客户端支付时(例如小程序,公众号)可能出现201,商户订单号重复错误
|
||
*/
|
||
public static function formatOrderSn($orderSn, $terminal)
|
||
{
|
||
$suffix = mb_substr(time(), -4);
|
||
return $orderSn . $terminal . $suffix;
|
||
}
|
||
}
|