<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="true" Inherits="Kesion.NET.WebSite.Admin.Yun.AccountAPI" CodeBehind="KS.YunAccountApi.aspx.cs" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="System.Data" %>
<asp:Content ID="Content1" ContentPlaceHolderID="KSContent" runat="server">
   <div class="clear blank20"></div>
   <div class="content-area"> 
        <script>
            $(function () {
                $("#AccountBtn").find("a").click(function () {
                    $("#AccountBtn").find("a").removeClass("button_on");
                    $(this).addClass("button_on");
                    var n = $("#AccountBtn a").index(this);
                    if (n == 0) {
                     $("#RegBox").hide();
                     $("#BindBox").show();
                } else {
                    $("#RegBox").show();
                     $("#BindBox").hide();
                }
                })
            })
           
            function DoReg() {
                var schoolName = $("#SchoolName").val();
                var email = $("#Email").val();
                var mobile = $("#Mobile").val();
                var MobileCode = $("#MobileCode").val();
                var PassWord = $("#PassWord").val();

                if (schoolName == '') {
                     KesionJS.Alert('请输入机构名称！', "$('#SchoolName').focus()");
	                 return false;
                }
                if (email == '') {
                     KesionJS.Alert('请输入邮箱！', "$('#Email').focus()");
	                 return false;
                }
                if (mobile == '') {
                     KesionJS.Alert('请输入手机号码！', "$('#Mobile').focus()");
	                 return false;
                }
                if (MobileCode == '') {
                     KesionJS.Alert('请输入短信验证码！', "$('#MobileCode').focus()");
	                 return false;
                }
                if (PassWord == '') {
                     KesionJS.Alert('请输入登录密码！', "$('#PassWord').focus()");
	                 return false;
                }
                $("#Action").val("doreg");
            }
            function DoBind() {
                var userName = $("#BindUserName").val();
                var passWord = $("#BindPassword").val();
                if (userName == '') {
                     KesionJS.Alert('请输入云市场账号！', "$('#BindUserName').focus()");
	                 return false;
                }
                 if (passWord == '') {
                     KesionJS.Alert('请输入云市场登录密码！', "$('#BindPassword').focus()");
	                 return false;
                  }
                $("#Action").val("dobind");
            }
            function ismobile(s)
            {
                var p = /^(013|014|015|017|018|13|14|15|17|18|19)\d{9}$/;
               if(s.match(p) != null){
              return true;
              }
              return false;
            }
            var OutTimes = 60;
            var tOutTimes=OutTimes;
            function leavePage() {
		             if (tOutTimes==0){
		             tOutTimes=OutTimes;
		             $("#SendMobileBtn").attr("disabled",false);
		             $("#SendMobileBtn").val("免费获取手机验证码")
		             }
		             else{
		             tOutTimes -= 1;
		             $("#SendMobileBtn").val("已发，"+tOutTimes+"秒后可重发!")
		             setTimeout("leavePage()", 1000);}
            }
            function getMobileCode(){
	            var mobile=$("#Mobile").val();
	            var fieldName="Mobile";
	            if (mobile==''){
	              $.dialog.alert('请选输入手机号码！',function(){ $("#"+fieldName).focus();});
	               return false;
	            }
	            if (ismobile(mobile)==false){
	              $.dialog.alert('手机号码格式不正确，请重新输入！',function(){ $("#"+fieldName).focus();});
	              return false;
                }
                $("#SendMobileBtn").attr("disabled", true);
                $.ajax({
                    type: "get",
                    url: "KS.YunAccountApi.aspx", 
                    data: "model=userreg&action=sendsmscode&mobile="+mobile, 
                    success: function (data) {
                         if (data == 'true') {
			                    leavePage();
		                     }else{
			                     $.dialog.alert(data,function(){$("#SendMobileBtn").attr("disabled",false); });
		                     }
                    }
                });
	            return false;
            }
            //验证域名
            function VerifyDomain() {
                var domain = $("#Domain").val();
                if (domain == '') {
                     $.dialog.alert('请输入本站的域名！',function(){ $("#Domain").focus();});
	              return false;
                }
                 $("#aspnetForm").attr("action","KS.YunAccountApi.aspx?action=doverifydomain").submit();
            }
            //发起充值
            function DoPay() {
                var Money = parseFloat($("#Money").val());
                if (Money <= 0) {
                     $.dialog.alert('充值金额必须大于0！',function(){ $("#Money").focus();});
	              return false;
                }

                $.ajax({
                    type: "get",
                    url: "KS.YunAccountApi.aspx", 
                    data: "action=dopay&money="+Money, 
                    success: function (data) {
                        if (data.indexOf('ok') != -1) {
                            var url = data.split('|')[1];
                            $("#payBox").html("<span style='color:brown'>温馨提示：正在跳转到第三方支付页面，支付成功，请返回刷新此页面！</span>");
                            $("#aspnetForm").attr("action", url).attr("target", "_blank").submit();
                        } else {
                            $.dialog.alert(data, function () { });

                        }
                    }
                });
                 return false;
            }
        </script>

   		<div class="myTitle">我的云状态</div>
       <%if (dr == null)
         { %>
         <input type="hidden" name="Action" id="Action" value="" />
		<!--未绑定-->
        <table class="yun-bindBox">
        	<tr>
                <td class="yun-bindTit" width="200" align="center">科汛云状态：<font class="redFont">未绑定</font></td>
                <td class="yun-btndBox" id="AccountBtn">
                    <a href="javascript:;" title="点击绑定账号" class="button button_on">绑定账号</a>
                    <a href="javascript:;" title="点击注册账号" class="button">注册账号</a>
                </td>
            </tr>
        </table>
        
        <!--绑定账号-->
        <table id="BindBox" class="yun-bindBox yun-bindBox2" style="display:none;">
        	
            <tr>
                <td class="yun-bindTit" width="120" align="right">科汛云账号：</td>
                <td>
                    <input name="BindUserName" id="BindUserName" type="text" style="width:300px">
                </td>
            </tr>
            <tr>
                <td class="yun-bindTit" width="120" align="right">科汛云密码：</td>
                <td>
                    <input name="BindPassword" id="BindPassword" type="password" style="width:300px">
                </td>
            </tr>
            <tr>
                <td class="yun-bindTit" width="120" align="right"> </td>
                <td class="yun-btndBox">
                    <input type="submit" title="点击绑定账号" class="button button_on" value="绑定账号" onclick="return(DoBind())"/>
                    <br /><br />
                    <div class="tips">温馨提示：如果您已有yun.kesion.com账号，可以在此直接绑定。</div>
                </td>
            </tr>
         </table>
         
         <!--注册云账号-->
         <table id="RegBox" class="yun-bindBox yun-bindBox3" style="display:none;">
        	<tr>
                <td class="yun-bindTit" width="120" align="right">机构名称：</td>
                <td>
                    <input name="SchoolName" id="SchoolName" type="text" style="width:300px">
                </td>
            </tr>
            <tr>
                <td class="yun-bindTit" width="120" align="right">电子邮箱：</td>
                <td>
                    <input name="Email" id="Email" type="text" style="width:300px">
                </td>
            </tr>
            <tr>
                <td class="yun-bindTit" width="120" align="right">手机号：</td>
                <td>
                    <input name="Mobile" id="Mobile" type="text" style="width:300px">
                </td>
            </tr>
            <tr>
                <td class="yun-bindTit" width="120" align="right">验证码：</td>
                <td class="V-Code">
                    <input name="MobileCode" id="MobileCode" type="text" style="width:150px;" maxlength="6">
                    <input type="button" value="获取手机验证码" class="button button_on" id="SendMobileBtn" onclick="getMobileCode();"/>
                </td>
            </tr>
            <tr>
                <td class="yun-bindTit" width="120" align="right">设置密码：</td>
                <td>
                    <input name="PassWord" id="PassWord" type="password" style="width:300px">
                </td>
            </tr>
            <tr>
                <td class="yun-bindTit" width="120" align="right"> </td>
                <td class="yun-btndBox">
                    <input type="submit" title="点击确定提交" class="button button_on" onclick="return(DoReg())" value="确定提交" />
                    <a href="" title="点击取消返回" class="button">取消返回</a>
                </td>
            </tr>
         </table>
         
        <%}
    else
    { %>
         <!--开通科汛云-->
         <div class="yun-openBox clearfix">
         	<div class="fl yun-open-info">
            	<h3>开发者信息</h3>
                <ul>
                    <%if (IsVerify==false)
                        {
                            Response.Write("<li>云账号名称："+dr["mobile"].ToString()+"</li>");
                            Response.Write(@"<li>云账号状态：<span style='color:red'>审核中...</span>(<a href='?action=rebind' onclick=""confirm('确认重新绑定吗？');"">重新绑定</a>)</li>");
                        }
                        else
                        {%>
                	<li>云账号机构名称：<%=dr["schoolname"].ToString() %> <asp:Label ID="LabVipInfo" runat="server"></asp:Label></li>
                	<li>云账号名称：<%=dr["mobile"].ToString() %></li>
                    <li>科汛云APPID：<%=dr["appid"].ToString() %></li>
                    <li>科汛云APPKey：<%=dr["AppKey"].ToString().Substring(0, 10) %>************<%=dr["AppKey"].ToString().Substring(dr["AppKey"].ToString().Length - 10, 10)%></li>
                    <li>访问token：
                        <%if (dr["token"].ToString().Length > 10)
                    { %>
                                        <%=dr["token"].ToString().Substring(0, 10) %>************<%=dr["token"].ToString().Substring(dr["token"].ToString().Length - 10, 10)%>
                                        <%}
                    else
                    { %> 未获得   
                                        <%} %>(<a href="?action=refreshToken">点此刷新token</a>)
                                    </li>
                                    <li>科汛云验证域名：<%if (string.IsNullOrEmpty(dr["domain"].ToString()))
                    {
                        Response.Write(@"<a href='javascript:;' onclick='$(""#domainBind"").toggle()'><span style='color:red'>未对接,点此对接</span></a>");
                    }
                    else
                    {
                        Response.Write(dr["domain"].ToString());
                    }%></li>
                </ul>
                 <div id="domainBind" style="display:none">
                     <input type="text" name="Domain" id="Domain" value="<%=MyCache.GetCacheConfig(5) %>"  style="width:250px;"/> <input onclick="VerifyDomain()" type="button" value="验证绑定" class="button" />
                 </div>
                <a href="?action=unbind" onclick="return(confirm('确认取消绑定吗？'))" class="greenFont moreBox">→取消绑定</a>
                 <%} %>
            </div>
             <%if (IsVerify)
                 { %>
            <div class="fl yun-open-account">
            	<div class="fl balance">
                	<h3>云账户余额</h3>
                    <p class="account-data">
                    	<span class="redFont"><asp:Label ID="LabMoney" runat="server"></asp:Label></span>元
                    </p>
                   
                     <!--在线充值-->
                    <div id="payBox">
                     充值金额：<input name="Money" id="Money" onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')" value="100" type="text" style="width:60px;text-align:center; margin-bottom:10px;"> 元&nbsp;&nbsp;
                    <input type="button" title="点击确定提交" id="paybtn" class="button button_on"  value="确定充值" onclick="DoPay()" />
                    </div>
                </div>
                <div class="fl integral">
                	<h3>云账户积分</h3>
                    <p class="account-data">
                    	<span class="orangeFont"><asp:Label ID="LabPoint" runat="server"></asp:Label></span>积分
                    </p>
                </div>
                <div style="clear:both"></div>
                 <div class="message">
                        温馨提示：本账户余额可用于购买付费应用、付费模板及云服务产品等。
                    </div>
            </div>
             <%} %>

         
         


         </div>
       <%} %>
	</div>


</asp:Content>

