<?php
require '../conn/conn.php';
require '../conn/function.php';
require '../conn/sendmail.php';
require 'admin_check.php';

$action=$_GET["action"];

if($action=="testemail"){
    $info=sendmail("发卡宝测试邮件", "如果您收到了此封邮件，说明您的邮箱接口配合正确！", $C_recieve);
    die("{\"msg\":\"$info\",\"recieve\":\"$C_recieve\"}");
}
if($action=="save"){
    $C_email=t($_POST["C_email"]);
    $C_smtp=t($_POST["C_smtp"]);
    $C_emailpwd=t(trim($_POST["C_emailpwd"]));
    $C_recieve=t($_POST["C_recieve"]);
    $C_userid=t($_POST["C_userid"]);
    $C_sms=t($_POST["C_sms"]);
    $C_smssign=t($_POST["C_smssign"]);
    $C_smspwd=t(trim($_POST["C_smspwd"]));

    $C_pid=t(trim($_POST["C_pid"]));
    $C_pkey=t(trim($_POST["C_pkey"]));
    $C_payurl=t(trim($_POST["C_payurl"]));
    
    $C_alipayon=intval($_POST["C_alipayon"]);
    $C_wxpayon=intval($_POST["C_wxpayon"]);

    if($C_email==""){
        die("请填全信息");
    }else{
        sql("update sl_config set 
        C_email='$C_email',
        C_smtp='$C_smtp',
        C_recieve='$C_recieve',
        C_userid='$C_userid',
        C_sms='$C_sms',
        C_smssign='$C_smssign'");

        if($C_smspwd!=""){
          sql("update sl_config set C_smspwd='$C_smspwd'");
        }
        if($C_emailpwd!=""){
          sql("update sl_config set C_emailpwd='$C_emailpwd'");
        }
        die("success");
  }
}

if($C_userid=="" || $C_sms=="" || $C_smspwd==""){
  $sms_rest="<font color='#ff0000'>未知</font>";
}else{
  $info=GetBody("http://115.159.161.192:18005/balance.do?uid=".$C_userid."&pw=".$C_smspwd,"");
  if($info>0){
    $sms_rest=$info;
  }else{
    $sms_rest="<font color='#ff0000'>".$info."</font>";
  }
}

?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>接口设置 - 后台管理</title>
<link rel="shortcut icon" href="../media/<?php echo $C_ico?>" />
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/materialdesignicons.min.css" rel="stylesheet">
<link href="../css/style.min.css" rel="stylesheet">
<script type="text/javascript" src="../upload/upload.js"></script>
<style type="text/css">
.qrcode{width:200px;height:200px}
</style>
</head>
  
<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
  <?php require 'nav.php';?>
    <main class="lyear-layout-content">
      <div class="container-fluid">
        <div class="row">
            
        <form id="form">

          <div class="col-md-6">
            <div class="card">
              <div class="card-header"><h4>邮箱接口</h4></div>
              <div class="card-body">
                <div class="row">
                  
                  <div class="form-group row">
                    <label class="col-md-2" for="example-email-input">收件邮箱</label>
                    <div class="col-md-10">
                      <input class="form-control" type="text" name="C_recieve" value="<?php echo $C_recieve?>">
                    </div>
                  </div>

                  <div class="form-group row">
                    <label class="col-md-2" for="example-email-input">发件邮箱</label>
                    <div class="col-md-10">
                      <input class="form-control" type="text" name="C_email" value="<?php echo $C_email?>">
                    </div>
                  </div>
                        
                  <div class="form-group row">
                    <label class="col-md-2" for="example-email-input">发件smtp</label>
                    <div class="col-md-10">
                      <input class="form-control" type="text" name="C_smtp" value="<?php echo $C_smtp?>">
                    </div>
                  </div>

                  <div class="form-group row">
                    <label class="col-md-2" for="example-email-input">邮箱授权码</label>
                    <div class="col-md-10">
                      <input class="form-control" type="text" name="C_emailpwd" value="" placeholder="已加密保存，留空则不修改">
                    </div>
                  </div>

                  <div class="form-group row">
                    <label class="col-md-2" for="example-email-input">
                      <button class="btn btn-info btn-sm" onclick="api_testemail()" type="button">测试邮件</button>
                    </label>
                    <div class="col-md-10">
                      <div style="font-size: 12px;margin-top: 10px;color: #33cabb">如果您不知道如何填写，请点击 <a href="https://www.7-card.cn/newsinfo.html?id=2" class="btn btn-xs btn-success" target="_blank">帮助文档</a></div>
                    </div>
                  </div>

                    </div>
                  </div>

                </div>
          </div>

              <div class="col-md-6">

                <div class="card">
              <div class="card-header"><h4>短信接口</h4></div>
              <div class="card-body">
                <div class="row">
                  
                  <div class="form-group row">
                    <label class="col-md-2" for="example-email-input">短信签名</label>
                    <div class="col-md-10">
                      <input class="form-control" type="text" name="C_smssign" value="<?php echo $C_smssign?>">
                    </div>
                  </div>

                  <div class="form-group row">
                    <label class="col-md-2" for="example-email-input">企业ID</label>
                    <div class="col-md-10">
                      <input class="form-control" type="text" name="C_userid" value="<?php echo $C_userid?>">
                    </div>
                  </div>
                        
                  <div class="form-group row">
                    <label class="col-md-2" for="example-email-input">账号</label>
                    <div class="col-md-10">
                      <input class="form-control" type="text" name="C_sms" value="<?php echo $C_sms?>">
                    </div>
                  </div>

                  <div class="form-group row">
                    <label class="col-md-2" for="example-email-input">密码</label>
                    <div class="col-md-10">
                      <input class="form-control" type="text" name="C_smspwd" value="" placeholder="已加密保存，留空则不修改">
                    </div>
                  </div>

                  <div class="form-group row">
                    <label class="col-md-2" for="example-email-input">
                      <!--<button class="btn btn-info btn-sm" onclick="api_testsms()" type="button">测试短信</button>-->
                    </label>
                    <div class="col-md-10">
                      <div style="font-size: 12px;margin-top: 10px;color: #33cabb">短信余额：<?php echo $sms_rest;?> <a href="https://www.51faka.vip/shop/?id=675" class="btn btn-xs btn-success" target="_blank">购买短信包</a></div>
                    </div>
                  </div>

                    </div>
                  </div>

                </div>

              </div>

                    <div class="col-md-12">
                      <button class="btn btn-primary" type="button" onclick="api_save()">保存</button>
                      说明：邮件及短信可用于发货使用。
                    </div>



            </div>

          </div>
          </form>
        </div>
      </div>
    </main>
  </div>
</div>

<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="../js/main.min.js"></script>
<script src="../js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="../js/lightyear.js"></script>
<script src="../js/jqPaginator.min.js" type="text/javascript"></script>
<script src="../js/help.js" type="text/javascript"></script>
<script src="../js/jconfirm/jquery-confirm.min.js"></script>
<script src="../js/admin.js"></script>
</body>
</html>