2023-11-15 12:02:33 +08:00
|
|
|
|
<?php
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
|
|
|
|
// | 开源版本可自由商用,可去除界面版权logo
|
|
|
|
|
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
|
|
|
|
// | github下载:https://github.com/likeshop-github/likeadmin
|
|
|
|
|
// | 访问官网:https://www.likeadmin.cn
|
|
|
|
|
// | likeadmin团队 版权所有 拥有最终解释权
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | author: likeadminTeam
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
namespace app\common\service\wechat;
|
|
|
|
|
|
|
|
|
|
use app\common\enum\PayEnum;
|
|
|
|
|
use app\common\enum\user\UserTerminalEnum;
|
|
|
|
|
use app\common\model\pay\PayConfig;
|
|
|
|
|
use app\common\service\ConfigService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 微信配置类
|
|
|
|
|
* Class WeChatConfigService
|
|
|
|
|
* @package app\common\service
|
|
|
|
|
*/
|
|
|
|
|
class WeChatPayMerchantConfigService
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @notes 获取支付配置
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function getPayConfig()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$notifyUrl = (string)url('wechat_pay_service_merchant_pay/notifyApp', [], false, true);
|
|
|
|
|
$pay = PayConfig::where(['pay_way' => PayEnum::WECHAT_PAY])->findOrEmpty()->toArray();
|
|
|
|
|
//判断是否已经存在证书文件夹,不存在则新建
|
|
|
|
|
if (!file_exists(app()->getRootPath() . 'runtime/cert')) {
|
|
|
|
|
mkdir(app()->getRootPath() . 'runtime/cert', 0775, true);
|
|
|
|
|
}
|
|
|
|
|
//写入文件
|
|
|
|
|
$apiclientCert = $pay['config']['apiclient_cert'] ?? '';
|
|
|
|
|
$apiclientKey = $pay['config']['apiclient_key'] ?? '';
|
2023-11-16 17:33:16 +08:00
|
|
|
|
$plaformCert = $pay['config']['platform_certs'] ?? '';
|
2023-11-15 12:02:33 +08:00
|
|
|
|
|
|
|
|
|
$certPath = app()->getRootPath() . 'runtime/cert/' . md5($apiclientCert) . '.pem';
|
|
|
|
|
$keyPath = app()->getRootPath() . 'runtime/cert/' . md5($apiclientKey) . '.pem';
|
2023-11-16 17:33:16 +08:00
|
|
|
|
$plaformCertPath = app()->getRootPath() . 'runtime/cert/' . md5($plaformCert) . '.pem';
|
2023-11-15 12:02:33 +08:00
|
|
|
|
|
|
|
|
|
if (!empty($apiclientCert) && !file_exists($certPath)) {
|
|
|
|
|
static::setCert($certPath, trim($apiclientCert));
|
|
|
|
|
}
|
|
|
|
|
if (!empty($apiclientKey) && !file_exists($keyPath)) {
|
|
|
|
|
static::setCert($keyPath, trim($apiclientKey));
|
|
|
|
|
}
|
2023-11-16 17:33:16 +08:00
|
|
|
|
if (!empty($plaformCert) && !file_exists($plaformCertPath)) {
|
|
|
|
|
static::setCert($plaformCertPath, trim($plaformCert));
|
|
|
|
|
}
|
2023-11-15 12:02:33 +08:00
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
// 服务商商户号
|
|
|
|
|
'mch_id' => $pay['config']['mch_id'] ?? '',
|
|
|
|
|
// 商户证书
|
|
|
|
|
'private_key' => $keyPath,
|
|
|
|
|
'certificate' => $certPath,
|
2023-11-16 17:33:16 +08:00
|
|
|
|
// 平台证书
|
|
|
|
|
'platform_certs' => $plaformCertPath,
|
|
|
|
|
// v3 API 秘钥
|
|
|
|
|
'secret_key' => '1A1233CFB69D7F27211E36AFF9EC373A',
|
2023-11-15 12:02:33 +08:00
|
|
|
|
// v2 API 秘钥
|
2023-11-16 17:33:16 +08:00
|
|
|
|
// 'v2_secret_key' => $pay['config']['pay_sign_key'] ?? '',
|
2023-11-15 12:02:33 +08:00
|
|
|
|
'notify_url' => $notifyUrl,
|
|
|
|
|
'http' => [
|
|
|
|
|
'throw' => true, // 状态码非 200、300 时是否抛出异常,默认为开启
|
|
|
|
|
'timeout' => 5.0,
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 临时写入证书
|
|
|
|
|
* @param $path
|
|
|
|
|
* @param $cert
|
|
|
|
|
* @author 段誉
|
|
|
|
|
* @date 2023/2/27 15:48
|
|
|
|
|
*/
|
|
|
|
|
public static function setCert($path, $cert)
|
|
|
|
|
{
|
|
|
|
|
$fopenPath = fopen($path, 'w');
|
|
|
|
|
fwrite($fopenPath, $cert);
|
|
|
|
|
fclose($fopenPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|