chore: 更新企业微信配置页面

This commit is contained in:
2025-12-16 10:50:58 +08:00
parent 09c859750e
commit 3aab5b9c75
3 changed files with 442 additions and 55 deletions

View File

@@ -856,6 +856,23 @@ class Config extends BaseModel
*/ */
public function setWxworkConfig($data, $site_id = 1, $app_module = 'shop') public function setWxworkConfig($data, $site_id = 1, $app_module = 'shop')
{ {
// 只要提供了Secret就自动生成时间戳、随机字符串和签名
if (!empty($data['secret'])) {
$data['timestamp'] = time();
// 生成16位随机字符串
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$nonceStr = '';
for ($i = 0; $i < 16; $i++) {
$nonceStr .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
$data['nonceStr'] = $nonceStr;
// 生成SHA1签名
$string = 'secret=' . $data['secret'] . '&timestamp=' . $data['timestamp'] . '&nonceStr=' . $data['nonceStr'];
$data['signature'] = sha1($string);
}
$config = new ConfigModel(); $config = new ConfigModel();
$res = $config->setConfig($data, '企业微信配置', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'WXWORK_CONFIG' ] ]); $res = $config->setConfig($data, '企业微信配置', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'WXWORK_CONFIG' ] ]);
return $res; return $res;
@@ -875,6 +892,7 @@ class Config extends BaseModel
$res[ 'data' ][ 'value' ] = [ $res[ 'data' ][ 'value' ] = [
'corp_id' => '', 'corp_id' => '',
'agent_id' => '', 'agent_id' => '',
'secret' => '',
'contact_id' => '', 'contact_id' => '',
'contact_url' => '', 'contact_url' => '',
'timestamp' => '', 'timestamp' => '',

View File

@@ -220,6 +220,7 @@ class Config extends BaseShop
$data = [ $data = [
'corp_id' => input('corp_id', ''), 'corp_id' => input('corp_id', ''),
'agent_id' => input('agent_id', ''), 'agent_id' => input('agent_id', ''),
'secret' => input('secret', ''),
'contact_id' => input('contact_id', ''), 'contact_id' => input('contact_id', ''),
'contact_url' => input('contact_url', ''), 'contact_url' => input('contact_url', ''),
'timestamp' => input('timestamp', ''), 'timestamp' => input('timestamp', ''),

View File

@@ -3,9 +3,30 @@
.wxwork-form .layui-form-item{margin-bottom: 20px;} .wxwork-form .layui-form-item{margin-bottom: 20px;}
.wxwork-form .layui-input-block{margin-left: 120px;} .wxwork-form .layui-input-block{margin-left: 120px;}
.wxwork-help{color: #999; font-size: 12px; margin-top: 5px;} .wxwork-help{color: #999; font-size: 12px; margin-top: 5px;}
.wxwork-required{color: #ff5722; margin-right: 4px;}
.wxwork-guide{background: #f8f9fa; border-left: 3px solid #007bff; padding: 15px; margin-top: 10px; border-radius: 4px;}
.wxwork-guide h4{margin: 0 0 10px 0; color: #007bff;}
.wxwork-guide ol{margin: 0; padding-left: 20px;}
.wxwork-guide li{margin-bottom: 8px;}
.wxwork-code{background: #f1f3f4; padding: 2px 6px; border-radius: 3px; font-family: monospace; font-size: 12px;}
.wxwork-field-required .layui-form-label{color: #333;}
.wxwork-link{color: #007bff; text-decoration: none;}
.wxwork-link:hover{text-decoration: underline;}
.wxwork-guide-toggle{margin-top: 30px;}
.wxwork-guide-toggle .guide-toggle-btn{width: 100%; padding: 12px; background: #f8f9fa; border: 1px solid #dee2e6; border-radius: 4px; cursor: pointer; transition: all 0.3s; display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 14px; color: #333;}
.wxwork-guide-toggle .guide-toggle-btn:hover{background: #e9ecef; border-color: #007bff;}
.wxwork-guide-toggle .guide-toggle-btn.active{background: #007bff; color: white; border-color: #007bff;}
.wxwork-guide-toggle .guide-content{margin-top: 15px; background: #f8f9fa; border-left: 3px solid #007bff; padding: 15px; border-radius: 4px; display: none;}
.wxwork-guide-toggle .guide-content.show{display: block;}
.guide-toggle-icon{transition: transform 0.3s;}
.guide-toggle-icon.rotate{transform: rotate(180deg);}
.password-wrapper{position: relative;}
.password-toggle{position: absolute; right: 10px; top: 50%; transform: translateY(-50%); cursor: pointer; color: #999; font-size: 16px; user-select: none;}
.password-toggle:hover{color: #007bff;}
</style> </style>
<div class="layui-form form-wrap wxwork-form"> <div class="layui-form form-wrap wxwork-form">
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">启用状态:</label> <label class="layui-form-label">启用状态:</label>
<div class="layui-input-block"> <div class="layui-input-block">
@@ -14,79 +35,182 @@
<div class="wxwork-help">开启后,企业微信相关功能将可用</div> <div class="wxwork-help">开启后,企业微信相关功能将可用</div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item wxwork-field-required">
<label class="layui-form-label">企业ID</label> <label class="layui-form-label"><span class="wxwork-required">*</span>企业ID</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="text" name="corp_id" autocomplete="off" value="{$wxwork_config.corp_id ?? ''}" class="layui-input len-long"> <input type="text" name="corp_id" required autocomplete="off" value="{$wxwork_config.corp_id ?? ''}" class="layui-input len-long" placeholder="wwxxxxxxxxxxxx">
</div> </div>
<div class="wxwork-help"> <div class="wxwork-help">
<p>企业微信的企业ID可在企业微信管理后台获取</p> <p><strong>获取方式</strong>:企业微信管理后台 → 我的企业 → 企业信息 → 企业ID</p>
<p><strong>格式</strong>:通常以 "ww" 开头的18位字符串</p>
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item wxwork-field-required">
<label class="layui-form-label">应用ID</label> <label class="layui-form-label"><span class="wxwork-required">*</span>应用ID</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="text" name="agent_id" autocomplete="off" value="{$wxwork_config.agent_id ?? ''}" class="layui-input len-long"> <input type="text" name="agent_id" required autocomplete="off" value="{$wxwork_config.agent_id ?? ''}" class="layui-input len-long" placeholder="1000001">
</div> </div>
<div class="wxwork-help"> <div class="wxwork-help">
<p>企业微信应用的AgentId创建应用后获取</p> <p><strong>获取方式</strong>:应用管理 → 选择应用 → 查看应用详情 → AgentId</p>
<p><strong>格式</strong>:数字字符串,如 1000001</p>
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item wxwork-field-required">
<label class="layui-form-label">客服ID</label> <label class="layui-form-label"><span class="wxwork-required">*</span>应用Secret</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="text" name="contact_id" autocomplete="off" value="{$wxwork_config.contact_id ?? ''}" class="layui-input len-long"> <div class="password-wrapper">
<input type="password" name="secret" id="secret-input" required autocomplete="off" value="{$wxwork_config.secret ?? ''}" class="layui-input len-long" placeholder="请输入应用Secret">
<span class="password-toggle" onclick="togglePassword()">👁️</span>
</div> </div>
<div class="wxwork-help"> </div>
<p>企业微信客服的ID用于客服功能</p> <div class="wxwork-help" style="color: #ff5722;">
<p><strong>获取方式</strong>:企业微信管理后台 → 应用管理 → 选择应用 → 查看Secret</p>
<p><strong>说明</strong><strong style="color: #ff5722;">系统必需</strong>:用于自动生成签名,请妥善保管</p>
<p><strong>安全提示</strong>Secret仅在创建时可见请立即复制保存</p>
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item wxwork-field-required">
<label class="layui-form-label">活码链接</label> <label class="layui-form-label"><span class="wxwork-required">*</span>客服ID</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="text" name="contact_url" autocomplete="off" value="{$wxwork_config.contact_url ?? ''}" class="layui-input len-long"> <input type="text" name="contact_id" required autocomplete="off" value="{$wxwork_config.contact_id ?? ''}" class="layui-input len-long" placeholder="kfc_xxxxx">
</div> </div>
<div class="wxwork-help"> <div class="wxwork-help" style="color: #ff5722;">
<p>企业微信活码的链接地址</p> <p><strong>获取方式</strong>:企业微信管理后台 → 应用管理 → 客服 → 联系我</p>
<p><strong>说明</strong><strong style="color: #ff5722;">系统必需功能</strong>,用于企业微信客服对接</p>
<p><strong>格式</strong>:通常以 "kfc_" 开头的字符串</p>
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item wxwork-field-required">
<label class="layui-form-label">时间戳</label> <label class="layui-form-label"><span class="wxwork-required">*</span>活码链接</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="text" name="timestamp" autocomplete="off" value="{$wxwork_config.timestamp ?? ''}" class="layui-input len-long"> <input type="text" name="contact_url" required autocomplete="off" value="{$wxwork_config.contact_url ?? ''}" class="layui-input len-long" placeholder="https://work.weixin.qq.com/kf/...">
</div> </div>
<div class="wxwork-help"> <div class="wxwork-help" style="color: #ff5722;">
<p>用于验证的时间戳,通常由系统自动生成</p> <p><strong>获取方式</strong>:企业微信管理后台 → 客服 → 联系我 → 生成活码</p>
<p><strong>说明</strong><strong style="color: #ff5722;">系统必需功能</strong>,客服活码的完整链接地址</p>
<p><strong>格式</strong>完整的HTTPS链接如 https://work.weixin.qq.com/kf/xxxx</p>
</div> </div>
</div> </div>
<div class="layui-form-item"> <!-- 隐藏的自动生成字段 -->
<label class="layui-form-label">随机字符串:</label> <input type="hidden" name="timestamp" value="{$wxwork_config.timestamp ?? ''}">
<div class="layui-input-block"> <input type="hidden" name="nonceStr" value="{$wxwork_config.nonceStr ?? ''}">
<input type="text" name="nonceStr" autocomplete="off" value="{$wxwork_config.nonceStr ?? ''}" class="layui-input len-long"> <input type="hidden" name="signature" value="{$wxwork_config.signature ?? ''}">
</div>
<div class="wxwork-help">
<p>用于验证的随机字符串</p>
</div>
</div>
<!-- 系统状态显示区域 -->
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">签名:</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="text" name="signature" autocomplete="off" value="{$wxwork_config.signature ?? ''}" class="layui-input len-long"> <div class="wxwork-status-panel" style="border: 1px solid #e6e6e6; border-radius: 4px; padding: 15px; background: #fafafa; display: flex; flex-direction: column;">
<div style="margin-bottom: 10px;">
<span><strong>配置完整性:</strong></span>
<span id="config-completeness" style="color: #999;">检查中...</span>
</div>
<div style="margin-bottom: 10px;">
<span><strong>签名生成状态:</strong></span>
<span id="signature-status" style="color: #999;">点击保存配置,将自动生成</span>
</div>
<div style="margin-bottom: 10px;">
<span><strong>时间戳:</strong></span>
<span id="timestamp-value" style="color: #666;">{if condition="$wxwork_config.timestamp"}{$wxwork_config.timestamp}{else /}未生成{/if}</span>
</div>
<div style="margin-bottom: 10px;">
<span><strong>随机字符串:</strong></span>
<span id="nonce-str-value" style="color: #666;">{if condition="$wxwork_config.nonceStr"}{$wxwork_config.nonceStr}{else /}未生成{/if}</span>
</div>
<div style="margin-bottom: 10px;">
<span><strong>签名:</strong></span>
<span id="signature-value" style="color: #52c41a; font-family: monospace; font-size: 12px; word-break: break-all;">{if condition="$wxwork_config.signature"}{$wxwork_config.signature}{else /}未生成{/if}</span>
</div>
<div>
<span><strong>最后更新时间:</strong></span>
<span id="last-update-time" style="color: #666;">{if condition="$wxwork_config.timestamp"}<?php echo date('Y-m-d H:i:s', $wxwork_config['timestamp']); ?>{else /}从未生成{/if}</span>
</div>
</div>
</div> </div>
<div class="wxwork-help"> <div class="wxwork-help">
<p>用于验证的签名,通常由系统自动生成</p> <p><strong>说明</strong>:系统将在保存配置时自动生成时间戳、随机字符串和签名</p>
<p><strong>生成规则</strong>基于Secret使用SHA1算法生成用于企业微信API验证</p>
</div> </div>
</div> </div>
<div class="form-row"> <div class="form-row">
<button class="layui-btn" lay-submit lay-filter="save">保存</button> <button class="layui-btn" lay-submit lay-filter="save">保存配置</button>
<button type="button" class="layui-btn layui-btn-primary" onclick="window.location.reload()">重置</button> <button type="button" class="layui-btn layui-btn-primary" onclick="window.location.reload()">重置</button>
<button type="button" class="layui-btn layui-btn-normal" onclick="window.open('https://work.weixin.qq.com/', '_blank')">企业微信管理后台</button>
</div>
</div>
<!-- 获取指南 -->
<div class="wxwork-guide-toggle">
<div class="guide-toggle-btn" onclick="toggleGuide()">
<span>📋 企业微信配置获取指南</span>
<span class="guide-toggle-icon"></span>
</div>
<div class="guide-content">
<p style="color: #ff5722; font-weight: bold; margin-bottom: 15px;">⚠️ 注意:客服功能为系统必需功能,必须正确配置相关参数</p>
<ol>
<li><strong>登录企业微信管理后台</strong><a href="https://work.weixin.qq.com/" target="_blank" class="wxwork-link">https://work.weixin.qq.com/</a></li>
<li><strong>获取企业ID</strong>进入「我的企业」→「企业信息」→「企业ID」</li>
<li><strong>创建应用</strong>:进入「应用管理」→「应用」→「创建应用」→「自建」</li>
<li><strong>获取应用ID</strong>:创建完成后进入应用详情页,查看 <span class="wxwork-code">AgentId</span></li>
<li><strong>获取Secret</strong>:在应用详情页查看 <span class="wxwork-code">Secret</span>(用于生成签名)</li>
<li><strong>配置可信域名</strong>在应用详情页设置可信域名用于JS接口调用</li>
<li><strong>开启客服功能</strong><strong style="color: #ff5722;">(必需)</strong>进入「应用管理」→「客服」→「联系我」→ 开启服务</li>
<li><strong>获取客服参数</strong>在客服页面获取客服ID和活码链接</li>
</ol>
<h5 style="margin-top: 15px; color: #007bff;">🔧 参数获取方式说明</h5>
<table style="width: 100%; border-collapse: collapse; margin-top: 10px;">
<tr style="background: #f8f9fa;">
<th style="border: 1px solid #dee2e6; padding: 8px; text-align: left;">参数名称</th>
<th style="border: 1px solid #dee2e6; padding: 8px; text-align: left;">获取方式</th>
<th style="border: 1px solid #dee2e6; padding: 8px; text-align: left;">说明</th>
</tr>
<tr>
<td style="border: 1px solid #dee2e6; padding: 8px;">企业ID</td>
<td style="border: 1px solid #dee2e6; padding: 8px;">企业微信管理后台 → 我的企业 → 企业信息 → 企业ID</td>
<td style="border: 1px solid #dee2e6; padding: 8px;">企业唯一标识</td>
</tr>
<tr>
<td style="border: 1px solid #dee2e6; padding: 8px;">应用ID</td>
<td style="border: 1px solid #dee2e6; padding: 8px;">企业微信管理后台 → 应用管理 → 选择应用 → 查看应用详情 → AgentId</td>
<td style="border: 1px solid #dee2e6; padding: 8px;">应用的AgentId</td>
</tr>
<tr>
<td style="border: 1px solid #dee2e6; padding: 8px;">应用Secret</td>
<td style="border: 1px solid #dee2e6; padding: 8px;">企业微信管理后台 → 应用管理 → 选择应用 → 查看Secret</td>
<td style="border: 1px solid #dee2e6; padding: 8px; color: #ff5722;"><strong>必需</strong>:用于生成签名的密钥</td>
</tr>
<tr>
<td style="border: 1px solid #dee2e6; padding: 8px;">客服ID</td>
<td style="border: 1px solid #dee2e6; padding: 8px;">企业微信管理后台 → 应用管理 → 客服 → 联系我</td>
<td style="border: 1px solid #dee2e6; padding: 8px; color: #ff5722;"><strong>必需</strong>:客服功能的唯一标识</td>
</tr>
<tr>
<td style="border: 1px solid #dee2e6; padding: 8px;">活码链接</td>
<td style="border: 1px solid #dee2e6; padding: 8px;">企业微信管理后台 → 客服 → 联系我 → 生成活码</td>
<td style="border: 1px solid #dee2e6; padding: 8px; color: #ff5722;"><strong>必需</strong>:客服活码的完整链接</td>
</tr>
<tr>
<td style="border: 1px solid #dee2e6; padding: 8px;">时间戳</td>
<td style="border: 1px solid #dee2e6; padding: 8px;"><span class="wxwork-code">本系统自动生成</span></td>
<td style="border: 1px solid #dee2e6; padding: 8px;">Unix时间戳无需手动填写</td>
</tr>
<tr>
<td style="border: 1px solid #dee2e6; padding: 8px;">随机字符串</td>
<td style="border: 1px solid #dee2e6; padding: 8px;"><span class="wxwork-code">本系统自动生成</span></td>
<td style="border: 1px solid #dee2e6; padding: 8px;">16位随机字符无需手动填写</td>
</tr>
<tr>
<td style="border: 1px solid #dee2e6; padding: 8px;">签名</td>
<td style="border: 1px solid #dee2e6; padding: 8px;"><span class="wxwork-code">本系统自动生成</span></td>
<td style="border: 1px solid #dee2e6; padding: 8px;">SHA1签名无需手动填写</td>
</tr>
</table>
</div> </div>
</div> </div>
@@ -98,10 +222,233 @@
form.render(); form.render();
/**
* 监听提交
*/ // 启用状态切换时的验证
$('input[name="enabled"]').on('change', function() {
if($(this).is(':checked')) {
var corpId = $('input[name="corp_id"]').val().trim();
var agentId = $('input[name="agent_id"]').val().trim();
var secret = $('input[name="secret"]').val().trim();
var contactId = $('input[name="contact_id"]').val().trim();
var contactUrl = $('input[name="contact_url"]').val().trim();
if(!corpId) {
layer.msg('请先填写企业ID必填项', {icon: 2});
$(this).prop('checked', false);
form.render();
$('input[name="corp_id"]').focus();
return;
}
if(!agentId) {
layer.msg('请先填写应用ID必填项', {icon: 2});
$(this).prop('checked', false);
form.render();
$('input[name="agent_id"]').focus();
return;
}
if(!secret) {
layer.msg('请先填写应用Secret系统必需', {icon: 2});
$(this).prop('checked', false);
form.render();
$('input[name="secret"]').focus();
return;
}
if(!contactId) {
layer.msg('请先填写客服ID系统必需功能', {icon: 2});
$(this).prop('checked', false);
form.render();
$('input[name="contact_id"]').focus();
return;
}
if(!contactUrl) {
layer.msg('请先填写活码链接(系统必需功能)', {icon: 2});
$(this).prop('checked', false);
form.render();
$('input[name="contact_url"]').focus();
return;
}
// 企业ID格式验证
if(!/^ww[a-zA-Z0-9]{16}$/.test(corpId)) {
layer.msg('企业ID格式不正确应为ww开头的18位字符', {icon: 2});
$(this).prop('checked', false);
form.render();
$('input[name="corp_id"]').focus();
return;
}
// 应用ID格式验证
if(!/^\d+$/.test(agentId)) {
layer.msg('应用ID格式不正确应为纯数字', {icon: 2});
$(this).prop('checked', false);
form.render();
$('input[name="agent_id"]').focus();
return;
}
// Secret格式验证
if(secret.length < 10) {
layer.msg('Secret格式不正确长度至少10位字符', {icon: 2});
$(this).prop('checked', false);
form.render();
$('input[name="secret"]').focus();
return;
}
layer.msg('配置验证通过!企业微信功能已启用,系统将自动生成签名', {icon: 1});
}
});
// 更新配置完整性状态
function updateConfigStatus() {
var corpId = $('input[name="corp_id"]').val().trim();
var agentId = $('input[name="agent_id"]').val().trim();
var secret = $('input[name="secret"]').val().trim();
var contactId = $('input[name="contact_id"]').val().trim();
var contactUrl = $('input[name="contact_url"]').val().trim();
var timestamp = $('input[name="timestamp"]').val();
var nonceStr = $('input[name="nonceStr"]').val();
var signature = $('input[name="signature"]').val();
// 更新配置完整性
var requiredFields = [corpId, agentId, secret, contactId, contactUrl];
var filledCount = requiredFields.filter(function(field) { return field.length > 0; }).length;
var completeness = Math.round((filledCount / requiredFields.length) * 100);
var completenessElement = $('#config-completeness');
if (completeness === 100) {
completenessElement.text('完整 (100%)').css('color', '#52c41a');
} else {
completenessElement.text('不完整 (' + completeness + '%)').css('color', '#ff7875');
}
// 更新签名状态和相关信息
var signatureElement = $('#signature-status');
var timestampElement = $('#timestamp-value');
var nonceStrElement = $('#nonce-str-value');
var signatureValueElement = $('#signature-value');
if (signature && timestamp) {
// 显示已存在的签名信息
signatureElement.text('已生成').css('color', '#52c41a');
timestampElement.text(timestamp).css('color', '#52c41a');
nonceStrElement.text(nonceStr || '未生成').css('color', '#52c41a');
signatureValueElement.text(signature).css('color', '#52c41a');
} else {
// 显示生成提示
if (completeness === 100) {
signatureElement.text('配置完整,点击保存将生成').css('color', '#1890ff');
} else {
signatureElement.text('请完善必填配置信息').css('color', '#ff7875');
}
timestampElement.text('未生成').css('color', '#999');
nonceStrElement.text('未生成').css('color', '#999');
signatureValueElement.text('未生成').css('color', '#999');
}
}
// 监听所有输入框变化
$('input[name="corp_id"], input[name="agent_id"], input[name="secret"], input[name="contact_id"], input[name="contact_url"]').on('input blur', function() {
updateConfigStatus();
});
// 初始化状态
updateConfigStatus();
// 表单提交前的必填项验证
form.on('submit(save)', function(data) { form.on('submit(save)', function(data) {
var corpId = data.field.corp_id.trim();
var agentId = data.field.agent_id.trim();
var secret = data.field.secret.trim();
var contactId = data.field.contact_id.trim();
var contactUrl = data.field.contact_url.trim();
// 验证企业ID
if(!corpId) {
layer.msg('企业ID为必填项', {icon: 2});
$('input[name="corp_id"]').focus();
repeat_flag = false;
return false;
}
// 验证应用ID
if(!agentId) {
layer.msg('应用ID为必填项', {icon: 2});
$('input[name="agent_id"]').focus();
repeat_flag = false;
return false;
}
// 验证Secret必需
if(!secret) {
layer.msg('应用Secret为系统必需参数必须填写', {icon: 2});
$('input[name="secret"]').focus();
repeat_flag = false;
return false;
}
// 验证客服ID必需
if(!contactId) {
layer.msg('客服ID为系统必需功能必须填写', {icon: 2});
$('input[name="contact_id"]').focus();
repeat_flag = false;
return false;
}
// 验证活码链接(必需)
if(!contactUrl) {
layer.msg('活码链接为系统必需功能,必须填写', {icon: 2});
$('input[name="contact_url"]').focus();
repeat_flag = false;
return false;
}
// 企业ID格式验证
if(!/^ww[a-zA-Z0-9]{16}$/.test(corpId)) {
layer.msg('企业ID格式不正确应为ww开头的18位字符', {icon: 2});
$('input[name="corp_id"]').focus();
repeat_flag = false;
return false;
}
// 应用ID格式验证
if(!/^\d+$/.test(agentId)) {
layer.msg('应用ID格式不正确应为纯数字', {icon: 2});
$('input[name="agent_id"]').focus();
repeat_flag = false;
return false;
}
// Secret格式验证
if(secret.length < 10) {
layer.msg('Secret格式不正确长度至少10位字符', {icon: 2});
$('input[name="secret"]').focus();
repeat_flag = false;
return false;
}
// 客服ID格式验证
if(!/^kfc_[a-zA-Z0-9]+$/.test(contactId)) {
layer.msg('客服ID格式不正确应以kfc_开头', {icon: 2});
$('input[name="contact_id"]').focus();
repeat_flag = false;
return false;
}
// 活码链接格式验证
if(!/^https:\/\/work\.weixin\.qq\.com\/kf\//.test(contactUrl)) {
layer.msg('活码链接格式不正确,应为 https://work.weixin.qq.com/kf/... 格式', {icon: 2});
$('input[name="contact_url"]').focus();
repeat_flag = false;
return false;
}
// 继续执行原有的AJAX提交逻辑
if (repeat_flag) return false; if (repeat_flag) return false;
repeat_flag = true; repeat_flag = true;
@@ -115,7 +462,11 @@
type: 'POST', type: 'POST',
success: function(res){ success: function(res){
if(res.code == 0){ if(res.code == 0){
layer.msg(res.message, {icon: 1}); layer.msg('企业微信配置保存成功!系统已自动生成签名和时间戳', {icon: 1});
// 刷新页面以显示更新后的状态
setTimeout(function() {
window.location.reload();
}, 1500);
}else{ }else{
layer.msg(res.message, {icon: 2}); layer.msg(res.message, {icon: 2});
} }
@@ -126,21 +477,38 @@
repeat_flag = false; repeat_flag = false;
} }
}); });
return false; // 阻止默认提交
});
}); });
// 启用状态切换时的提示 // 切换密码显示/隐藏
$('input[name="enabled"]').on('change', function() { function togglePassword() {
if($(this).is(':checked')) { var secretInput = $('#secret-input');
// 可以在这里添加启用时的验证提示 var toggleBtn = $('.password-toggle');
var corpId = $('input[name="corp_id"]').val();
var agentId = $('input[name="agent_id"]').val();
if(!corpId || !agentId) { if (secretInput.attr('type') === 'password') {
layer.msg('请先填写企业ID和应用ID', {icon: 2}); secretInput.attr('type', 'text');
$(this).prop('checked', false); toggleBtn.text('🙈');
form.render(); } else {
secretInput.attr('type', 'password');
toggleBtn.text('👁️');
}
}
// 切换指南显示/隐藏
function toggleGuide() {
var btn = $('.guide-toggle-btn');
var content = $('.guide-content');
var icon = $('.guide-toggle-icon');
if (content.hasClass('show')) {
content.removeClass('show');
btn.removeClass('active');
icon.removeClass('rotate');
} else {
content.addClass('show');
btn.addClass('active');
icon.addClass('rotate');
} }
} }
});
});
</script> </script>