mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
兼容 wap & web 支付回跳地址
This commit is contained in:
parent
cd3d540c2b
commit
0df6a2480e
@ -185,17 +185,18 @@ class Order extends Auth
|
||||
public function payment()
|
||||
{
|
||||
$data = $this->_vali([
|
||||
'back.default' => '', #支付回跳地址
|
||||
'payid.require' => '支付通道不能为空!',
|
||||
'order_no.require' => '订单单号不能为空!',
|
||||
]);
|
||||
$map = ['order_no' => $data['order_no']];
|
||||
$order = $this->app->db->name('ShopOrder')->where($map)->find();
|
||||
if (empty($order)) $this->error('获取订单数据失败,请稍候再试!');
|
||||
if ($order['status'] != 2) $this->error('该订单不能发起支付哦!');
|
||||
if (empty($order)) $this->error('获取订单数据失败!');
|
||||
if ($order['status'] != 2) $this->error('订单不能发起支付哦!');
|
||||
if ($order['payment_status'] > 0) $this->error('订单已经完成支付!');
|
||||
try {
|
||||
$openid = $this->user[UserService::TYPES[$this->type]['auth']] ?? '';
|
||||
$params = PaymentService::build($data['payid'])->create($openid, $order['order_no'], $order['amount_total'], '商城订单支付', '');
|
||||
$params = PaymentService::build($data['payid'])->create($openid, $order['order_no'], $order['amount_total'], '商城订单支付', '', $data['back']);
|
||||
$this->success('获取支付参数成功!', $params);
|
||||
} catch (HttpResponseException $exception) {
|
||||
throw $exception;
|
||||
|
@ -18,7 +18,7 @@ abstract class PaymentService extends Service
|
||||
const PAYMENT_JOINPAY_GZH = 'joinpay_gzh';
|
||||
const PAYMENT_JOINPAY_XCX = 'joinpay_xcx';
|
||||
|
||||
// 微信支付通道
|
||||
// 微信商户通道
|
||||
const PAYMENT_WECHAT_APP = 'wechat_app';
|
||||
const PAYMENT_WECHAT_MWEB = 'wechat_mweb';
|
||||
const PAYMENT_WECHAT_JSAPI = 'wechat_jsapi';
|
||||
@ -190,7 +190,8 @@ abstract class PaymentService extends Service
|
||||
* @param string $payAmount 交易订单金额(元)
|
||||
* @param string $payTitle 交易订单名称
|
||||
* @param string $payRemark 订单订单描述
|
||||
* @param string $returnUrl 支付回跳地址
|
||||
* @return array
|
||||
*/
|
||||
abstract public function create(string $openid, string $orderNo, string $payAmount, string $payTitle, string $payRemark): array;
|
||||
abstract public function create(string $openid, string $orderNo, string $payAmount, string $payTitle, string $payRemark, string $returnUrl = ''): array;
|
||||
}
|
@ -6,7 +6,7 @@ use app\data\service\PaymentService;
|
||||
|
||||
/**
|
||||
* 支付宝支付基础服务
|
||||
* Class JoinPaymentService
|
||||
* Class AliPaymentService
|
||||
* @package app\store\service\payment
|
||||
*/
|
||||
class AliPaymentService extends PaymentService
|
||||
@ -32,13 +32,13 @@ class AliPaymentService extends PaymentService
|
||||
// 应用ID
|
||||
'appid' => static::$config['alipay_appid'],
|
||||
// 支付宝公钥 (1行填写,特别注意,这里是支付宝公钥,不是应用公钥,最好从开发者中心的网页上去复制)
|
||||
'public_key' => static::$config['alipay_public_key'],
|
||||
'public_key' => $this->_trimCertHeader(static::$config['alipay_public_key']),
|
||||
// 支付宝私钥 (1行填写)
|
||||
'private_key' => static::$config['alipay_private_key'],
|
||||
'private_key' => $this->_trimCertHeader(static::$config['alipay_private_key']),
|
||||
// 应用公钥证书(新版资金类接口转 app_cert_sn)
|
||||
'app_cert' => '',
|
||||
# 'app_cert' => '',
|
||||
// 支付宝根证书(新版资金类接口转 alipay_root_cert_sn)
|
||||
'root_cert' => '',
|
||||
# 'root_cert' => '',
|
||||
// 支付成功通知地址
|
||||
'notify_url' => '',
|
||||
// 网页支付回跳地址
|
||||
@ -47,6 +47,20 @@ class AliPaymentService extends PaymentService
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 去除证书内容前后缀
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
private function _trimCertHeader(string $content): string
|
||||
{
|
||||
$search = [
|
||||
'-----BEGIN PUBLIC KEY-----', '-----END PUBLIC KEY-----',
|
||||
'-----BEGIN RSA PRIVATE KEY-----', '-----END RSA PRIVATE KEY-----',
|
||||
];
|
||||
return preg_replace('/\s+/', '', str_replace(trim($content), $search, ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付结果处理
|
||||
* @param string $type 支付通道
|
||||
@ -103,10 +117,11 @@ class AliPaymentService extends PaymentService
|
||||
* @param string $payAmount 交易订单金额(元)
|
||||
* @param string $payTitle 交易订单名称
|
||||
* @param string $payRemark 订单订单描述
|
||||
* @param string $returnUrl 完成回跳地址
|
||||
* @return array
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
public function create(string $openid, string $orderNo, string $payAmount, string $payTitle, string $payRemark): array
|
||||
public function create(string $openid, string $orderNo, string $payAmount, string $payTitle, string $payRemark, string $returnUrl = ''): array
|
||||
{
|
||||
try {
|
||||
if (isset(static::TYPES[static::$type])) {
|
||||
@ -116,6 +131,13 @@ class AliPaymentService extends PaymentService
|
||||
throw new \think\Exception('支付类型[' . static::$type . ']未配置定义!');
|
||||
}
|
||||
$this->params['notify_url'] = sysuri("@data/api.notify/alipay/scene/order/param/{$tradeParam}", [], false, true);
|
||||
if (in_array($tradeType, [static::PAYMENT_ALIPAY_WAP, static::PAYMENT_ALIPAY_WEB])) {
|
||||
if (empty($returnUrl)) {
|
||||
throw new \think\Exception('支付回跳地址不能为空!');
|
||||
} else {
|
||||
$this->params['return_url'] = $returnUrl;
|
||||
}
|
||||
}
|
||||
if ($tradeType === static::PAYMENT_WECHAT_APP) {
|
||||
$payment = \AliPay\App::instance($this->params);
|
||||
} elseif ($tradeType === static::PAYMENT_ALIPAY_WAP) {
|
||||
@ -125,7 +147,9 @@ class AliPaymentService extends PaymentService
|
||||
} else {
|
||||
throw new \think\Exception("支付类型[{$tradeType}]暂时不支持!");
|
||||
}
|
||||
$result = $payment->apply(['out_trade_no' => $orderNo, 'total_amount' => $payAmount, 'subject' => $payTitle, 'body' => $payRemark]);
|
||||
$data = ['out_trade_no' => $orderNo, 'total_amount' => $payAmount, 'subject' => $payTitle];
|
||||
if (!empty($payRemark)) $data['body'] = $payRemark;
|
||||
$result = $payment->apply($data);
|
||||
// 创建支付记录
|
||||
$this->app->db->name('DataPaymentItem')->insert([
|
||||
'order_no' => $orderNo, 'order_name' => $payTitle, 'order_amount' => $payAmount,
|
||||
|
@ -62,10 +62,11 @@ class JoinPaymentService extends PaymentService
|
||||
* @param string $payAmount 交易订单金额(元)
|
||||
* @param string $payTitle 交易订单名称
|
||||
* @param string $payRemark 订单订单描述
|
||||
* @param string $returnUrl 支付回跳地址
|
||||
* @return array
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
public function create(string $openid, string $orderNo, string $payAmount, string $payTitle, string $payRemark): array
|
||||
public function create(string $openid, string $orderNo, string $payAmount, string $payTitle, string $payRemark, string $returnUrl = ''): array
|
||||
{
|
||||
try {
|
||||
if (isset(static::TYPES[static::$type])) {
|
||||
|
@ -52,10 +52,11 @@ class WechatPaymentService extends PaymentService
|
||||
* @param string $payAmount 交易订单金额(元)
|
||||
* @param string $payTitle 交易订单名称
|
||||
* @param string $payRemark 订单订单描述
|
||||
* @param string $returnUrl 支付回跳地址
|
||||
* @return array
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
public function create(string $openid, string $orderNo, string $payAmount, string $payTitle, string $payRemark): array
|
||||
public function create(string $openid, string $orderNo, string $payAmount, string $payTitle, string $payRemark, string $returnUrl = ''): array
|
||||
{
|
||||
try {
|
||||
if (isset(static::TYPES[static::$type])) {
|
||||
|
6
vendor/composer/autoload_classmap.php
vendored
6
vendor/composer/autoload_classmap.php
vendored
@ -202,6 +202,7 @@ return array(
|
||||
'app\\data\\controller\\Config' => $baseDir . '/app/data/controller/Config.php',
|
||||
'app\\data\\controller\\NewsItem' => $baseDir . '/app/data/controller/NewsItem.php',
|
||||
'app\\data\\controller\\NewsMark' => $baseDir . '/app/data/controller/NewsMark.php',
|
||||
'app\\data\\controller\\Payment' => $baseDir . '/app/data/controller/Payment.php',
|
||||
'app\\data\\controller\\ShopGoods' => $baseDir . '/app/data/controller/ShopGoods.php',
|
||||
'app\\data\\controller\\ShopGoodsCate' => $baseDir . '/app/data/controller/ShopGoodsCate.php',
|
||||
'app\\data\\controller\\ShopGoodsMark' => $baseDir . '/app/data/controller/ShopGoodsMark.php',
|
||||
@ -225,14 +226,19 @@ return array(
|
||||
'app\\data\\controller\\api\\Wxapp' => $baseDir . '/app/data/controller/api/Wxapp.php',
|
||||
'app\\data\\controller\\api\\auth\\Address' => $baseDir . '/app/data/controller/api/auth/Address.php',
|
||||
'app\\data\\controller\\api\\auth\\Center' => $baseDir . '/app/data/controller/api/auth/Center.php',
|
||||
'app\\data\\controller\\api\\auth\\Config' => $baseDir . '/app/data/controller/api/auth/Config.php',
|
||||
'app\\data\\controller\\api\\auth\\News' => $baseDir . '/app/data/controller/api/auth/News.php',
|
||||
'app\\data\\controller\\api\\auth\\Order' => $baseDir . '/app/data/controller/api/auth/Order.php',
|
||||
'app\\data\\service\\GoodsService' => $baseDir . '/app/data/service/GoodsService.php',
|
||||
'app\\data\\service\\MessageService' => $baseDir . '/app/data/service/MessageService.php',
|
||||
'app\\data\\service\\NewsService' => $baseDir . '/app/data/service/NewsService.php',
|
||||
'app\\data\\service\\OrderService' => $baseDir . '/app/data/service/OrderService.php',
|
||||
'app\\data\\service\\PaymentService' => $baseDir . '/app/data/service/PaymentService.php',
|
||||
'app\\data\\service\\TruckService' => $baseDir . '/app/data/service/TruckService.php',
|
||||
'app\\data\\service\\UserService' => $baseDir . '/app/data/service/UserService.php',
|
||||
'app\\data\\service\\payment\\AliPaymentService' => $baseDir . '/app/data/service/payment/AliPaymentService.php',
|
||||
'app\\data\\service\\payment\\JoinPaymentService' => $baseDir . '/app/data/service/payment/JoinPaymentService.php',
|
||||
'app\\data\\service\\payment\\WechatPaymentService' => $baseDir . '/app/data/service/payment/WechatPaymentService.php',
|
||||
'app\\index\\controller\\Index' => $baseDir . '/app/index/controller/Index.php',
|
||||
'app\\wechat\\command\\Fans' => $baseDir . '/app/wechat/command/Fans.php',
|
||||
'app\\wechat\\controller\\Config' => $baseDir . '/app/wechat/controller/Config.php',
|
||||
|
6
vendor/composer/autoload_static.php
vendored
6
vendor/composer/autoload_static.php
vendored
@ -330,6 +330,7 @@ class ComposerStaticInit4f89fd0e0503ccf740f2fa5757825d7b
|
||||
'app\\data\\controller\\Config' => __DIR__ . '/../..' . '/app/data/controller/Config.php',
|
||||
'app\\data\\controller\\NewsItem' => __DIR__ . '/../..' . '/app/data/controller/NewsItem.php',
|
||||
'app\\data\\controller\\NewsMark' => __DIR__ . '/../..' . '/app/data/controller/NewsMark.php',
|
||||
'app\\data\\controller\\Payment' => __DIR__ . '/../..' . '/app/data/controller/Payment.php',
|
||||
'app\\data\\controller\\ShopGoods' => __DIR__ . '/../..' . '/app/data/controller/ShopGoods.php',
|
||||
'app\\data\\controller\\ShopGoodsCate' => __DIR__ . '/../..' . '/app/data/controller/ShopGoodsCate.php',
|
||||
'app\\data\\controller\\ShopGoodsMark' => __DIR__ . '/../..' . '/app/data/controller/ShopGoodsMark.php',
|
||||
@ -353,14 +354,19 @@ class ComposerStaticInit4f89fd0e0503ccf740f2fa5757825d7b
|
||||
'app\\data\\controller\\api\\Wxapp' => __DIR__ . '/../..' . '/app/data/controller/api/Wxapp.php',
|
||||
'app\\data\\controller\\api\\auth\\Address' => __DIR__ . '/../..' . '/app/data/controller/api/auth/Address.php',
|
||||
'app\\data\\controller\\api\\auth\\Center' => __DIR__ . '/../..' . '/app/data/controller/api/auth/Center.php',
|
||||
'app\\data\\controller\\api\\auth\\Config' => __DIR__ . '/../..' . '/app/data/controller/api/auth/Config.php',
|
||||
'app\\data\\controller\\api\\auth\\News' => __DIR__ . '/../..' . '/app/data/controller/api/auth/News.php',
|
||||
'app\\data\\controller\\api\\auth\\Order' => __DIR__ . '/../..' . '/app/data/controller/api/auth/Order.php',
|
||||
'app\\data\\service\\GoodsService' => __DIR__ . '/../..' . '/app/data/service/GoodsService.php',
|
||||
'app\\data\\service\\MessageService' => __DIR__ . '/../..' . '/app/data/service/MessageService.php',
|
||||
'app\\data\\service\\NewsService' => __DIR__ . '/../..' . '/app/data/service/NewsService.php',
|
||||
'app\\data\\service\\OrderService' => __DIR__ . '/../..' . '/app/data/service/OrderService.php',
|
||||
'app\\data\\service\\PaymentService' => __DIR__ . '/../..' . '/app/data/service/PaymentService.php',
|
||||
'app\\data\\service\\TruckService' => __DIR__ . '/../..' . '/app/data/service/TruckService.php',
|
||||
'app\\data\\service\\UserService' => __DIR__ . '/../..' . '/app/data/service/UserService.php',
|
||||
'app\\data\\service\\payment\\AliPaymentService' => __DIR__ . '/../..' . '/app/data/service/payment/AliPaymentService.php',
|
||||
'app\\data\\service\\payment\\JoinPaymentService' => __DIR__ . '/../..' . '/app/data/service/payment/JoinPaymentService.php',
|
||||
'app\\data\\service\\payment\\WechatPaymentService' => __DIR__ . '/../..' . '/app/data/service/payment/WechatPaymentService.php',
|
||||
'app\\index\\controller\\Index' => __DIR__ . '/../..' . '/app/index/controller/Index.php',
|
||||
'app\\wechat\\command\\Fans' => __DIR__ . '/../..' . '/app/wechat/command/Fans.php',
|
||||
'app\\wechat\\controller\\Config' => __DIR__ . '/../..' . '/app/wechat/controller/Config.php',
|
||||
|
2
vendor/services.php
vendored
2
vendor/services.php
vendored
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
// This file is automatically generated at:2020-12-10 16:31:45
|
||||
// This file is automatically generated at:2020-12-14 18:23:12
|
||||
declare (strict_types = 1);
|
||||
return array (
|
||||
0 => 'think\\admin\\Library',
|
||||
|
Loading…
x
Reference in New Issue
Block a user