chore(addon/huaweipay): 支持证书文本填写模式
This commit is contained in:
@@ -32,6 +32,45 @@ class HuaweiPayClient
|
|||||||
// 是否加载了华为平台支付服务加密证书
|
// 是否加载了华为平台支付服务加密证书
|
||||||
private $has_huawei_public_key_certificate_instance_encrypt = false;
|
private $has_huawei_public_key_certificate_instance_encrypt = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化证书内容,添加适当的格式头尾
|
||||||
|
* @param string $content 证书内容
|
||||||
|
* @param string $type 证书类型:private_key, public_key
|
||||||
|
* @return string 格式化后的证书内容
|
||||||
|
*/
|
||||||
|
private function formatCertificateContent($content, $type)
|
||||||
|
{
|
||||||
|
// 移除空白字符和换行
|
||||||
|
$content = preg_replace('/\s+/', '', $content);
|
||||||
|
|
||||||
|
// 检查是否已经包含格式头尾
|
||||||
|
if (preg_match('/-----BEGIN.*-----/', $content) && preg_match('/-----END.*-----/', $content)) {
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加适当的格式头尾
|
||||||
|
$header = '';
|
||||||
|
$footer = '';
|
||||||
|
|
||||||
|
if ($type == 'private_key') {
|
||||||
|
$header = "-----BEGIN PRIVATE KEY-----\n";
|
||||||
|
$footer = "\n-----END PRIVATE KEY-----";
|
||||||
|
} elseif ($type == 'public_key') {
|
||||||
|
$header = "-----BEGIN PUBLIC KEY-----\n";
|
||||||
|
$footer = "\n-----END PUBLIC KEY-----";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 每64个字符添加一个换行
|
||||||
|
$formattedContent = $header;
|
||||||
|
$length = strlen($content);
|
||||||
|
for ($i = 0; $i < $length; $i += 64) {
|
||||||
|
$formattedContent .= substr($content, $i, 64) . "\n";
|
||||||
|
}
|
||||||
|
$formattedContent .= $footer;
|
||||||
|
|
||||||
|
return $formattedContent;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造函数
|
* 构造函数
|
||||||
* @param array $config 华为支付配置
|
* @param array $config 华为支付配置
|
||||||
@@ -53,37 +92,58 @@ class HuaweiPayClient
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// 加载商户应用私有证书
|
// 加载商户应用私有证书
|
||||||
if (!empty($this->config['private_key'])) {
|
$private_key_content = '';
|
||||||
|
if (!empty($this->config['private_key_text'])) {
|
||||||
|
// 文本模式,需要格式化
|
||||||
|
$private_key_content = $this->formatCertificateContent($this->config['private_key_text'], 'private_key');
|
||||||
|
} elseif (!empty($this->config['private_key'])) {
|
||||||
|
// 文件模式
|
||||||
$private_key_path = realpath($cert_base_path . $this->config['private_key']);
|
$private_key_path = realpath($cert_base_path . $this->config['private_key']);
|
||||||
if (!$private_key_path) {
|
if (!$private_key_path) {
|
||||||
throw new \Exception('商户应用私有证书文件不存在: ' . $this->config['private_key']);
|
throw new \Exception('商户应用私有证书文件不存在: ' . $this->config['private_key']);
|
||||||
}
|
}
|
||||||
$private_key_content = file_get_contents($private_key_path);
|
$private_key_content = file_get_contents($private_key_path);
|
||||||
$this->private_key_certificate_instance = openssl_pkey_get_private($private_key_content);
|
|
||||||
if (!$this->private_key_certificate_instance) {
|
|
||||||
throw new \Exception('加载商户应用私有证书失败,请检查证书格式是否正确');
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw new \Exception('缺少必要配置:private_key');
|
throw new \Exception('缺少必要配置:private_key或private_key_text');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->private_key_certificate_instance = openssl_pkey_get_private($private_key_content);
|
||||||
|
if (!$this->private_key_certificate_instance) {
|
||||||
|
throw new \Exception('加载商户应用私有证书失败,请检查证书格式是否正确');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载华为平台支付证书
|
// 加载华为平台支付证书
|
||||||
if (!empty($this->config['huawei_public_key'])) {
|
$huawei_public_key_content = '';
|
||||||
|
if (!empty($this->config['huawei_public_key_text'])) {
|
||||||
|
// 文本模式,需要格式化
|
||||||
|
$huawei_public_key_content = $this->formatCertificateContent($this->config['huawei_public_key_text'], 'public_key');
|
||||||
|
} elseif (!empty($this->config['huawei_public_key'])) {
|
||||||
|
// 文件模式
|
||||||
$huawei_public_key_path = realpath($cert_base_path . $this->config['huawei_public_key']);
|
$huawei_public_key_path = realpath($cert_base_path . $this->config['huawei_public_key']);
|
||||||
if (!$huawei_public_key_path) {
|
if (!$huawei_public_key_path) {
|
||||||
throw new \Exception('华为平台支付证书文件不存在: ' . $this->config['huawei_public_key']);
|
throw new \Exception('华为平台支付证书文件不存在: ' . $this->config['huawei_public_key']);
|
||||||
}
|
}
|
||||||
$huawei_public_key_content = file_get_contents($huawei_public_key_path);
|
$huawei_public_key_content = file_get_contents($huawei_public_key_path);
|
||||||
$this->huawei_public_key_certificate_instance = openssl_pkey_get_public($huawei_public_key_content);
|
|
||||||
if (!$this->huawei_public_key_certificate_instance) {
|
|
||||||
throw new \Exception('加载华为平台支付证书失败,请检查证书格式是否正确');
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw new \Exception('缺少必要配置:huawei_public_key');
|
throw new \Exception('缺少必要配置:huawei_public_key或huawei_public_key_text');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->huawei_public_key_certificate_instance = openssl_pkey_get_public($huawei_public_key_content);
|
||||||
|
if (!$this->huawei_public_key_certificate_instance) {
|
||||||
|
throw new \Exception('加载华为平台支付证书失败,请检查证书格式是否正确');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载华为平台支付服务加密证书(可选)
|
// 加载华为平台支付服务加密证书(可选)
|
||||||
if (!empty($this->config['huawei_public_key_for_sessionkey'])) {
|
if (!empty($this->config['huawei_public_key_for_sessionkey_text'])) {
|
||||||
|
// 文本模式,需要格式化
|
||||||
|
$huawei_public_key_encrypt_content = $this->formatCertificateContent($this->config['huawei_public_key_for_sessionkey_text'], 'public_key');
|
||||||
|
$this->huawei_public_key_certificate_instance_encrypt = openssl_pkey_get_public($huawei_public_key_encrypt_content);
|
||||||
|
if (!$this->huawei_public_key_certificate_instance_encrypt) {
|
||||||
|
throw new \Exception('加载华为平台支付服务加密证书失败');
|
||||||
|
}
|
||||||
|
$this->has_huawei_public_key_certificate_instance_encrypt = true;
|
||||||
|
} elseif (!empty($this->config['huawei_public_key_for_sessionkey'])) {
|
||||||
|
// 文件模式
|
||||||
$huawei_public_key_encrypt_path = realpath($cert_base_path . $this->config['huawei_public_key_for_sessionkey']);
|
$huawei_public_key_encrypt_path = realpath($cert_base_path . $this->config['huawei_public_key_for_sessionkey']);
|
||||||
if (!$huawei_public_key_encrypt_path) {
|
if (!$huawei_public_key_encrypt_path) {
|
||||||
throw new \Exception('华为平台支付服务加密证书文件不存在: ' . $this->config['huawei_public_key_for_sessionkey']);
|
throw new \Exception('华为平台支付服务加密证书文件不存在: ' . $this->config['huawei_public_key_for_sessionkey']);
|
||||||
|
|||||||
@@ -28,8 +28,11 @@ class Config extends BaseModel
|
|||||||
// 'app_id',
|
// 'app_id',
|
||||||
// 'mch_auth_id',
|
// 'mch_auth_id',
|
||||||
'private_key',
|
'private_key',
|
||||||
|
'private_key_text',
|
||||||
'huawei_public_key',
|
'huawei_public_key',
|
||||||
'huawei_public_key_for_sessionkey'
|
'huawei_public_key_text',
|
||||||
|
'huawei_public_key_for_sessionkey',
|
||||||
|
'huawei_public_key_for_sessionkey_text'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,10 +21,14 @@ class Pay extends BaseShop
|
|||||||
$app_id = input("app_id", "");//华为应用ID, // PETALPAY.APPID, 商户号关联的APPID
|
$app_id = input("app_id", "");//华为应用ID, // PETALPAY.APPID, 商户号关联的APPID
|
||||||
$mch_id = input("mch_id", "");//商户号, // PETALPAY.MERC_NO, 商户号
|
$mch_id = input("mch_id", "");//商户号, // PETALPAY.MERC_NO, 商户号
|
||||||
$private_key = input("private_key", "");//商户应用私钥, // PETALPAY.MERC_PRIVATE_KEY, 商户应用私钥
|
$private_key = input("private_key", "");//商户应用私钥, // PETALPAY.MERC_PRIVATE_KEY, 商户应用私钥
|
||||||
|
$private_key_text = input("private_key_text", "");//商户应用私钥文本, // PETALPAY.MERC_PRIVATE_KEY_TEXT, 商户应用私钥文本
|
||||||
$mch_auth_id = input("mch_auth_id", "");//商户证书id, // PETALPAY.MERC_AUTH_ID, 商户证书id
|
$mch_auth_id = input("mch_auth_id", "");//商户证书id, // PETALPAY.MERC_AUTH_ID, 商户证书id
|
||||||
$sign_type = input("sign_type", "RSA2");//商户公私钥签名类型, // PETALPAY.SIGN_TYPE, 签名类型, 默认使用RSA
|
$sign_type = input("sign_type", "RSA2");//商户公私钥签名类型, // PETALPAY.SIGN_TYPE, 签名类型, 默认使用RSA
|
||||||
$huawei_public_key = input("huawei_public_key", ""); //华为公钥, // PETALPAY.HW_PAY_PUBLIC_KEY_FOR_CALLBACK, 华为公钥
|
$huawei_public_key = input("huawei_public_key", ""); //华为公钥, // PETALPAY.HW_PAY_PUBLIC_KEY_FOR_CALLBACK, 华为公钥
|
||||||
|
$huawei_public_key_text = input("huawei_public_key_text", ""); //华为公钥文本, // PETALPAY.HW_PAY_PUBLIC_KEY_TEXT_FOR_CALLBACK, 华为公钥文本
|
||||||
$huawei_public_key_for_sessionkey = input("huawei_public_key_for_sessionkey", ""); //华为公钥, // PETALPAY.HW_PAY_PUBLIC_KEY_FOR_SESSIONKEY, 华为公钥
|
$huawei_public_key_for_sessionkey = input("huawei_public_key_for_sessionkey", ""); //华为公钥, // PETALPAY.HW_PAY_PUBLIC_KEY_FOR_SESSIONKEY, 华为公钥
|
||||||
|
$huawei_public_key_for_sessionkey_text = input("huawei_public_key_for_sessionkey_text", ""); //华为公钥文本, // PETALPAY.HW_PAY_PUBLIC_KEY_TEXT_FOR_SESSIONKEY, 华为公钥文本
|
||||||
|
$cert_type = input("cert_type", "file");//证书配置方式, // PETALPAY.CERT_TYPE, 证书配置方式: file(文件上传), text(文本填写)
|
||||||
$enable_app_types = input("enable_app_types", '');//支持端口 如web app,app // PETALPAY.ENABLE_APP_TYPES, 支持的支付端口
|
$enable_app_types = input("enable_app_types", '');//支持端口 如web app,app // PETALPAY.ENABLE_APP_TYPES, 支持的支付端口
|
||||||
$pay_status = input("pay_status", 0);//支付启用状态
|
$pay_status = input("pay_status", 0);//支付启用状态
|
||||||
$refund_status = input("refund_status", 0);//退款启用状态
|
$refund_status = input("refund_status", 0);//退款启用状态
|
||||||
@@ -34,10 +38,14 @@ class Pay extends BaseShop
|
|||||||
"app_id" => $app_id,
|
"app_id" => $app_id,
|
||||||
"mch_id" => $mch_id,
|
"mch_id" => $mch_id,
|
||||||
"private_key" => $private_key,
|
"private_key" => $private_key,
|
||||||
|
"private_key_text" => $private_key_text,
|
||||||
"mch_auth_id" => $mch_auth_id,
|
"mch_auth_id" => $mch_auth_id,
|
||||||
"sign_type" => $sign_type,
|
"sign_type" => $sign_type,
|
||||||
"huawei_public_key" => $huawei_public_key,
|
"huawei_public_key" => $huawei_public_key,
|
||||||
|
"huawei_public_key_text" => $huawei_public_key_text,
|
||||||
"huawei_public_key_for_sessionkey" => $huawei_public_key_for_sessionkey,
|
"huawei_public_key_for_sessionkey" => $huawei_public_key_for_sessionkey,
|
||||||
|
"huawei_public_key_for_sessionkey_text" => $huawei_public_key_for_sessionkey_text,
|
||||||
|
"cert_type" => $cert_type,
|
||||||
"refund_status" => $refund_status,
|
"refund_status" => $refund_status,
|
||||||
"pay_status" => $pay_status,
|
"pay_status" => $pay_status,
|
||||||
"transfer_status" => $transfer_status,
|
"transfer_status" => $transfer_status,
|
||||||
|
|||||||
@@ -1,9 +1,19 @@
|
|||||||
<style>
|
<style>
|
||||||
.input-text span{margin-right: 15px;}
|
.input-text span{margin-right: 15px;}
|
||||||
.file-upload {display: inline-block; margin-right: 5px;}
|
.file-upload {display: inline-block; margin-right: 5px;}
|
||||||
|
.cert-type-switch {margin-bottom: 15px;}
|
||||||
|
.cert-textarea {width: 100%; height: 100px; margin-top: 10px;}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="layui-form form-wrap">
|
<div class="layui-form form-wrap">
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">证书配置方式:</label>
|
||||||
|
<div class="layui-input-block cert-type-switch">
|
||||||
|
<input type="radio" name="cert_type" value="text" title="文本填写" lay-filter="cert_type" {if empty($info.cert_type) || $info.cert_type == 'text'}checked{/if}>
|
||||||
|
<input type="radio" name="cert_type" value="file" title="文件上传" lay-filter="cert_type" {if !empty($info.cert_type) && $info.cert_type == 'file'}checked{/if}>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label" name="mch_id"><span class="required">*</span>商户号:</label>
|
<label class="layui-form-label" name="mch_id"><span class="required">*</span>商户号:</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
@@ -23,15 +33,22 @@
|
|||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label" name="private_key_upload"><span class="required">*</span>商户应用私钥:</label>
|
<label class="layui-form-label" name="private_key_upload"><span class="required">*</span>商户应用私钥:</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
{notempty name="$info.private_key"}
|
<!-- 文件上传模式 -->
|
||||||
<p class="file-upload">已上传✅</p>
|
<div class="cert-config-file" {if !isset($info.cert_type) || empty($info.cert_type) || $info.cert_type == 'text'}style="display: none;"{/if}>
|
||||||
{else/}
|
{notempty name="$info.private_key" && empty($info.private_key_text)}
|
||||||
<p class="file-upload">未上传</p>
|
<p class="file-upload">已上传✅</p>
|
||||||
{/notempty}
|
{else/}
|
||||||
<button type="button" class="layui-btn" id="private_key_upload">
|
<p class="file-upload">未上传</p>
|
||||||
<i class="layui-icon"></i>上传文件
|
{/notempty}
|
||||||
</button>
|
<button type="button" class="layui-btn" id="private_key_upload">
|
||||||
<input type="hidden" name="private_key" class="layui-input len-long" value="{$info.private_key ?? ''}" lay-verify="private_key">
|
<i class="layui-icon"></i>上传文件
|
||||||
|
</button>
|
||||||
|
<input type="hidden" name="private_key" class="layui-input len-long" value="{$info.private_key ?? ''}" lay-verify="private_key">
|
||||||
|
</div>
|
||||||
|
<!-- 文本填写模式 -->
|
||||||
|
<div class="cert-config-text" {if isset($info.cert_type) && $info.cert_type == 'file'}style="display: none;"{/if}>
|
||||||
|
<textarea name="private_key_text" class="layui-textarea cert-textarea" placeholder="请输入商户应用私钥内容">{$info.private_key_text ?? ''}</textarea>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="word-aux">上传商户应用私钥.pem 文件 </div>
|
<div class="word-aux">上传商户应用私钥.pem 文件 </div>
|
||||||
<div class="word-aux">如何获取商户应用私钥.pem文件 <a href="https://developer.huawei.com/consumer/cn/doc/HMSCore-Guides/certificate-preparation-0000001596094962#section1886895941411" target="_blank">查看指引</a></div>
|
<div class="word-aux">如何获取商户应用私钥.pem文件 <a href="https://developer.huawei.com/consumer/cn/doc/HMSCore-Guides/certificate-preparation-0000001596094962#section1886895941411" target="_blank">查看指引</a></div>
|
||||||
@@ -48,15 +65,22 @@
|
|||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label" name="huawei_public_key_upload"><span class="required">*</span>华为支付证书:</label>
|
<label class="layui-form-label" name="huawei_public_key_upload"><span class="required">*</span>华为支付证书:</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
{notempty name="$info.huawei_public_key"}
|
<!-- 文件上传模式 -->
|
||||||
<p class="file-upload">已上传✅</p>
|
<div class="cert-config-file" {if !isset($info.cert_type) || empty($info.cert_type) || $info.cert_type == 'text'}style="display: none;"{/if}>
|
||||||
{else/}
|
{notempty name="$info.huawei_public_key" && empty($info.huawei_public_key_text)}
|
||||||
<p class="file-upload">未上传</p>
|
<p class="file-upload">已上传✅</p>
|
||||||
{/notempty}
|
{else/}
|
||||||
<button type="button" class="layui-btn" id="huawei_public_key_upload">
|
<p class="file-upload">未上传</p>
|
||||||
<i class="layui-icon"></i>上传文件
|
{/notempty}
|
||||||
</button>
|
<button type="button" class="layui-btn" id="huawei_public_key_upload">
|
||||||
<input type="hidden" name="huawei_public_key" class="layui-input len-long" value="{$info.huawei_public_key ?? ''}" lay-verify="huawei_public_key">
|
<i class="layui-icon"></i>上传文件
|
||||||
|
</button>
|
||||||
|
<input type="hidden" name="huawei_public_key" class="layui-input len-long" value="{$info.huawei_public_key ?? ''}" lay-verify="huawei_public_key">
|
||||||
|
</div>
|
||||||
|
<!-- 文本填写模式 -->
|
||||||
|
<div class="cert-config-text" {if isset($info.cert_type) && $info.cert_type == 'file'}style="display: none;"{/if}>
|
||||||
|
<textarea name="huawei_public_key_text" class="layui-textarea cert-textarea" placeholder="请输入华为支付证书内容">{$info.huawei_public_key_text ?? ''}</textarea>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="word-aux">上传华为支付证书.pem文件</div>
|
<div class="word-aux">上传华为支付证书.pem文件</div>
|
||||||
<div class="word-aux">如何获取华为支付证书.pem文件,<a href="https://developer.huawei.com/consumer/cn/doc/HMSCore-Guides/certificate-preparation-0000001596094962#section377312802116" target="_blank">查看指引</a></div>
|
<div class="word-aux">如何获取华为支付证书.pem文件,<a href="https://developer.huawei.com/consumer/cn/doc/HMSCore-Guides/certificate-preparation-0000001596094962#section377312802116" target="_blank">查看指引</a></div>
|
||||||
@@ -65,15 +89,22 @@
|
|||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label" name="huawei_public_key_for_sessionkey_upload">(可选)华为支付服务加密公钥:</label>
|
<label class="layui-form-label" name="huawei_public_key_for_sessionkey_upload">(可选)华为支付服务加密公钥:</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
{notempty name="$info.huawei_public_key_for_sessionkey"}
|
<!-- 文件上传模式 -->
|
||||||
<p class="file-upload">已上传✅</p>
|
<div class="cert-config-file" {if !isset($info.cert_type) || empty($info.cert_type) || $info.cert_type == 'text'}style="display: none;"{/if}>
|
||||||
{else/}
|
{notempty name="$info.huawei_public_key_for_sessionkey" && empty($info.huawei_public_key_for_sessionkey_text)}
|
||||||
<p class="file-upload">未上传</p>
|
<p class="file-upload">已上传✅</p>
|
||||||
{/notempty}
|
{else/}
|
||||||
<button type="button" class="layui-btn" id="huawei_public_key_for_sessionkey_upload">
|
<p class="file-upload">未上传</p>
|
||||||
<i class="layui-icon"></i>上传文件
|
{/notempty}
|
||||||
</button>
|
<button type="button" class="layui-btn" id="huawei_public_key_for_sessionkey_upload">
|
||||||
<input type="hidden" name="huawei_public_key_for_sessionkey" class="layui-input len-long" value="{$info.huawei_public_key_for_sessionkey ?? ''}">
|
<i class="layui-icon"></i>上传文件
|
||||||
|
</button>
|
||||||
|
<input type="hidden" name="huawei_public_key_for_sessionkey" class="layui-input len-long" value="{$info.huawei_public_key_for_sessionkey ?? ''}">
|
||||||
|
</div>
|
||||||
|
<!-- 文本填写模式 -->
|
||||||
|
<div class="cert-config-text" {if isset($info.cert_type) && $info.cert_type == 'file'}style="display: none;"{/if}>
|
||||||
|
<textarea name="huawei_public_key_for_sessionkey_text" class="layui-textarea cert-textarea" placeholder="请输入华为支付服务加密公钥内容">{$info.huawei_public_key_for_sessionkey_text ?? ''}</textarea>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="word-aux">上传华为支付服务加密公钥.pem文件</div>
|
<div class="word-aux">上传华为支付服务加密公钥.pem文件</div>
|
||||||
<div class="word-aux">(可选)加密公钥, 没有可以不填 <a href="https://developer.huawei.com/consumer/cn/doc/HMSCore-Guides/certificate-preparation-0000001596094962#section377312802116" target="_blank">查看指引</a></div>
|
<div class="word-aux">(可选)加密公钥, 没有可以不填 <a href="https://developer.huawei.com/consumer/cn/doc/HMSCore-Guides/certificate-preparation-0000001596094962#section377312802116" target="_blank">查看指引</a></div>
|
||||||
@@ -118,115 +149,163 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
layui.use('form', function() {
|
layui.use('form', function() {
|
||||||
var form = layui.form;
|
var form = layui.form;
|
||||||
var repeat_flag = false; //防重复标识
|
var repeat_flag = false; //防重复标识
|
||||||
form.render();
|
form.render();
|
||||||
|
|
||||||
// 上传商户应用私钥.pem 文件
|
// 页面初始加载时根据当前选中的radio状态设置证书配置方式
|
||||||
new Upload({
|
var initCertType = $('input[name="cert_type"]:checked').val();
|
||||||
elem: '#private_key_upload',
|
if (initCertType == 'file') {
|
||||||
url: ns.url("huaweipay://shop/pay/uploadHuaweiCrt"),
|
$('.cert-config-file').show();
|
||||||
accept: 'file',
|
$('.cert-config-text').hide();
|
||||||
callback: function(res){
|
} else {
|
||||||
if (res.code >= 0) {
|
$('.cert-config-file').hide();
|
||||||
$('input[name="private_key"]').val(res.data.path);
|
$('.cert-config-text').show();
|
||||||
$('input[name="private_key"]').siblings(".file-upload").text("已上传✅");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// 上传华为支付服务加密公钥.pem文件
|
// 证书类型切换
|
||||||
new Upload({
|
form.on('radio(cert_type)', function(data) {
|
||||||
elem: '#huawei_public_key_for_sessionkey_upload',
|
var certType = data.value;
|
||||||
url: ns.url("huaweipay://shop/pay/uploadHuaweiCrt"),
|
if (certType == 'file') {
|
||||||
accept: 'file',
|
$('.cert-config-file').show();
|
||||||
callback: function(res){
|
$('.cert-config-text').hide();
|
||||||
if (res.code >= 0) {
|
} else {
|
||||||
$('input[name="huawei_public_key_for_sessionkey"]').val(res.data.path);
|
$('.cert-config-file').hide();
|
||||||
$('input[name="huawei_public_key_for_sessionkey"]').siblings(".file-upload").text("已上传✅");
|
$('.cert-config-text').show();
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// 上传华为支付证书.pem文件
|
// 上传商户应用私钥.pem 文件
|
||||||
new Upload({
|
new Upload({
|
||||||
elem: '#huawei_public_key_upload',
|
elem: '#private_key_upload',
|
||||||
url: ns.url("huaweipay://shop/pay/uploadHuaweiCrt"),
|
url: ns.url("huaweipay://shop/pay/uploadHuaweiCrt"),
|
||||||
accept: 'file',
|
accept: 'file',
|
||||||
callback: function(res){
|
callback: function(res){
|
||||||
if (res.code >= 0) {
|
|
||||||
$('input[name="huawei_public_key"]').val(res.data.path);
|
|
||||||
$('input[name="huawei_public_key"]').siblings(".file-upload").text("已上传✅");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 表单验证
|
|
||||||
*/
|
|
||||||
form.verify({
|
|
||||||
private_key: function(value){
|
|
||||||
if (!/[\S]+/.test(value)) return '请上传商户应用私钥.pem文件';
|
|
||||||
},
|
|
||||||
huawei_public_key: function(value){
|
|
||||||
if (!/[\S]+/.test(value)) return '请上传华为支付证书.pem文件';
|
|
||||||
},
|
|
||||||
// 可选
|
|
||||||
// huawei_public_key_for_sessionkey: function(value){
|
|
||||||
// if (!/[\S]+/.test(value)) return '请上传华为支付服务加密公钥.pem文件';
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 监听提交
|
|
||||||
*/
|
|
||||||
form.on('submit(save)', function(data) {
|
|
||||||
if (repeat_flag) return false;
|
|
||||||
repeat_flag = true;
|
|
||||||
|
|
||||||
// 处理 enable_app_types 字段
|
|
||||||
{
|
|
||||||
const values = [];
|
|
||||||
let i = 0;
|
|
||||||
|
|
||||||
while (data.field.hasOwnProperty(`enable_app_types[${i}]`)) {
|
|
||||||
const val = data.field[`enable_app_types[${i}]`];
|
|
||||||
if (val != null && val !== '') {
|
|
||||||
values.push(val);
|
|
||||||
}
|
|
||||||
delete data.field[`enable_app_types[${i}]`]; // 可选:清理旧字段
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
data.field.enable_app_types = values.join(',');
|
|
||||||
}
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: ns.url("huaweipay://shop/pay/config"),
|
|
||||||
data: data.field,
|
|
||||||
dataType: 'JSON',
|
|
||||||
type: 'POST',
|
|
||||||
success: function(res){
|
|
||||||
repeat_flag = false;
|
|
||||||
if (res.code >= 0) {
|
if (res.code >= 0) {
|
||||||
layer.confirm('编辑成功', {
|
$('input[name="private_key"]').val(res.data.path);
|
||||||
title:'操作提示',
|
$('input[name="private_key"]').siblings(".file-upload").text("已上传✅");
|
||||||
btn: ['返回列表', '继续编辑'],
|
|
||||||
yes: function(index, layero) {
|
|
||||||
location.hash = ns.hash("shop/config/pay");
|
|
||||||
layer.close(index);
|
|
||||||
},
|
|
||||||
btn2: function(index, layero) {
|
|
||||||
layer.close(index);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
layer.msg(res.message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
// 上传华为支付服务加密公钥.pem文件
|
||||||
|
new Upload({
|
||||||
|
elem: '#huawei_public_key_for_sessionkey_upload',
|
||||||
|
url: ns.url("huaweipay://shop/pay/uploadHuaweiCrt"),
|
||||||
|
accept: 'file',
|
||||||
|
callback: function(res){
|
||||||
|
if (res.code >= 0) {
|
||||||
|
$('input[name="huawei_public_key_for_sessionkey"]').val(res.data.path);
|
||||||
|
$('input[name="huawei_public_key_for_sessionkey"]').siblings(".file-upload").text("已上传✅");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 上传华为支付证书.pem文件
|
||||||
|
new Upload({
|
||||||
|
elem: '#huawei_public_key_upload',
|
||||||
|
url: ns.url("huaweipay://shop/pay/uploadHuaweiCrt"),
|
||||||
|
accept: 'file',
|
||||||
|
callback: function(res){
|
||||||
|
if (res.code >= 0) {
|
||||||
|
$('input[name="huawei_public_key"]').val(res.data.path);
|
||||||
|
$('input[name="huawei_public_key"]').siblings(".file-upload").text("已上传✅");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表单验证
|
||||||
|
*/
|
||||||
|
form.verify({
|
||||||
|
private_key: function(value){
|
||||||
|
var certType = $('input[name="cert_type"]:checked').val();
|
||||||
|
if (certType == 'file') {
|
||||||
|
if (!/[\S]+/.test(value)) return '请上传商户应用私钥.pem文件';
|
||||||
|
} else {
|
||||||
|
var privateKeyText = $('textarea[name="private_key_text"]').val();
|
||||||
|
if (!/[\S]+/.test(privateKeyText)) return '请输入商户应用私钥内容';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
huawei_public_key: function(value){
|
||||||
|
var certType = $('input[name="cert_type"]:checked').val();
|
||||||
|
if (certType == 'file') {
|
||||||
|
if (!/[\S]+/.test(value)) return '请上传华为支付证书.pem文件';
|
||||||
|
} else {
|
||||||
|
var huaweiPublicKeyText = $('textarea[name="huawei_public_key_text"]').val();
|
||||||
|
if (!/[\S]+/.test(huaweiPublicKeyText)) return '请输入华为支付证书内容';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监听提交
|
||||||
|
*/
|
||||||
|
form.on('submit(save)', function(data) {
|
||||||
|
if (repeat_flag) return false;
|
||||||
|
repeat_flag = true;
|
||||||
|
|
||||||
|
// 处理 enable_app_types 字段
|
||||||
|
{
|
||||||
|
const values = [];
|
||||||
|
let i = 0;
|
||||||
|
|
||||||
|
while (data.field.hasOwnProperty(`enable_app_types[${i}]`)) {
|
||||||
|
const val = data.field[`enable_app_types[${i}]`];
|
||||||
|
if (val != null && val !== '') {
|
||||||
|
values.push(val);
|
||||||
|
}
|
||||||
|
delete data.field[`enable_app_types[${i}]`]; // 可选:清理旧字段
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
data.field.enable_app_types = values.join(',');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理证书内容
|
||||||
|
var certType = data.field.cert_type;
|
||||||
|
if (certType == 'text') {
|
||||||
|
// 添加文本模式下的证书内容
|
||||||
|
data.field.private_key_text = $('textarea[name="private_key_text"]').val();
|
||||||
|
data.field.huawei_public_key_text = $('textarea[name="huawei_public_key_text"]').val();
|
||||||
|
data.field.huawei_public_key_for_sessionkey_text = $('textarea[name="huawei_public_key_for_sessionkey_text"]').val();
|
||||||
|
// 清空文件模式下的字段
|
||||||
|
data.field.private_key = '';
|
||||||
|
data.field.huawei_public_key = '';
|
||||||
|
data.field.huawei_public_key_for_sessionkey = '';
|
||||||
|
} else {
|
||||||
|
// 清空文本模式下的字段
|
||||||
|
data.field.private_key_text = '';
|
||||||
|
data.field.huawei_public_key_text = '';
|
||||||
|
data.field.huawei_public_key_for_sessionkey_text = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: ns.url("huaweipay://shop/pay/config"),
|
||||||
|
data: data.field,
|
||||||
|
dataType: 'JSON',
|
||||||
|
type: 'POST',
|
||||||
|
success: function(res){
|
||||||
|
repeat_flag = false;
|
||||||
|
if (res.code >= 0) {
|
||||||
|
layer.confirm('编辑成功', {
|
||||||
|
title:'操作提示',
|
||||||
|
btn: ['返回列表', '继续编辑'],
|
||||||
|
yes: function(index, layero) {
|
||||||
|
location.hash = ns.hash("shop/config/pay");
|
||||||
|
layer.close(index);
|
||||||
|
},
|
||||||
|
btn2: function(index, layero) {
|
||||||
|
layer.close(index);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
layer.msg(res.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function back(){
|
function back(){
|
||||||
|
|||||||
Reference in New Issue
Block a user