调整支付
This commit is contained in:
parent
6c71eb8c11
commit
75c3787759
@ -5,8 +5,7 @@ namespace app\api\controller;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\logic\PayNotifyLogic;
|
||||
use app\common\model\retail\Cashierclass;
|
||||
use Webman\Config;
|
||||
use Yansongda\Pay\Pay;
|
||||
use app\common\service\pay\PayService;
|
||||
|
||||
/**
|
||||
* 支付
|
||||
@ -20,19 +19,11 @@ class PayController extends BaseApiController
|
||||
|
||||
/**
|
||||
* @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()
|
||||
{
|
||||
$config = Config::get('payment');
|
||||
Pay::config($config);
|
||||
$result = Pay::wechat()->callback(Request()->post());
|
||||
$app=new PayService(1);
|
||||
$result = $app->wechat->callback(Request()->post());
|
||||
if($result && $result->event_type=='TRANSACTION.SUCCESS'){
|
||||
$ciphertext=$result->resource['ciphertext'];
|
||||
if ($ciphertext['trade_state'] === 'SUCCESS') {
|
||||
@ -46,12 +37,10 @@ class PayController extends BaseApiController
|
||||
return true;
|
||||
}
|
||||
PayNotifyLogic::handle('cashierclass', $ciphertext['out_trade_no'], $ciphertext);
|
||||
Pay::wechat()->success();
|
||||
$app->wechat->success();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return (new WeChatPayService(UserTerminalEnum::WECHAT_MMP))->notify();
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class PayEnum
|
||||
|
||||
/**
|
||||
* 支付类型
|
||||
* @BALANCE 余额
|
||||
* @BALANCE_PAY 余额
|
||||
* @WECHAT_PAY 微信支付
|
||||
* @ALIPAY 支付宝
|
||||
* @WECHAT_PAY_APP 微信APP
|
||||
|
@ -64,10 +64,6 @@ class PayNotifyLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
// 更新充值订单状态
|
||||
// $order->transaction_id = $extra['transaction_id'];
|
||||
// $order->paid = PayEnum::ISPAID;
|
||||
// $order->save();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,28 +1,12 @@
|
||||
<?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;
|
||||
use app\common\service\pay\PayService;
|
||||
|
||||
/**
|
||||
* 支付逻辑
|
||||
@ -47,21 +31,12 @@ class PaymentLogic extends BaseLogic
|
||||
{
|
||||
// 支付编号-仅为微信支付预置(同一商户号下不同客户端支付需使用唯一订单号)
|
||||
$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,
|
||||
@ -75,38 +50,13 @@ class PaymentLogic extends BaseLogic
|
||||
],
|
||||
'attach' => $from
|
||||
];
|
||||
|
||||
$config = Config::get('payment');
|
||||
Pay::config($config);
|
||||
$result = Pay::wechat()->mini($order)->toArray();
|
||||
$wechat=new PayService(1);
|
||||
$result = $wechat->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;
|
||||
}
|
||||
}
|
||||
|
66
app/common/service/pay/PayService.php
Normal file
66
app/common/service/pay/PayService.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\service\pay;
|
||||
|
||||
use app\common\model\user\UserAuth;
|
||||
use Webman\Config;
|
||||
use Yansongda\Pay\Pay;
|
||||
|
||||
/**
|
||||
* 支付
|
||||
* Class PayService
|
||||
* @package app\common\server
|
||||
*/
|
||||
class PayService extends BasePayService
|
||||
{
|
||||
/**
|
||||
* 授权信息
|
||||
* @var UserAuth|array|\think\Model
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
|
||||
/**
|
||||
* Pay配置
|
||||
* @var
|
||||
*/
|
||||
public $config;
|
||||
|
||||
|
||||
/**
|
||||
* Pay实例
|
||||
* @var
|
||||
*/
|
||||
public $wechat;
|
||||
protected $alipay;
|
||||
|
||||
|
||||
/**
|
||||
* 当前使用客户端
|
||||
* @var
|
||||
*/
|
||||
protected $terminal;
|
||||
|
||||
|
||||
/**
|
||||
* 初始化微信支付配置
|
||||
* @param $terminal //用户终端
|
||||
* @param null $userId //用户id(获取授权openid)
|
||||
*/
|
||||
public function __construct($terminal, $userId = null)
|
||||
{
|
||||
$this->terminal = $terminal;
|
||||
$config = Config::get('payment');
|
||||
Pay::config($config);
|
||||
if ($userId !== null) {
|
||||
$this->auth = UserAuth::where(['user_id' => $userId, 'terminal' => $terminal])->findOrEmpty();
|
||||
}
|
||||
$this->wechat=Pay::wechat();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user