Skip to content

Commit

Permalink
!3 支付优化
Browse files Browse the repository at this point in the history
Merge pull request !3 from 白书科技/feat/v493
  • Loading branch information
Qsnh authored and gitee-org committed Sep 8, 2023
2 parents 24624a2 + 7f004bd commit ed02e10
Show file tree
Hide file tree
Showing 30 changed files with 260 additions and 139 deletions.
4 changes: 3 additions & 1 deletion .php_cs → .php-cs-fixer.php
Expand Up @@ -6,7 +6,9 @@
(c) 杭州白书科技有限公司
EOF;

return PhpCsFixer\Config::create()
$fixer = new PhpCsFixer\Config();

return $fixer
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
Expand Down
15 changes: 15 additions & 0 deletions app/Constant/ConfigConstant.php
@@ -0,0 +1,15 @@
<?php

/*
* This file is part of the Qsnh/meedu.
*
* (c) 杭州白书科技有限公司
*/

namespace App\Constant;

class ConfigConstant
{

public const PRIVATE_MASK = '************';
}
13 changes: 6 additions & 7 deletions app/Events/AppConfigSavedEvent.php
Expand Up @@ -15,13 +15,12 @@ class AppConfigSavedEvent
{
use Dispatchable, SerializesModels;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct()
public $newConfig;
public $oldConfig;

public function __construct(array $newConfig, array $oldConfig)
{
//
$this->newConfig = $newConfig;
$this->oldConfig = $oldConfig;
}
}
29 changes: 25 additions & 4 deletions app/Http/Controllers/Backend/Api/V1/SettingController.php
Expand Up @@ -10,15 +10,21 @@

use App\Meedu\Setting;
use Illuminate\Http\Request;
use App\Constant\ConfigConstant;
use App\Models\AdministratorLog;
use App\Events\AppConfigSavedEvent;
use App\Meedu\ServiceV2\Services\ConfigServiceInterface;

