支付宝-app支付
parent
03a604c2ff
commit
bb752083f3
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use Alipay\EasySDK\Kernel\Config as AlipayConfig;
|
||||
use Alipay\EasySDK\Kernel\EasySDKKernel as AlipayKernel;
|
||||
use App\Services\SettingService;
|
||||
use EasyWeChat\Factory as EasyWeChatFactory;
|
||||
use EasyWeChat\Payment\Application as EasyWeChatPaymentApplication;
|
||||
|
|
@ -26,7 +24,6 @@ class AppServiceProvider extends ServiceProvider
|
|||
$this->registerEasyWeChat();
|
||||
$this->registerRequestRealIp();
|
||||
$this->registerSettings();
|
||||
$this->registerAlipay();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -98,29 +95,4 @@ class AppServiceProvider extends ServiceProvider
|
|||
return new SettingService($app['cache.store']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册应用支付宝服务
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerAlipay()
|
||||
{
|
||||
$this->app->singleton(AlipayKernel::class, function ($app) {
|
||||
$alipayConfigs = $app['config']->get('alipay');
|
||||
|
||||
$config = new AlipayConfig();
|
||||
$config->protocol = 'https';
|
||||
$config->gatewayHost = 'openapi.alipay.com';
|
||||
$config->signType = 'RSA2';
|
||||
$config->appId = $alipayConfigs['app_id'];
|
||||
$config->merchantPrivateKey = $alipayConfigs['app_private_key'];
|
||||
$config->merchantCertPath = $alipayConfigs['app_public_cert_path'];
|
||||
$config->alipayCertPath = $alipayConfigs['public_cert_path'];
|
||||
$config->alipayRootCertPath = $alipayConfigs['root_cert_path'];
|
||||
$config->notifyUrl = $alipayConfigs['notify_url'] ?? url(route('alipay.paid_notify', [], false), [], true);
|
||||
|
||||
return new AlipayKernel($config);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,14 +2,17 @@
|
|||
|
||||
namespace App\Services;
|
||||
|
||||
use AlibabaCloud\Client\Config\Config;
|
||||
use Alipay\EasySDK\Kernel\CertEnvironment;
|
||||
use Alipay\EasySDK\Kernel\EasySDKKernel;
|
||||
use Alipay\EasySDK\Payment\App\Client as AppClient;
|
||||
|
||||
class AlipayService
|
||||
{
|
||||
public function __construct(
|
||||
protected EasySDKKernel $kernel,
|
||||
) {
|
||||
protected $kernel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -20,7 +23,7 @@ class AlipayService
|
|||
*/
|
||||
public function pay(array $params)
|
||||
{
|
||||
$result = (new AppClient($this->kernel))->pay(
|
||||
$result = $this->app()->pay(
|
||||
$params['subject'],
|
||||
$params['out_trade_no'],
|
||||
$params['total_amount'],
|
||||
|
|
@ -30,4 +33,49 @@ class AlipayService
|
|||
'body' => $result->body,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* App 支付客户端
|
||||
*
|
||||
* @return AppClient
|
||||
*/
|
||||
protected function app(): AppClient
|
||||
{
|
||||
$kernel = new EasySDKKernel($this->getConfig());
|
||||
|
||||
return new AppClient($kernel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支付宝配置信息
|
||||
*
|
||||
* @return \AlibabaCloud\Client\Config\Config
|
||||
*/
|
||||
protected function getConfig(): Config
|
||||
{
|
||||
$configs = config('alipay');
|
||||
|
||||
$cfg = new Config();
|
||||
$cfg->protocol = 'https';
|
||||
$cfg->gatewayHost = 'openapi.alipay.com';
|
||||
$cfg->signType = 'RSA2';
|
||||
$cfg->appId = $configs['app_id'];
|
||||
$cfg->merchantPrivateKey = $configs['app_private_key'];
|
||||
$cfg->merchantCertPath = $configs['app_public_cert_path'];
|
||||
$cfg->alipayCertPath = $configs['public_cert_path'];
|
||||
$cfg->alipayRootCertPath = $configs['root_cert_path'];
|
||||
$cfg->notifyUrl = $configs['notify_url'] ?? url(route('alipay.paid_notify', [], false), [], true);
|
||||
|
||||
$certEnvironment = new CertEnvironment();
|
||||
$certEnvironment->certEnvironment(
|
||||
$cfg->merchantCertPath,
|
||||
$cfg->alipayCertPath,
|
||||
$cfg->alipayRootCertPath
|
||||
);
|
||||
$cfg->merchantCertSN = $certEnvironment->getMerchantCertSN();
|
||||
$cfg->alipayRootCertSN = $certEnvironment->getRootCertSN();
|
||||
$cfg->alipayPublicKey = $certEnvironment->getCachedAlipayPublicKey();
|
||||
|
||||
return $cfg;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue