<?php
	$this->display(tpl('head',true));
	$is_login[$settingDB['is_login']]='checked';
	$is_attention_reg[$settingDB['is_attention_reg']]='checked';
	$type[$settingDB['type']]='checked';
?>
<style>
	.layui-form-label {
	    float: left;
	    display: block;
	    padding: 9px 15px;
	    width: 10%;
	    font-weight: 400;
	    text-align: right;
	}
	.layui-input, .layui-textarea {
	    display:  inline;
	    width: 80%;
	    padding-left: 10px;
	}
</style>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
	  	<legend>微信核心设置</legend>
	</fieldset>
	<form class="layui-form" method="post">
		<div class="layui-form-item">
			<label class="layui-form-label">AppID（应用ID）</label>
			<div class="layui-input-block">
				<input name="wechat[appid]" value="<?php echo $settingDB['appid'] ?>" class="layui-input my-input" type="text">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">AppSecret（应用密钥）</label>
			<div class="layui-input-block">
				<input name="wechat[appsecret]" value="<?php echo $settingDB['appsecret'] ?>" class="layui-input my-input" type="text">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">公众号接口Token:</label>
			<div class="layui-input-block">
				<input name="wechat[token]" value="<?php echo $settingDB['token'] ?>" class="layui-input my-input" type="text">[<a href="https://mp.weixin.qq.com/cgi-bin/readtemplate?t=register/step1_tmpl&lang=zh_CN" target="_blank">申请</a>]
				<p style="color: #aaa;">必须要先申请到微信公众帐号才可以在你的网站使用微信相关功能，这个值是由任意多个数字+字母的组合，越复杂越好，必须要与微信公众平台保持一致，<a href="https://mp.weixin.qq.com/" target="_blank">点击登录微信公众平台</a></p>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">公众号类型</label>
			<div class="layui-input-block">
				<input name="wechat[type]" value="0" <?php echo $type[0] ?> title="没有公众号，不对接绑定" type="radio">
				<input name="wechat[type]" value="1" <?php echo $type[1] ?> title="认证服务号" type="radio">
				<input name="wechat[type]" value="2" <?php echo $type[2] ?> title="非认证服务号" type="radio">
				<input name="wechat[type]" value="3" <?php echo $type[3] ?> title="认证订阅号" type="radio">
				<input name="wechat[type]" value="4" <?php echo $type[4] ?> title="非认证订阅号" type="radio">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">启用微信登录</label>
			<div class="layui-input-block">
				<input name="wechat[is_login]" value="0" <?php echo $is_login[0] ?> title="不启用" type="radio">
				<input name="wechat[is_login]" value="1" <?php echo $is_login[1] ?> title="启用" type="radio">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">关注微信公众号时，直接注册</label>
			<div class="layui-input-block">
				<input name="wechat[is_attention_reg]" value="0" <?php echo $is_attention_reg[0] ?> title="关注时，不注册" type="radio">
				<input name="wechat[is_attention_reg]" value="1" <?php echo $is_attention_reg[1] ?> title="关注时直接注册会员" type="radio">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">微信注册后所属会员组</label>
			<div class="layui-input-block">
				<select name="wechat[reg_groupid]">
						<option  value="">请选择一个会员组</option>
						<?php foreach(C('USER_GROUP') AS $gid =>$row) { 
							$selected='';
							if($gid == $settingDB['reg_groupid']){$selected='selected';}
						?>
						<option <?php echo $selected ?>  value="<?php echo $gid ?>"><?php echo $row[name] ?></option>
						<?php } ?>
					</select>
			</div>
		</div>
		<blockquote class="layui-elem-quote layui-text">上面4项，不能留空，没有公众号就选择第一项，请在<a href="https://mp.weixin.qq.com/" target="_blank">微信公众平台（开发者中心）查阅</a>
	  </blockquote>
		<div class="layui-form-item">
			<div class="layui-input-block my_button">
				<input type="hidden" name="step" id="step" value="post" />
				<button class="layui-btn">立即设置</button>
			</div>
		</div>
		
	</form>
<script>

layui.config({
	version: '<?php echo NOWTIME ?>'
});
layui.use(['form','upload'], function(){
  	var $ = layui.jquery;
	var form = layui.form;
	var upload = layui.upload;
  	upload.render({
	    elem: '#up_apiclient_cert'
	    ,url: '/admin/index/plugin/<?php echo P_MODULE ?>/index/up/name_apiclient+++cert/'
	    ,accept:'file'
	    ,exts:'pem'
	    ,done: function(res){
	    	if(res.Result==1){
	    		$('#apiclient_cert').val(res.file);
	    	}
	      	return layer.msg(res.content);
	      //上传成功
	    }
    });
    upload.render({
	    elem: '#up_apiclient_key'
	    ,url: '/admin/index/plugin/<?php echo P_MODULE ?>/index/up/name_apiclient+++key/'
	    ,accept:'file'
	    ,exts:'pem'
	    ,done: function(res){
	    	if(res.Result==1){
	    		$('#apiclient_key').val(res.file);
	    	}
	      	return layer.msg(res.content);
	      //上传成功
	    }
    });
    upload.render({
	    elem: '#up_rootca'
	    ,url: '/admin/index/plugin/<?php echo P_MODULE ?>/index/up/name_rootca/'
	    ,accept:'file'
	    ,exts:'pem'
	    ,done: function(res){
	    	if(res.code==0){
	    		$('#rootca').val(res.file);
	    	}
	      	return layer.msg(res.text);
	      //上传成功
	    }
    });
});

</script>
<?php
	$this->display(tpl('foot',true));
?>
