diff --git a/app/Http/Controllers/Manager/OrdersController.php b/app/Http/Controllers/Manager/OrdersController.php index 165b6c2..2f98115 100644 --- a/app/Http/Controllers/Manager/OrdersController.php +++ b/app/Http/Controllers/Manager/OrdersController.php @@ -6,6 +6,7 @@ namespace App\Http\Controllers\Manager; use AlicFeng\IdentityCard\InfoHelper; use App\Customer; use App\Events\OrderAssigned; +use App\Libs\AlipayF2F; use App\Libs\WxMicroPay; use App\Models\Area; use App\Models\Balance; @@ -730,14 +731,18 @@ class OrdersController extends CommonController "errormsg" => $res->getMessage() ]); } - return response()->json($res); + return response()->json(true); break; case "alipay": //todo:支付宝支付实现 - return response()->json([ - "errorcode" => 60003, - "errormsg" => request()->auth_code - ]); + $res = (new AlipayF2F())->test(); + if (!$res["status"]) { + return response()->json([ + "errorcode" => $res["code"], + "errormsg" => $res["msg"] + ]); + } + return response()->json(true); break; default: return response()->json([ diff --git a/app/Libs/Alipay.class.php b/app/Libs/Alipay.class.php deleted file mode 100644 index dba7a02..0000000 --- a/app/Libs/Alipay.class.php +++ /dev/null @@ -1,61 +0,0 @@ -config = config("pay.alipay"); - } - - public function test() - { - $order = [ - 'out_trade_no' => time(), - 'total_amount' => '1', - 'subject' => 'test subject - 测试', - ]; - - $alipay = Pay::alipay($this->config)->scan($order); - return $alipay->send();// laravel 框架中请直接 `return $alipay` - } - - public function return() - { - $data = Pay::alipay($this->config)->verify(); // 是的,验签就这么简单! - - // 订单号:$data->out_trade_no - // 支付宝交易号:$data->trade_no - // 订单总金额:$data->total_amount - } - - public function notify() - { - $alipay = Pay::alipay($this->config); - - try { - $data = $alipay->verify(); // 是的,验签就这么简单! - - // 请自行对 trade_status 进行判断及其它逻辑进行判断,在支付宝的业务通知中,只有交易通知状态为 TRADE_SUCCESS 或 TRADE_FINISHED 时,支付宝才会认定为买家付款成功。 - // 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号; - // 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额); - // 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email); - // 4、验证app_id是否为该商户本身。 - // 5、其它业务逻辑情况 - - Log::debug('Alipay notify', $data->all()); - } catch (\Exception $e) { - // $e->getMessage(); - } - - return $alipay->success(); - } -} diff --git a/app/Libs/AlipayF2F.class.php b/app/Libs/AlipayF2F.class.php new file mode 100644 index 0000000..5a78f30 --- /dev/null +++ b/app/Libs/AlipayF2F.class.php @@ -0,0 +1,63 @@ +auth_code; + $result = Factory::setOptions($this->getOptions())::payment()->faceToFace("这是一个测试商品", time(), "0.01", $auth_code); + $responseChecker = new ResponseChecker(); + //处理响应或异常 + if ($responseChecker->success($result)) { + return [ + "status" => true + ]; + } else { + return [ + "status" => false, + "code" => $result->code, + "msg" => $result->msg + ]; + } + } catch (\Exception $exception) { + return [ + "status" => false, + "code" => $exception->getCode(), + "msg" => $exception->getMessage() + ]; + } + } + + public function getOptions() + { + $options = new Config(); + $options->protocol = 'https'; + $options->gatewayHost = 'openapi.alipay.com'; + $options->signType = 'RSA2'; + + $options->appId = env("ALI_APP_ID"); + $options->alipayCertPath = env("ALI_CERT_ALIPAY"); + $options->alipayRootCertPath = env("ALI_CERT_ROOT"); + $options->merchantCertPath = env("ALI_CERT_APP"); + + // 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中 + $options->merchantPrivateKey = env("ALI_PRIVATE_KEY"); + //注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可 + $options->alipayPublicKey = env("ALI_PUBLIC_KEY"); + + //可设置异步通知接收服务地址(可选) + $options->notifyUrl = ""; + + //可设置AES密钥,调用AES加解密相关接口时需要(可选) + $options->encryptKey = ""; + + return $options; + } +} diff --git a/composer.json b/composer.json index a37317c..31afcba 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "require": { "php": "^7.2.5", "alicfeng/identity-card": "^3.1", + "alipaysdk/easysdk": "^2.2", "fideloper/proxy": "^4.2", "fruitcake/laravel-cors": "^1.0", "guzzlehttp/guzzle": "^6.3", diff --git a/composer.lock b/composer.lock index 2fc763f..7990f45 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,176 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b8ff78bfb22a69de3e425d40b2699815", + "content-hash": "2e1535f199098b30f3943fb68b33b70d", "packages": [ + { + "name": "adbario/php-dot-notation", + "version": "2.2.0", + "source": { + "type": "git", + "url": "https://github.com/adbario/php-dot-notation.git", + "reference": "eee4fc81296531e6aafba4c2bbccfc5adab1676e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/adbario/php-dot-notation/zipball/eee4fc81296531e6aafba4c2bbccfc5adab1676e", + "reference": "eee4fc81296531e6aafba4c2bbccfc5adab1676e", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-json": "*", + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.0|^5.0|^6.0", + "squizlabs/php_codesniffer": "^3.0" + }, + "type": "library", + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Adbar\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Riku Särkinen", + "email": "riku@adbar.io" + } + ], + "description": "PHP dot notation access to arrays", + "homepage": "https://github.com/adbario/php-dot-notation", + "keywords": [ + "ArrayAccess", + "dotnotation" + ], + "time": "2019-01-01T23:59:15+00:00" + }, + { + "name": "alibabacloud/tea", + "version": "3.1.21", + "source": { + "type": "git", + "url": "https://github.com/aliyun/tea-php.git", + "reference": "379faffe240ee97134cf3f796cb28059f9fb7fa9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/aliyun/tea-php/zipball/379faffe240ee97134cf3f796cb28059f9fb7fa9", + "reference": "379faffe240ee97134cf3f796cb28059f9fb7fa9", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "adbario/php-dot-notation": "^2.2", + "ext-curl": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-openssl": "*", + "ext-simplexml": "*", + "ext-xmlwriter": "*", + "guzzlehttp/guzzle": "^6.3|^7.0", + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "*", + "symfony/dotenv": "^3.4", + "symfony/var-dumper": "^3.4" + }, + "suggest": { + "ext-sockets": "To use client-side monitoring" + }, + "type": "library", + "autoload": { + "psr-4": { + "AlibabaCloud\\Tea\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Alibaba Cloud SDK", + "email": "sdk-team@alibabacloud.com", + "homepage": "http://www.alibabacloud.com" + } + ], + "description": "Client of Tea for PHP", + "homepage": "https://www.alibabacloud.com/", + "keywords": [ + "alibabacloud", + "client", + "cloud", + "tea" + ], + "time": "2021-03-15T03:31:41+00:00" + }, + { + "name": "alibabacloud/tea-fileform", + "version": "0.3.4", + "source": { + "type": "git", + "url": "https://github.com/alibabacloud-sdk-php/tea-fileform.git", + "reference": "4bf0c75a045c8115aa8cb1a394bd08d8bb833181" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/alibabacloud-sdk-php/tea-fileform/zipball/4bf0c75a045c8115aa8cb1a394bd08d8bb833181", + "reference": "4bf0c75a045c8115aa8cb1a394bd08d8bb833181", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "alibabacloud/tea": "^3.0", + "php": ">5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35|^5.4.3" + }, + "type": "library", + "autoload": { + "psr-4": { + "AlibabaCloud\\Tea\\FileForm\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Alibaba Cloud SDK", + "email": "sdk-team@alibabacloud.com" + } + ], + "description": "Alibaba Cloud Tea File Library for PHP", + "time": "2020-12-01T07:24:35+00:00" + }, { "name": "alicfeng/identity-card", "version": "v3.1.0", @@ -61,6 +229,71 @@ ], "time": "2020-02-23T14:37:36+00:00" }, + { + "name": "alipaysdk/easysdk", + "version": "2.2.0", + "source": { + "type": "git", + "url": "https://github.com/alipay/alipay-easysdk.git", + "reference": "7a1cfa83c7e140bded957498ea072c77611e6480" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/alipay/alipay-easysdk/zipball/7a1cfa83c7e140bded957498ea072c77611e6480", + "reference": "7a1cfa83c7e140bded957498ea072c77611e6480", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "adbario/php-dot-notation": "^2.2", + "alibabacloud/tea": "^3.1", + "alibabacloud/tea-fileform": "^0.3.2", + "danielstjules/stringy": "^3.1", + "ext-ctype": "*", + "ext-curl": "*", + "ext-dom": "*", + "ext-fileinfo": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-openssl": "*", + "ext-simplexml": "*", + "ext-xmlwriter": "*", + "guzzlehttp/guzzle": ">=6.3", + "mtdowling/jmespath.php": "^2.4", + "php": ">=7.0", + "pimple/pimple": "^3.0", + "psr/log": "^1.1", + "songshenzong/support": "^2.0", + "xin/container": "^2.0.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Alipay\\EasySDK\\": "php/src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "junying.wjy", + "email": "junying.wjy@antfin.com" + } + ], + "description": "支付宝官方 Alipay Easy SDK", + "time": "2021-01-19T07:30:32+00:00" + }, { "name": "asm89/stack-cors", "version": "1.3.0", @@ -223,6 +456,68 @@ ], "time": "2021-01-20T22:51:39+00:00" }, + { + "name": "danielstjules/stringy", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/danielstjules/Stringy.git", + "reference": "df24ab62d2d8213bbbe88cc36fc35a4503b4bd7e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/danielstjules/Stringy/zipball/df24ab62d2d8213bbbe88cc36fc35a4503b4bd7e", + "reference": "df24ab62d2d8213bbbe88cc36fc35a4503b4bd7e", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.4.0", + "symfony/polyfill-mbstring": "~1.1" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Stringy\\": "src/" + }, + "files": [ + "src/Create.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel St. Jules", + "email": "danielst.jules@gmail.com", + "homepage": "http://www.danielstjules.com" + } + ], + "description": "A string manipulation library with multibyte support", + "homepage": "https://github.com/danielstjules/Stringy", + "keywords": [ + "UTF", + "helpers", + "manipulation", + "methods", + "multibyte", + "string", + "utf-8", + "utility", + "utils" + ], + "time": "2017-06-12T01:10:27+00:00" + }, { "name": "dnoegel/php-xdg-base-dir", "version": "v0.1.1", @@ -2205,6 +2500,69 @@ ], "time": "2020-12-14T13:15:25+00:00" }, + { + "name": "mtdowling/jmespath.php", + "version": "2.6.0", + "source": { + "type": "git", + "url": "https://github.com/jmespath/jmespath.php.git", + "reference": "42dae2cbd13154083ca6d70099692fef8ca84bfb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jmespath/jmespath.php/zipball/42dae2cbd13154083ca6d70099692fef8ca84bfb", + "reference": "42dae2cbd13154083ca6d70099692fef8ca84bfb", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^5.4 || ^7.0 || ^8.0", + "symfony/polyfill-mbstring": "^1.17" + }, + "require-dev": { + "composer/xdebug-handler": "^1.4", + "phpunit/phpunit": "^4.8.36 || ^7.5.15" + }, + "bin": [ + "bin/jp.php" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.6-dev" + } + }, + "autoload": { + "psr-4": { + "JmesPath\\": "src/" + }, + "files": [ + "src/JmesPath.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Declaratively specify how to extract elements from a JSON document", + "keywords": [ + "json", + "jsonpath" + ], + "time": "2020-07-31T21:01:56+00:00" + }, { "name": "myclabs/php-enum", "version": "1.8.0", @@ -2789,6 +3147,62 @@ ], "time": "2020-07-20T17:29:33+00:00" }, + { + "name": "pimple/pimple", + "version": "v3.3.1", + "source": { + "type": "git", + "url": "https://github.com/silexphp/Pimple.git", + "reference": "21e45061c3429b1e06233475cc0e1f6fc774d5b0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/silexphp/Pimple/zipball/21e45061c3429b1e06233475cc0e1f6fc774d5b0", + "reference": "21e45061c3429b1e06233475cc0e1f6fc774d5b0", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.2.5", + "psr/container": "^1.0" + }, + "require-dev": { + "symfony/phpunit-bridge": "^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3.x-dev" + } + }, + "autoload": { + "psr-0": { + "Pimple": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Pimple, a simple Dependency Injection Container", + "homepage": "https://pimple.symfony.com", + "keywords": [ + "container", + "dependency injection" + ], + "time": "2020-11-24T20:35:42+00:00" + }, { "name": "psr/container", "version": "1.0.0", @@ -3519,6 +3933,77 @@ ], "time": "2017-11-26T15:27:12+00:00" }, + { + "name": "songshenzong/support", + "version": "2.0.5", + "source": { + "type": "git", + "url": "https://github.com/songshenzong/support.git", + "reference": "34973c04ffcf226e503f1c3a69d30ac49f7621f6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/songshenzong/support/zipball/34973c04ffcf226e503f1c3a69d30ac49f7621f6", + "reference": "34973c04ffcf226e503f1c3a69d30ac49f7621f6", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "danielstjules/stringy": "^3.1", + "ext-json": "*", + "ext-simplexml": "*", + "ext-xml": "*", + "php": ">=5.5" + }, + "require-dev": { + "laravel/framework": "^5.8", + "phpunit/phpunit": "^4.8.35|^5.4.3" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Songshenzong\\Support\\StringsServiceProvider" + ], + "aliases": { + "Strings": "Songshenzong\\Support\\StringsFacade" + } + } + }, + "autoload": { + "psr-4": { + "Songshenzong\\Support\\": "src/" + }, + "files": [ + "src/StringsHelpers.php", + "src/BashEchoHelpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Songshenzong", + "email": "i@songshenzong.com" + } + ], + "description": "The Songshenzong Support package.", + "homepage": "http://songshenzong.com", + "keywords": [ + "laravel", + "support", + "tools", + "web" + ], + "time": "2019-08-29T01:59:12+00:00" + }, { "name": "spatie/laravel-permission", "version": "3.18.0", @@ -5914,6 +6399,80 @@ ], "time": "2020-11-12T00:07:28+00:00" }, + { + "name": "xin/container", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://gitee.com/liuxiaojinla/php-container", + "reference": "97bb67f87dd851545938a1f2fe0ffbd379e3ff81" + }, + "require": { + "ext-ctype": "*", + "ext-iconv": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-openssl": "*", + "ext-simplexml": "*", + "psr/container": "^1.0", + "xin/helper": "^1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "xin\\container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "晋", + "email": "657306123@qq.com" + } + ], + "description": "严格基于PSR11规范实现基础的容器和依赖注入", + "time": "2019-10-21T03:51:25+00:00" + }, + { + "name": "xin/helper", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://gitee.com/liuxiaojinla/php-helper", + "reference": "02a58132dae2aea2d1c0b8e66f55125969224747" + }, + "require": { + "ext-ctype": "*", + "ext-iconv": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-openssl": "*", + "ext-simplexml": "*" + }, + "type": "library", + "autoload": { + "psr-4": { + "xin\\helper\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "晋", + "email": "1540175452@qq.com" + } + ], + "description": "PHP项目日常开发必备基础库,数组工具类、字符串工具类、数字工具类、函数工具类、服务器工具类、加密工具类", + "time": "2019-06-22T08:28:23+00:00" + }, { "name": "zircote/swagger-php", "version": "3.1.0",