class SettingController extends BaseController
{
public function index(Setting $setting)
{
$config = $setting->getCanEditConfig();
foreach ($config as $key => $val) {
if ($val['is_show'] !== 1) {
// 界面隐藏的配置项
continue;
}
// 可选值
if ($val['option_value']) {
$config[$key]['option_value'] = json_decode($val['option_value'], true);
Expand All @@ -45,12 +51,27 @@ public function index(Setting $setting)
return $this->successData($data);
}

public function saveHandler(Request $request, Setting $setting)
public function saveHandler(Request $request, ConfigServiceInterface $configService, Setting $setting)
{
$data = $request->input('config');
$setting->append($data);
// 前端提交的配置数据,格式:{key: value,...}
$newConfigData = $request->input('config');
if (!$newConfigData) {
return $this->error(__('参数错误'));
}

foreach ($newConfigData as $key => $value) {
if ($value === ConfigConstant::PRIVATE_MASK) {
unset($newConfigData[$key]);
}
}

// 未修改之前的配置
$oldConfigData = $configService->allKeyValue();

// 将修改的配置同步到数据库
$setting->append($newConfigData);

event(new AppConfigSavedEvent());
event(new AppConfigSavedEvent($newConfigData, $oldConfigData));

AdministratorLog::storeLog(
AdministratorLog::MODULE_SYSTEM_CONFIG,
Expand Down
2 changes: 1 addition & 1 deletion app/Meedu/MeEdu.php
Expand Up @@ -10,5 +10,5 @@

class MeEdu
{
const VERSION = 'v4.9.2';
const VERSION = 'v4.9.3';
}
2 changes: 0 additions & 2 deletions app/Meedu/Payment/Alipay/Alipay.php
Expand Up @@ -63,8 +63,6 @@ public function create(array $order, array $extra = []): PaymentStatus

// 支付宝配置
$config = $this->configService->getAlipayPay();
// 回调地址
$config['notify_url'] = route('payment.callback', ['alipay']);
// 同步返回地址
$returnUrl = request()->input('redirect');
$returnUrl || $returnUrl = request()->input('s_url');
Expand Down
4 changes: 0 additions & 4 deletions app/Meedu/Payment/Alipay/AlipayRefund.php
Expand Up @@ -43,11 +43,7 @@ public function handle($refundNo, $outTradeNo, $amount, $reason)
'out_request_no' => $refundNo,
];

// 支付宝配置
$config = $this->configService->getAlipayPay();
// 回调地址
$config['notify_url'] = route('payment.callback', ['alipay']);

$result = Pay::alipay($config)->refund($params);
Log::info(__METHOD__ . '|支付宝退款返回参数', $result->toArray());
}
Expand Down
2 changes: 0 additions & 2 deletions app/Meedu/Payment/Wechat/WechatJSAPI.php
Expand Up @@ -102,15 +102,13 @@ public function createDirect(array $order, string $openid)

// 微信支付配置
$config = $this->configService->getWechatPay();
$config['notify_url'] = route('payment.callback', ['wechat']);

// 创建订单
$createResult = Pay::wechat($config)->{$order['payment_method']}($payOrderData);

return $createResult;
} catch (Exception $exception) {
exception_record($exception);

throw new ServiceException(__('system error'));
}
}
Expand Down
22 changes: 1 addition & 21 deletions app/Meedu/Payment/Wechat/WechatRefund.php
Expand Up @@ -10,7 +10,6 @@

use Yansongda\Pay\Pay;
use Illuminate\Support\Facades\Log;
use App\Exceptions\ServiceException;
use App\Services\Base\Services\ConfigService;
use App\Services\Base\Interfaces\ConfigServiceInterface;

Expand Down Expand Up @@ -48,27 +47,8 @@ public function handle($refundNo, $outTradeNo, $total, $amount, $reason = '', $e
protected function config()
{
$config = $this->configService->getWechatPay();
// 退款异步通知
// 修改异步通知为退款的异步通知
$config['notify_url'] = route('wechat.pay.refund.notify');

$cert = $config['cert_client'];
$key = $config['cert_key'];
if (!$cert || !$key) {
throw new ServiceException('微信API证书未配置');
}

$certPath = storage_path('private/wechat-pay-' . md5($cert) . '.pem');
if (!file_exists($certPath)) {
file_put_contents($certPath, $cert);
}
$keyPath = storage_path('private/wechat-pay-' . md5($key) . '.pem');
if (!file_exists($keyPath)) {
file_put_contents($keyPath, $key);
}

$config['cert_client'] = $certPath;
$config['cert_key'] = $keyPath;

return $config;
}

Expand Down
2 changes: 0 additions & 2 deletions app/Meedu/Payment/Wechat/WechatScan.php
Expand Up @@ -65,8 +65,6 @@ public function create(array $order, array $extra = []): PaymentStatus
$payOrderData = array_merge($payOrderData, $extra);

$config = $this->configService->getWechatPay();
// 回调地址
$config['notify_url'] = route('payment.callback', ['wechat']);

// 创建微信支付订单
// $createResult['code_url'] = 微信支付二维码的文本值[需要根据该文本值生成二维码]
Expand Down
8 changes: 8 additions & 0 deletions app/Meedu/ServiceV2/Dao/OtherDao.php
Expand Up @@ -9,6 +9,7 @@
namespace App\Meedu\ServiceV2\Dao;

use Carbon\Carbon;
use App\Meedu\ServiceV2\Models\AppConfig;
use App\Meedu\ServiceV2\Models\UserUploadImage;

class OtherDao implements OtherDaoInterface
Expand All @@ -28,4 +29,11 @@ public function storeUserUploadImage(int $userId, string $group, string $disk, s
'created_at' => Carbon::now()->toDateTimeLocalString(),
]);
}

