70 行
2.1 KiB
PHP
70 行
2.1 KiB
PHP
<?php
|
|
|
|
namespace addons\shopro\library\split;
|
|
|
|
use addons\shopro\model\Config as ShoproConfig;
|
|
use Yansongda\Pay\Pay;
|
|
use Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing\AddReceiverPlugin;
|
|
use Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing\CreatePlugin;
|
|
use Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing\QueryPlugin;
|
|
use Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing\ReturnPlugin;
|
|
|
|
class ProfitSharingService
|
|
{
|
|
protected $config = [];
|
|
|
|
public function __construct()
|
|
{
|
|
$this->config = $this->buildWechatConfig();
|
|
}
|
|
|
|
public function createOrder(array $params)
|
|
{
|
|
return $this->callPlugin(CreatePlugin::class, $params);
|
|
}
|
|
|
|
public function addReceiver(array $params)
|
|
{
|
|
return $this->callPlugin(AddReceiverPlugin::class, $params);
|
|
}
|
|
|
|
public function queryOrder(array $params)
|
|
{
|
|
return $this->callPlugin(QueryPlugin::class, $params);
|
|
}
|
|
|
|
public function returnOrder(array $params)
|
|
{
|
|
return $this->callPlugin(ReturnPlugin::class, $params);
|
|
}
|
|
|
|
protected function callPlugin($plugin, array $params)
|
|
{
|
|
$wechat = Pay::wechat($this->config);
|
|
$plugins = $wechat->mergeCommonPlugins([$plugin]);
|
|
return $wechat->pay($plugins, $params);
|
|
}
|
|
|
|
protected function buildWechatConfig()
|
|
{
|
|
$paymentConfig = json_decode(ShoproConfig::get(['name' => 'wechat'])->value, true);
|
|
$platformConfig = json_decode(ShoproConfig::get(['name' => 'wxMiniProgram'])->value, true);
|
|
|
|
if (isset($paymentConfig['mode']) && $paymentConfig['mode'] === 'service') {
|
|
$paymentConfig['sub_miniapp_id'] = $platformConfig['app_id'] ?? '';
|
|
} else {
|
|
$paymentConfig['miniapp_id'] = $platformConfig['app_id'] ?? '';
|
|
$paymentConfig['app_id'] = $platformConfig['app_id'] ?? '';
|
|
}
|
|
|
|
if (!empty($paymentConfig['cert_client'])) {
|
|
$paymentConfig['cert_client'] = ROOT_PATH . 'public' . $paymentConfig['cert_client'];
|
|
}
|
|
if (!empty($paymentConfig['cert_key'])) {
|
|
$paymentConfig['cert_key'] = ROOT_PATH . 'public' . $paymentConfig['cert_key'];
|
|
}
|
|
|
|
return $paymentConfig;
|
|
}
|
|
}
|