mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2026-06-07 12:38:11 +08:00
fix: 修改微信V3支付配置及调用DEMO
This commit is contained in:
parent
320a2220f7
commit
d338a8fc8c
@ -188,8 +188,7 @@ class Config extends Controller
|
||||
if (empty($wechat['mch_ssl_p12']) || !$local->has($wechat['mch_ssl_p12'], true)) {
|
||||
$this->error('商户证书 P12 不能为空!');
|
||||
}
|
||||
$content = $local->get($wechat['mch_ssl_p12'], true);
|
||||
if (openssl_pkcs12_read($content, $certs, $wechat['mch_id'])) {
|
||||
if (openssl_pkcs12_read($local->get($wechat['mch_ssl_p12'], true), $certs, $wechat['mch_id'])) {
|
||||
$name1 = "wxpay/{$wechat['mch_id']}_cer.pem";
|
||||
$name2 = "wxpay/{$wechat['mch_id']}_key.pem";
|
||||
$wechat['mch_ssl_cer'] = $local->set($name1, $certs['cert'], true)['url'];
|
||||
@ -206,7 +205,7 @@ class Config extends Controller
|
||||
'mch_key' => $wechat['mch_key'],
|
||||
'mch_v3_key' => $wechat['mch_v3_key'],
|
||||
'ssl_pay_id' => $wechat['mch_v3_payid'] ?? '',
|
||||
'ssl_pay_text' => $local->get($wechat['ssl_cer_pay'], true),
|
||||
'ssl_pay_text' => $local->get($wechat['mch_ssl_pay'], true),
|
||||
'ssl_key_text' => $local->get($wechat['mch_ssl_key'], true),
|
||||
'ssl_cer_text' => $local->get($wechat['mch_ssl_cer'], true),
|
||||
]);
|
||||
|
||||
@ -226,24 +226,23 @@ class WechatService extends Service
|
||||
public static function withWxpayCert(array $options): array
|
||||
{
|
||||
// 文本模式主要是为了解决分布式部署
|
||||
$local = LocalStorage::instance();
|
||||
$name1 = "wxpay/{$options['mch_id']}_cer.pem";
|
||||
$name2 = "wxpay/{$options['mch_id']}_key.pem";
|
||||
$local = LocalStorage::instance();
|
||||
if ($local->has($name1, true) && $local->has($name2, true)) {
|
||||
$sslCer = $local->path($name1, true);
|
||||
$sslKey = $local->path($name2, true);
|
||||
}
|
||||
$data = sysdata('plugin.wechat.payment');
|
||||
if (empty($sslCer) || empty($sslKey)) {
|
||||
if (!empty($data = sysdata('plugin.wechat.payment'))) {
|
||||
if (!empty($data['ssl_key_text']) && !empty($data['ssl_cer_text'])) {
|
||||
$sslCer = $local->set($name1, $data['ssl_cer_text'], true)['file'];
|
||||
$sslKey = $local->set($name2, $data['ssl_key_text'], true)['file'];
|
||||
}
|
||||
} else {
|
||||
if (empty($data)) {
|
||||
$sslCer = $local->path(sysconf('wechat.mch_ssl_cer'), true);
|
||||
$sslKey = $local->path(sysconf('wechat.mch_ssl_key'), true);
|
||||
if (!$local->has($sslCer, true)) unset($sslCer);
|
||||
if (!$local->has($sslKey, true)) unset($sslKey);
|
||||
} elseif (!empty($data['ssl_key_text']) && !empty($data['ssl_cer_text'])) {
|
||||
$sslCer = $local->set($name1, $data['ssl_cer_text'], true)['file'];
|
||||
$sslKey = $local->set($name2, $data['ssl_key_text'], true)['file'];
|
||||
}
|
||||
}
|
||||
if (isset($sslCer) && isset($sslKey)) {
|
||||
@ -251,6 +250,8 @@ class WechatService extends Service
|
||||
$options['ssl_key'] = $sslKey;
|
||||
$options['cert_public'] = $sslCer;
|
||||
$options['cert_private'] = $sslKey;
|
||||
$options['mp_cert_serial'] = $data['ssl_pay_id'] ?? '';
|
||||
$options['mp_cert_content'] = $data['ssl_pay_text'] ?? '';
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
@ -18,27 +18,41 @@
|
||||
<label class="layui-form-item relative block">
|
||||
<span class="help-label"><b>微信商户账号</b>MCH_ID</span>
|
||||
<input name="wechat.mch_id" required vali-name="微信商户号" placeholder="请输入微信商户账号(必填)" value="{:sysconf('wechat.mch_id')}" class="layui-input">
|
||||
<span class="help-block">微信商户账号,需要在微信商户平台获取,MCH_ID 与 APPID 匹配</span>
|
||||
<span class="help-block">微信商户账号,需要在微信商户平台获取</span>
|
||||
</label>
|
||||
|
||||
<label class="layui-form-item relative layui-hide">
|
||||
<span class="help-label"><b>微信商户 V2 密钥</b>MCH_KEY</span>
|
||||
<input name="wechat.mch_key" vali-name="微信商户V2密钥" placeholder="请输入微信商户V2密钥(必填)" maxlength="32" pattern=".{32}" required value="{:sysconf('wechat.mch_key')}" class="layui-input">
|
||||
<span class="help-block">微信商户 V2 密钥,需要在微信商户平台操作设置操作密码并获取商户接口密钥</span>
|
||||
<span class="help-label"><b>微信 V2 接口密钥</b>MCH_KEY</span>
|
||||
<input name="wechat.mch_key" vali-name="微信商户V2密钥" type="password" lay-affix="eye" placeholder="请输入微信商户V2密钥(必填)" maxlength="32" pattern=".{32}" required value="{:sysconf('wechat.mch_key')}" class="layui-input">
|
||||
<span class="help-block">微信商户 V2 密钥,需要在微信商户平台获取商户接口密钥</span>
|
||||
</label>
|
||||
|
||||
<label class="layui-form-item relative block">
|
||||
<span class="help-label"><b>微信商户 V3 密钥</b>MCH_V3_KEY</span>
|
||||
<input name="wechat.mch_v3_key" vali-name="微信商户V3密钥" placeholder="请输入微信商户V3密钥(必填)" maxlength="32" pattern=".{32}" required value="{:sysconf('wechat.mch_v3_key')}" class="layui-input">
|
||||
<span class="help-block">微信商户 V3 密钥,需要在微信商户平台操作设置操作密码并获取商户接口密钥</span>
|
||||
<span class="help-label"><b>微信 V3 接口密钥</b>MCH_V3_KEY</span>
|
||||
<input name="wechat.mch_v3_key" vali-name="微信商户V3密钥" type="password" lay-affix="eye" placeholder="请输入微信商户V3密钥(必填)" maxlength="32" pattern=".{32}" required value="{:sysconf('wechat.mch_v3_key')}" class="layui-input">
|
||||
<span class="help-block">微信商户 V3 密钥,需要在微信商户平台获取商户接口密钥</span>
|
||||
</label>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
|
||||
<label class="layui-form-item relative block">
|
||||
<span class="help-label"><b>微信商户 V3 支付公钥ID</b>MCH_V3_PAYCERT_ID</span>
|
||||
<input name="wechat.mch_v3_payid" vali-name="微信商户V3支付公钥ID" placeholder="请输入微信商户V3支付公钥ID(必填)" maxlength="100" required value="{:sysconf('wechat.mch_v3_payid')}" class="layui-input">
|
||||
<span class="help-label"><b>微信 V3 支付公钥ID</b>MCH_V3_PAYID</span>
|
||||
<input name="wechat.mch_v3_payid" vali-name="微信商户V3支付公钥ID" placeholder="请输入微信商户V3支付公钥ID(必填)" maxlength="45" pattern="PUB_KEY_ID_.{34}" required value="{:sysconf('wechat.mch_v3_payid')}" class="layui-input">
|
||||
<span class="help-block">微信商户 V3 支付证书ID,需要在微信商户平台操作设置操作密码并获取商户接口密钥</span>
|
||||
</label>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<span class="help-label label-required-prev"><b>微信 V3 支付证书公钥</b>MCH_V3_PAYCERT</span>
|
||||
<div class="margin-top-10">
|
||||
<div data-mch-type="pem" class="layui-tab-item">
|
||||
<input type="hidden" name="wechat.mch_ssl_pay" value="{$mch_ssl_pay|default=''}">
|
||||
<button data-file="btn" data-uptype="local" data-safe="true" data-type="pem" data-field="wechat.mch_ssl_pay" type="button" class="layui-btn font-code layui-btn-primary margin-right-10">
|
||||
<i class="layui-icon layui-icon-vercode"></i> 上传微信支付公钥
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
@ -57,11 +71,6 @@
|
||||
<button data-file="btn" data-uptype="local" data-safe="true" data-type="p12" data-field="wechat.mch_ssl_p12" type="button" class="layui-btn font-code layui-btn-primary margin-right-10">
|
||||
<i class="layui-icon layui-icon-vercode"></i> 上传商户P12证书
|
||||
</button>
|
||||
|
||||
<input type="hidden" name="wechat.mch_ssl_pay" value="{$mch_ssl_pay|default=''}">
|
||||
<button data-file="btn" data-uptype="local" data-safe="true" data-type="pem" data-field="wechat.mch_ssl_pay" type="button" class="layui-btn font-code layui-btn-primary margin-right-10">
|
||||
<i class="layui-icon layui-icon-vercode"></i> 上传微信支付公钥
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div data-mch-type="pem" class="layui-tab-item">
|
||||
@ -74,11 +83,6 @@
|
||||
<button data-file="btn" data-uptype="local" data-safe="true" data-type="pem" data-field="wechat.mch_ssl_cer" type="button" class="layui-btn font-code layui-btn-primary margin-right-10">
|
||||
<i class="layui-icon layui-icon-vercode"></i> 上传商户证书公钥
|
||||
</button>
|
||||
|
||||
<input type="hidden" name="wechat.mch_ssl_pay" value="{$mch_ssl_pay|default=''}">
|
||||
<button data-file="btn" data-uptype="local" data-safe="true" data-type="pem" data-field="wechat.mch_ssl_pay" type="button" class="layui-btn font-code layui-btn-primary margin-right-10">
|
||||
<i class="layui-icon layui-icon-vercode"></i> 上传微信支付公钥
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -99,7 +103,7 @@
|
||||
(function (type) {
|
||||
layui.form.val('payment', {'wechat.mch_ssl_type': type});
|
||||
layui.form.on('radio(data-mch-type)', apply) && apply({value: type});
|
||||
['wechat.mch_ssl_p12', 'wechat.mch_ssl_key', 'wechat.mch_ssl_cer'].forEach(function (type) {
|
||||
['wechat.mch_ssl_p12', 'wechat.mch_ssl_key', 'wechat.mch_ssl_cer', 'wechat.mch_ssl_pay'].forEach(function (type) {
|
||||
$('input[name="' + type + '"]').on('change', function () {
|
||||
let that = this, $button = $(this).next('button');
|
||||
if (typeof that.value === 'string' && that.value.length > 5) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user