<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<title>{echo admin_title()}</title>
<!--header-->
{template _:header}
</head>
<body>
<div class="layui-layout layui-layout-admin">
<!--top-->
{template _main_top}
<!--nav-->
{template _main_nav}
	<div class="position"><h1>微信配置</h1></div>
	<div class="layui-body admin-body">
		<div class="admin-content">
			<div class="layui-tab layui-tab-brief" style="margin-top:-5px;">
				<ul class="layui-tab-title layui-tab-links">
					<li class="<!--{if request()->action() == 'index'}-->layui-this<!--{/if}-->"><a href="{echo url('weixin/index')}">公众号授权</a></li>
					<li class="<!--{if request()->action() == 'card'}-->layui-this<!--{/if}-->"><a href="{echo url('weixin/card')}">微信会员卡</a></li>
				</ul>
			</div>
			<blockquote class="layui-elem-quote layui-top-margin">服务器地址(URL)：{echo url('/wx/' . $this->merchant['merchant_no'], null, null, true)}</blockquote>
			<div class="opwindow">
				<form name="theform" id="theform" method="post" action="{echo \befen\get_url()}">
				<table class="layui-table">
					<tbody>
						<tr style="display:none;">
							<td class="td1">AppID</td>
							<td class="td2"><input type="text" name="authorizer_appid" id="authorizer_appid" class="layui-input" value="{$value[authorizer_appid]}" /></td>
						</tr>
						<tr style="display:none;">
							<td class="td1">授权令牌</td>
							<td class="td2"><input type="text" name="authorizer_access_token" id="authorizer_access_token" class="layui-input" value="{$value[authorizer_access_token]}" /></td>
						</tr>
						<tr style="display:none;">
							<td class="td1">&nbsp;</td>
							<td class="td2">
								<!--{if empty($value['authorizer_appid'])}-->
								<button type="button" class="layui-btn layui-btn-primary" id="app_auth">绑定公众号</button>
								<!--{else}-->
								<button type="button" class="layui-btn layui-btn-primary" id="app_auth">重新绑定公众号</button>
								<!--{/if}-->
							</td>
						</tr>
							<td class="td1">令牌(Token)</td>
							<td class="td2"><input type="text" name="token" id="token" class="layui-input" value="{$value[token]}" /></td>
						</tr>
						<tr>
							<td class="td1">开发者ID(AppID)</td>
							<td class="td2"><input type="text" name="appid" id="appid" class="layui-input" value="{$value[appid]}" /></td>
						</tr>
						<tr>
							<td class="td1">开发者密码(AppSecret)</td>
							<td class="td2"><input type="text" name="appsecret" id="appsecret" class="layui-input" value="{$value[appsecret]}" /></td>
						</tr>
						<tr>
							<td class="td1">公众号密钥(EncodingAESKey)</td>
							<td class="td2"><input type="text" name="encodingaeskey" id="encodingaeskey" class="layui-input" value="{$value[encodingaeskey]}" /></td>
						</tr>
						<tr>
							<td class="td1">&nbsp;</td>
							<td class="td2">
								<button type="submit" name="submit" value="submit" id="submit" class="layui-btn">提交</button>
							</td>
						</tr>
					</tbody>
				</table>
				</form>
			</div>
		</div>
	</div>
</div>
<!--footer-->
{template _:footer}
<script type="text/javascript">
$("#submit").click(function(){
	ajaxSubmit(this, "", "#theform");
});
var the_url = "{echo url('/wechat/wx_open/app_auth', ['merchant_id' => '__authid__', 'merchant_return' => \befen\get_url(true)], null, true)}";
$("#app_auth").click(function(){
	$.ajax({
		type: "POST",
		dataType: "json",
		timeout: 10000,
		url: "{echo url('index/get_id_authcode')}",
		data: {
			ajax: "json",
			expires: 300,
		},
		success: function(data){
			gotourl(the_url.replace("__authid__", data.contents.merchant_id));
		},
		error: function(xhr, status){
			console.log(status);
			console.log(xhr);
		},
		complete: function(){
			hideLoader();
		},
		beforeSend: function(){
			showLoader();
		}
	});
});
</script>
</body>
</html>