<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>sc_wechat</title>
<script type="text/javascript" src="<c:url value='/scripts/lib/jquery-1.8.2.min.js'/>"></script>
<style type="text/css">
	div{
		margin-bottom:10px; 
		background-color:#F8F8F8;
		border:1px solid #CCC;
		padding-top:10px;
		padding-top:10px;
	}
	.i_btn{
		width:140px;
		height:35px;
		background:#ebf2fa;
		border:0;
		font-size:15px;
		cursor: pointer;
	}
	textarea{
		border:1px solid #d6dfe4;
	}
</style>

<script type="text/javascript">
	$(function(){
		var contextPath=$("#contextPath").val();
		
		$("#i_createmenu").bind("click",function(){
			doMenu(contextPath,"1");
		});
		$("#i_getmenu").bind("click",function(){
			doMenu(contextPath,"2");
		});
		$("#i_delemenu").bind("click",function(){
			doMenu(contextPath,"3");
		});
		$("#i_subscribe").bind("click",function(){
			subscribe(contextPath);
		});
		$("#i_unsubscribe").bind("click",function(){
			unsubscribe(contextPath);
		});
		
		$("#E1001_1002").bind("click",function(){
			E1001_1002(contextPath);
		});
		
		$("#i_textbtn").bind("click",function(){
			doText(contextPath);
		});
		
	});
	
	function doMenu(contextPath,actType){
		var developId=$("#developId").val();
		var json=$("#t_menu").val();
		if(actType=="1"&&$.trim(json)==""){
			alert("请录入自定义菜单数据");
			return;
		}
		$.ajax({
			url:contextPath+"/wechat/api/executeMenu?developId="+developId,
			type:"POST",
			data:{actType:actType,json:json},
			success:function(response){
				if(actType=="1"&&response=="true"){
					alert("菜单创建成功.");
				}
				else if(actType=="2"){
					$("#t_menu").val(response);
				}
				else if(actType=="3"&&response=="true"){
					alert("菜单删除成功.");
				}
				else{
					alert("执行失败.");
				}
			},
			error:function(response){
				alert("执行失败.");
			}
		});				
	}
	
	function subscribe(contextPath){
		var developId=$("#developId").val();
		$.ajax({
			url:contextPath+"/wechat/api/subscribe?developId="+developId,
			type:"POST",
			success:function(response){
				$("#t_test_content").val(response);
			},
			error:function(response){
				alert("执行失败.");
			}
		});				
	}
	
	function unsubscribe(contextPath){
		var developId=$("#developId").val();
		$.ajax({
			url:contextPath+"/wechat/api/unsubscribe?developId="+developId,
			type:"POST",
			success:function(response){
				$("#t_test_content").val(response);
			},
			error:function(response){
				alert("执行失败.");
			}
		});				
	}
	
	function E1001_1002(contextPath){
		var developId=$("#developId").val();
		$.ajax({
			url:contextPath+"/wechat/api/E1001_1002?developId="+developId,
			type:"POST",
			success:function(response){
				$("#t_test_content").val(response);
			},
			error:function(response){
				alert("执行失败.");
			}
		});				
	}
	
	function doText(contextPath){
		var textXml=$("#t_testbtn_content").val();
		$.ajax({
			url:contextPath+"/wechat/api/doText",
			type:"POST",
			data:{textXml:textXml},
			success:function(response){
				$("#t_testbtn_content").val(response);
			},
			error:function(response){
				alert("执行失败.");
			}
		});	
	}
	
</script>
</head>
<body>
	<input type="hidden" id="contextPath" value="${ctx}">
	<p align="center">SC 测试</p>
	
	<strong>请选择开发者id，即订阅号或者服务号</strong><br/>
	<div>
		<select id="developId">
			<option value="gh_1b0d75ca6668">gh_1b0d75ca6668 掌巢服务号（用户端）</option>
			<option value="gh_ac9ad9e9bdf5">gh_ac9ad9e9bdf5 宅点点服务号（员工端）</option>
			<option value="gh_39dc35e93ae6">gh_39dc35e93ae6超级前台管家公众号（员工端）</option>
		</select>
	</div>
	
	<strong>菜单处理</strong><br/>
	<div>
		<textarea rows="24" cols="80" id="t_menu">
		</textarea>
		<input type="button" id="i_createmenu" class="i_btn" value="创建菜单">
		<input type="button" id="i_getmenu"  class="i_btn" value="查询菜单">
		<input type="button" id="i_delemenu" class="i_btn" value="删除菜单">
	</div>
	
	<strong>事件测试</strong><br/>
	<div>
		<textarea rows="4" cols="80" id="t_test_content"></textarea>
		<input type="button" id="i_subscribe" class="i_btn" value="关注公众号">
		<input type="button" id="i_unsubscribe" class="i_btn" value="取消公众号">
		<input type="button" id="E1001_1002" class="i_btn" value="我的工单（员工）">
	</div>
	
	<strong>文本测试</strong><br/>
	<div>
		<textarea rows="10" cols="80" id="t_testbtn_content">
			<xml><ToUserName><![CDATA[gh_12f9e7c81af4]]></ToUserName>
	<FromUserName><![CDATA[o3jlSweaWF6USY_Sab0RG8lQfWfU]]></FromUserName>
	<CreateTime>1472269549</CreateTime>
	<MsgType><![CDATA[text]]></MsgType>
	<Content><![CDATA[新生]]></Content>
	<MsgId>6323349564368351047</MsgId>
	</xml>
		</textarea>
		<input type="button" id="i_textbtn" class="i_btn" value="测试">
	</div>
</body>
</html>