diff --git a/composer.json b/composer.json index 007daad..c64b5ca 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,8 @@ "webman/redis-queue": "^2.1", "ext-curl": "*", "ext-openssl": "*", - "yansongda/pay": "~3.0" + "yansongda/pay": "~3.0", + "endroid/qrcode": "^6.0" }, "suggest": { "ext-event": "For better performance. " diff --git a/composer.lock b/composer.lock index 6e4b6c7..3e27cf9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e790d656225abb33ded4bf69b52206b7", + "content-hash": "48402b888575b7a0657f0839da9eba60", "packages": [ { "name": "aliyuncs/oss-sdk-php", @@ -52,6 +52,61 @@ "time": "2024-10-28T10:41:12+00:00" }, { + "name": "bacon/bacon-qr-code", + "version": "v3.0.3", + "source": { + "type": "git", + "url": "https://github.com/Bacon/BaconQrCode.git", + "reference": "36a1cb2b81493fa5b82e50bf8068bf84d1542563" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Bacon/BaconQrCode/zipball/36a1cb2b81493fa5b82e50bf8068bf84d1542563", + "reference": "36a1cb2b81493fa5b82e50bf8068bf84d1542563", + "shasum": "" + }, + "require": { + "dasprid/enum": "^1.0.3", + "ext-iconv": "*", + "php": "^8.1" + }, + "require-dev": { + "phly/keep-a-changelog": "^2.12", + "phpunit/phpunit": "^10.5.11 || ^11.0.4", + "spatie/phpunit-snapshot-assertions": "^5.1.5", + "spatie/pixelmatch-php": "^1.2.0", + "squizlabs/php_codesniffer": "^3.9" + }, + "suggest": { + "ext-imagick": "to generate QR code images" + }, + "type": "library", + "autoload": { + "psr-4": { + "BaconQrCode\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Ben Scholzen 'DASPRiD'", + "email": "mail@dasprids.de", + "homepage": "https://dasprids.de/", + "role": "Developer" + } + ], + "description": "BaconQrCode is a QR code generator for PHP.", + "homepage": "https://github.com/Bacon/BaconQrCode", + "support": { + "issues": "https://github.com/Bacon/BaconQrCode/issues", + "source": "https://github.com/Bacon/BaconQrCode/tree/v3.0.3" + }, + "time": "2025-11-19T17:15:36+00:00" + }, + { "name": "brick/math", "version": "0.14.1", "source": { @@ -505,6 +560,56 @@ "time": "2024-02-09T16:56:22+00:00" }, { + "name": "dasprid/enum", + "version": "1.0.7", + "source": { + "type": "git", + "url": "https://github.com/DASPRiD/Enum.git", + "reference": "b5874fa9ed0043116c72162ec7f4fb50e02e7cce" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/DASPRiD/Enum/zipball/b5874fa9ed0043116c72162ec7f4fb50e02e7cce", + "reference": "b5874fa9ed0043116c72162ec7f4fb50e02e7cce", + "shasum": "" + }, + "require": { + "php": ">=7.1 <9.0" + }, + "require-dev": { + "phpunit/phpunit": "^7 || ^8 || ^9 || ^10 || ^11", + "squizlabs/php_codesniffer": "*" + }, + "type": "library", + "autoload": { + "psr-4": { + "DASPRiD\\Enum\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Ben Scholzen 'DASPRiD'", + "email": "mail@dasprids.de", + "homepage": "https://dasprids.de/", + "role": "Developer" + } + ], + "description": "PHP 7.1 enum implementation", + "keywords": [ + "enum", + "map" + ], + "support": { + "issues": "https://github.com/DASPRiD/Enum/issues", + "source": "https://github.com/DASPRiD/Enum/tree/1.0.7" + }, + "time": "2025-09-16T12:23:56+00:00" + }, + { "name": "doctrine/annotations", "version": "2.0.2", "source": { @@ -749,6 +854,79 @@ "time": "2024-02-05T11:56:58+00:00" }, { + "name": "endroid/qrcode", + "version": "6.0.9", + "source": { + "type": "git", + "url": "https://github.com/endroid/qr-code.git", + "reference": "21e888e8597440b2205e2e5c484b6c8e556bcd1a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/endroid/qr-code/zipball/21e888e8597440b2205e2e5c484b6c8e556bcd1a", + "reference": "21e888e8597440b2205e2e5c484b6c8e556bcd1a", + "shasum": "" + }, + "require": { + "bacon/bacon-qr-code": "^3.0", + "php": "^8.2" + }, + "require-dev": { + "endroid/quality": "dev-main", + "ext-gd": "*", + "khanamiryan/qrcode-detector-decoder": "^2.0.2", + "setasign/fpdf": "^1.8.2" + }, + "suggest": { + "ext-gd": "Enables you to write PNG images", + "khanamiryan/qrcode-detector-decoder": "Enables you to use the image validator", + "roave/security-advisories": "Makes sure package versions with known security issues are not installed", + "setasign/fpdf": "Enables you to use the PDF writer" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.x-dev" + } + }, + "autoload": { + "psr-4": { + "Endroid\\QrCode\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jeroen van den Enden", + "email": "info@endroid.nl" + } + ], + "description": "Endroid QR Code", + "homepage": "https://github.com/endroid/qr-code", + "keywords": [ + "code", + "endroid", + "php", + "qr", + "qrcode" + ], + "support": { + "issues": "https://github.com/endroid/qr-code/issues", + "source": "https://github.com/endroid/qr-code/tree/6.0.9" + }, + "funding": [ + { + "url": "https://github.com/endroid", + "type": "github" + } + ], + "abandoned": "endroid/qr-code", + "time": "2025-07-13T19:59:45+00:00" + }, + { "name": "fakerphp/faker", "version": "v1.24.1", "source": { diff --git a/plugin/piadmin/app/controller/v1/pay/PayController.php b/plugin/piadmin/app/controller/v1/pay/PayController.php index 585d140..2f21553 100644 --- a/plugin/piadmin/app/controller/v1/pay/PayController.php +++ b/plugin/piadmin/app/controller/v1/pay/PayController.php @@ -14,7 +14,6 @@ class PayController extends BaseController { $params = requestOnly([ 'price' => '', - 'type' => 'wechat' ]); $qrurl = $payService->getQrUrl($params); return success($qrurl); diff --git a/plugin/piadmin/app/route/v1/pay.php b/plugin/piadmin/app/route/v1/pay.php index 4b49b7e..25200a4 100644 --- a/plugin/piadmin/app/route/v1/pay.php +++ b/plugin/piadmin/app/route/v1/pay.php @@ -9,6 +9,9 @@ use Webman\Route; Route::group('/piadmin/v1/pay', function () { //获取支付二维码 Route::post('/getQrUrl', [PayController::class, 'getQrUrl']); + + //回调 + })->middleware([ UserAuthorizationMiddleware::class, ]); diff --git a/plugin/piadmin/app/service/pay/PayService.php b/plugin/piadmin/app/service/pay/PayService.php index d17b277..49d80ad 100644 --- a/plugin/piadmin/app/service/pay/PayService.php +++ b/plugin/piadmin/app/service/pay/PayService.php @@ -10,19 +10,25 @@ class PayService extends BaseService { public function getQrUrl($params) { - $order = [ + $wechatOrder = [ 'out_trade_no' => time().'', 'description' => 'subject-测试', 'amount' => [ 'total' => $params['price'] * 100, ], ]; - if ($params['type'] == 'wechat') { - $qrurl = WechatPay::getQrUrl($order); - } else { - $qrurl = AliPay::getQrUrl($order); - } - return $qrurl; + + $aliOrder = [ + 'out_trade_no' => time(), + 'total_amount' => $params['price'] . '', + 'subject' => 'yansongda 测试 - 01', + ]; + $wechatqrurl = WechatPay::getQrUrl($wechatOrder); + $aliqrurl = AliPay::getQrUrl($aliOrder); + return [ + 'wechat' => $wechatqrurl, + 'ali' => $aliqrurl, + ]; } } \ No newline at end of file diff --git a/plugin/piadmin/app/utils/pay/PayUtils.php b/plugin/piadmin/app/utils/pay/PayUtils.php new file mode 100644 index 0000000..470bbbc --- /dev/null +++ b/plugin/piadmin/app/utils/pay/PayUtils.php @@ -0,0 +1,48 @@ +build(); + header('Content-Type: '.$qrCode->getMimeType()); + return $qrCode->getDataUri(); + } catch (Exception $e) { + // 记录错误日志 + error_log('QR Code generation error: ' . $e->getMessage()); + throw $e; + } + } + +} diff --git a/plugin/piadmin/app/utils/pay/wechat/WechatPay.php b/plugin/piadmin/app/utils/pay/wechat/WechatPay.php index c01c827..343c46f 100644 --- a/plugin/piadmin/app/utils/pay/wechat/WechatPay.php +++ b/plugin/piadmin/app/utils/pay/wechat/WechatPay.php @@ -1,6 +1,7 @@ scan($order); return [ 'code_url' => $result['code_url'], - 'qr' => $result['code_url'] + 'qr' => PayUtils::generateQrCode($result['code_url']) ]; }