public function appConfigValueKey(): array
{
return AppConfig::query()->get()->pluck('value', 'key')->toArray();
}


}
4 changes: 3 additions & 1 deletion app/Meedu/ServiceV2/Dao/OtherDaoInterface.php
Expand Up @@ -11,7 +11,7 @@
interface OtherDaoInterface
{
public function storeUserUploadImage(
int $userId,
int $userId,
string $group,
string $disk,
string $path,
Expand All @@ -21,4 +21,6 @@ public function storeUserUploadImage(
string $logIp,
string $logUA
): void;

public function appConfigValueKey(): array;
}
23 changes: 23 additions & 0 deletions app/Meedu/ServiceV2/Models/AppConfig.php
@@ -0,0 +1,23 @@
<?php

/*
* This file is part of the Qsnh/meedu.
*
* (c) 杭州白书科技有限公司
*/

namespace App\Meedu\ServiceV2\Models;

use Illuminate\Database\Eloquent\Model;

class AppConfig extends Model
{

protected $table = 'app_config';

protected $fillable = [
'group', 'name', 'field_type', 'sort', 'default_value', 'key', 'value', 'is_private',
'option_value', 'help', 'is_show',
];

}
2 changes: 1 addition & 1 deletion app/Meedu/ServiceV2/ServiceInit.php
Expand Up @@ -26,9 +26,9 @@
class ServiceInit
{
public $dao = [
OtherDaoInterface::class => OtherDao::class,
UserDaoInterface::class => UserDao::class,
CourseDaoInterface::class => CourseDao::class,
OtherDaoInterface::class => OtherDao::class,
];

public $service = [
Expand Down
15 changes: 15 additions & 0 deletions app/Meedu/ServiceV2/Services/ConfigService.php
Expand Up @@ -8,8 +8,23 @@

namespace App\Meedu\ServiceV2\Services;

use App\Meedu\ServiceV2\Dao\OtherDaoInterface;

class ConfigService implements ConfigServiceInterface
{

private $dao;

public function __construct(OtherDaoInterface $dao)
{
$this->dao = $dao;
}

public function allKeyValue(): array
{
return $this->dao->appConfigValueKey();
}

public function getSuperAdministratorSlug(): string
{
return config('meedu.administrator.super_slug') ?? '';
Expand Down
2 changes: 2 additions & 0 deletions app/Meedu/ServiceV2/Services/ConfigServiceInterface.php
Expand Up @@ -33,4 +33,6 @@ public function getPCUrl(): string;
public function getH5Url(): string;

public function getLogo(): string;

public function allKeyValue(): array;
}
2 changes: 2 additions & 0 deletions app/Meedu/Upgrade.php
Expand Up @@ -10,6 +10,7 @@

use App\Meedu\UpgradeLog\UpgradeTo48;
use App\Meedu\UpgradeLog\UpgradeToV4;
use App\Meedu\UpgradeLog\UpgradeV493;
use App\Meedu\UpgradeLog\UpgradeToV42;
use App\Meedu\UpgradeLog\UpgradeToV45;
use App\Meedu\UpgradeLog\UpgradeToV46;
Expand All @@ -25,5 +26,6 @@ public function run()
UpgradeToV454::handle();
UpgradeToV46::handle();
UpgradeTo48::handle();
UpgradeV493::handle();
}
}
35 changes: 35 additions & 0 deletions app/Meedu/UpgradeLog/UpgradeV493.php
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Qsnh/meedu.
*
* (c) 杭州白书科技有限公司
*/

namespace App\Meedu\UpgradeLog;

use App\Meedu\ServiceV2\Models\AppConfig;

class UpgradeV493
{

public static function handle()
{
self::renameAppConfig();
}

private static function renameAppConfig()
{
AppConfig::query()->where('key', 'pay.alipay.ali_public_key')->update([
'name' => '支付宝公钥',
'sort' => 30,
'help' => '',
]);
AppConfig::query()->where('key', 'pay.alipay.private_key')->update([
'name' => '应用私钥',
'sort' => 35,
'help' => '',
]);
}

}

0 comments on commit ed02e10

Please sign in to comment.