<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
$weixin_cert_dir = ROOTPATH.'api/pay/weixin/cert/';
$weixin_cert_default = $weixin_cert_dir.'apiclient_cert.pem';
$weixin_key_default = $weixin_cert_dir.'apiclient_key.pem';
?>
<div class="form-group">
    <label class="col-md-2 control-label">AppId</label>
    <div class="col-md-9">
        <input type="text" class="form-control input-large" name="data[<?php echo $dir;?>][appid]" value="<?php echo $data[$dir]['appid']?>" >
    </div>
</div>
<div class="form-group">
    <label class="col-md-2 control-label">AppSecret</label>
    <div class="col-md-9">
        <input type="text" class="form-control input-large" name="data[<?php echo $dir;?>][appsecret]" value="<?php echo $data[$dir]['appsecret']?>" >
    </div>
</div>
<div class="form-group">
    <label class="col-md-2 control-label">MCHID</label>
    <div class="col-md-9">
        <input type="text" class="form-control input-large" name="data[<?php echo $dir;?>][mchid]" value="<?php echo $data[$dir]['mchid']?>" >
    </div>
</div>
<div class="form-group">
    <label class="col-md-2 control-label">KEY</label>
    <div class="col-md-9">
        <input type="text" class="form-control input-large" name="data[<?php echo $dir;?>][key]" value="<?php echo $data[$dir]['key']?>" >
    </div>
</div>
<div class="form-group">
    <label class="col-md-2 control-label"><?php echo dr_lang('退款API证书'); ?></label>
    <div class="col-md-9">
        <div class="alert alert-warning" style="margin-bottom:10px;">
            <p><?php echo dr_lang('微信退款必须配置商户 API 证书，否则无法退款。'); ?></p>
            <p><?php echo dr_lang('请在微信商户平台下载证书，将以下文件放到默认目录：'); ?></p>
            <p><code><?php echo $weixin_cert_default; ?></code></p>
            <p><code><?php echo $weixin_key_default; ?></code></p>
            <p class="margin-top-10"><?php echo dr_lang('也可在下方填写自定义绝对路径（留空则使用默认路径）。'); ?></p>
        </div>
        <p>
            <input type="text" class="form-control" name="data[<?php echo $dir;?>][sslcert_path]" id="dr_weixin_sslcert_path" value="<?php echo isset($data[$dir]['sslcert_path']) ? htmlspecialchars($data[$dir]['sslcert_path']) : '';?>" placeholder="<?php echo htmlspecialchars($weixin_cert_default); ?>">
            <span class="help-block"><?php echo dr_lang('证书文件 apiclient_cert.pem 路径'); ?></span>
        </p>
        <p>
            <input type="text" class="form-control" name="data[<?php echo $dir;?>][sslkey_path]" id="dr_weixin_sslkey_path" value="<?php echo isset($data[$dir]['sslkey_path']) ? htmlspecialchars($data[$dir]['sslkey_path']) : '';?>" placeholder="<?php echo htmlspecialchars($weixin_key_default); ?>">
            <span class="help-block"><?php echo dr_lang('密钥文件 apiclient_key.pem 路径'); ?></span>
        </p>
        <p>
            <button type="button" class="btn blue btn-sm" onclick="dr_weixin_check_cert()">
                <i class="fa fa-check-circle"></i> <?php echo dr_lang('检测证书'); ?>
            </button>
            <span class="help-block"><?php echo dr_lang('检测证书文件是否存在、可读，以及 PEM 格式是否可用'); ?></span>
        </p>
    </div>
</div>
<script type="text/javascript">
function dr_weixin_check_cert() {
    var cert = $('#dr_weixin_sslcert_path').val() || '';
    var key = $('#dr_weixin_sslkey_path').val() || '';
    var url = '<?php echo dr_url('pay/payapi/check_cert'); ?>';
    url += '&sslcert_path=' + encodeURIComponent(cert);
    url += '&sslkey_path=' + encodeURIComponent(key);
    dr_ajax_url(url);
}
</script>
