<%@ Page Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="true" Inherits="Kesion.NET.WebSite.Admin_AccountAPI" Title="Untitled Page" CodeBehind="KS.AccountAPI.aspx.cs" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Newtonsoft.Json" %>
<%@ Import Namespace="Newtonsoft.Json.Linq" %>
<asp:Content ID="Content1" ContentPlaceHolderID="KSContent" Runat="Server">


    <asp:Panel ID="listPanel" runat="server" Width="100%">
       <!--<KS:TopNav ID="TopNav2" runat="server" Text="账号通API&社交营销配置" />-->
    <div class="content-area mt20">
 		
       <div class="tab-page" id="AccountPanel">
         <script type="text/javascript">
             var tabPane1 = new WebFXTabPane(document.getElementById("AccountPanel"), 1)
         </script>
             
		 <div class="tab-page" id="tab0">
		  <h2 class="tab">账号通API</h2>
			<script type="text/javascript">
			    tabPane1.addTabPage(document.getElementById("tab0"));
			</script>
          <table width="100%" cellspacing="0" cellpadding="0">
              <tr>
                  <td>
                           <table width="99%" border="0" cellpadding="0" cellspacing="0" class="CTable no-borderTable" > 
                            <tr>
                               <td class="lefttd" align="right"><b>首次登录自动创建账号并登录：</b></td>
                               <td class="righttd">
                                   <asp:RadioButtonList ID="RdbApiAutoCreateUser" RepeatDirection="Horizontal" runat="server">
                                    <asp:ListItem Value="1" Selected>启用</asp:ListItem>
                                    <asp:ListItem Value="0">不启用</asp:ListItem>
                                   </asp:RadioButtonList>
                                  <span class="tips">如果启用首次登录自动创建账号，将省去让用户绑定的环节，但会导致无法和会员原有的账号绑定通用，请慎用。</span>                                      
                                  </td>
                             </tr>
                            <tr>
                               <td class="lefttd" align="right"><b>默认注册的会员用户组：</b></td>
                               <td class="righttd">
                                   <span id="groupidarea" runat="server"></span>                                
                                  </td>
                             </tr>
                        </table>
                  </td>
                  <td align="right" style="padding-right:50px;">
                      <asp:Button ID="Button1" CssClass="button_on" runat="server" Text="保存配置规则"   onclick="Button1_Click" />
                  </td>
              </tr>
          </table>
  
       
        <KS:KSGV ID="list" cssclass="CTable" runat="server" Width="99%" AutoGenerateColumns="False" EmptyDataText="暂无账号通API!" GridLines="None" OnRowDataBound="list_RowDataBound" PagerType="CustomNumeric">
            <Columns>
             <asp:BoundField HeaderText="接口标识ID" DataField="ID">
                    <ItemStyle HorizontalAlign="Center" Width="40px" />
                </asp:BoundField>
            <asp:TemplateField HeaderText="状态">
                <ItemStyle HorizontalAlign="Center" />
                <ItemTemplate>
              <asp:HiddenField ID="Hidenable" Value='<%# Eval("enable") %>' runat="server" />
              <asp:HiddenField ID="HidapplyUrl" Value='<%# Eval("applyurl") %>' runat="server" />
                <%# Eval("enable").ToString().Equals("true")?"<span style='color:green'>已启用</span>":"关闭" %>

                 </ItemTemplate>
            </asp:TemplateField>  
                
                
            <asp:TemplateField HeaderText="接口名称">
                <ItemStyle HorizontalAlign="Center" />
                <ItemTemplate>
                    <%#Eval("name") %>
                 </ItemTemplate>
            </asp:TemplateField>  
            <asp:TemplateField HeaderText="ApiID">
                <ItemStyle HorizontalAlign="Center" />
                <ItemTemplate>
                    <%#Eval("ApiID") %>
                 </ItemTemplate>
            </asp:TemplateField>  
           
            <asp:TemplateField HeaderText="登录成功返回的URL">
                <ItemStyle HorizontalAlign="Center" />
                <ItemTemplate>
                  <%#Eval("apireturnurl") %>
                 </ItemTemplate>
            </asp:TemplateField>  

            <asp:TemplateField HeaderText="修改">
                       <itemstyle horizontalalign="Center" width="25"/>
                        <itemtemplate>
                            <a onclick="doNone(event);" href="?id=<%#Eval("id") %>" class="edit"></a>
                        </itemtemplate>
             </asp:TemplateField>
            <asp:TemplateField HeaderText="申请">
                       <itemstyle horizontalalign="Center" width="25"/>
                        <itemtemplate>
                           <a class="apply" href="<%# Eval("ApplyUrl") %>" title="申请" target="_blank"></a>
                        </itemtemplate>
             </asp:TemplateField>
            
            </Columns>
           
            <PagerStyle CssClass="Page" HorizontalAlign="Right" />
            <HeaderStyle CssClass="CTitle" />
            <EmptyDataRowStyle CssClass="emptycss" />
      </KS:KSGV>
      
     <br />

        <br />
        <script type="text/javascript">
            showtips('<span class="state"><strong>说明：</strong><br /></span>上面接口的ApiID及ApiKey需要到第三方网站申请后填入方可使用。');
		</script>

    </div>


    <div class="tab-page" id="tab1">
		 <h2 class="tab">社交营销设置</h2>
		 <script type="text/javascript">
			    tabPane1.addTabPage(document.getElementById("tab1"));
		 </script>

         <table width="99%" border="0" cellpadding="1" cellspacing="1" class="CTable" style="border-bottom:none;"> 
            <tr>
               <td class="lefttd" align="right"><b>发表文档显示社交营销选项：</b></td>
               <td class="righttd">
                   <asp:RadioButtonList ID="RdbIsShowMarketing" AutoPostBack="true" RepeatDirection="Horizontal" runat="server" onselectedindexchanged="RdbIsMarketing_SelectedIndexChanged">
                    <asp:ListItem Value="1" Selected>显示</asp:ListItem>
                    <asp:ListItem Value="0">不显示</asp:ListItem>
                   </asp:RadioButtonList>
               </td>
            </tr>
        </table>
 
       <table id="showMarketing" runat="server" width="99%" border="0" cellpadding="0" cellspacing="0" class="CTable no-borderTable"> 
            <tr>
               <td class="lefttd" align="right"><b>新浪微博营销：</b></td>
               <td class="righttd">
                 <%
                     XmlDocument xmlDoc = new XmlDocument();
                     xmlDoc.Load(Server.MapPath("~/config/AccountAPI.config"));
                    
                     bool isToken = false;
                     XmlNode xn = xmlDoc.DocumentElement.SelectSingleNode("item[@id='sina']");
                     if (xn!= null)
                     {
                         if (xn.SelectSingleNode("@enable").InnerText != "true")
                         {
                             Response.Write("新浪微博账号通API没有开启！");
                         }
                         else
                         {
                             string token = string.Empty;
                             string uid = string.Empty;
                             if (xn.SelectSingleNode("@token") != null)
                             {
                                 token = xn.SelectSingleNode("@token").InnerText;
                             }
                             else
                             {
                                 XmlAttribute xe = xmlDoc.CreateAttribute("token");
                                 xe.InnerText = "";
                                 xn.Attributes.Append(xe);
                                 xmlDoc.Save(Server.MapPath("~/config/AccountAPI.config"));
                             }
                             if (xn.SelectSingleNode("@uid") != null)
                             {
                                 uid = xn.SelectSingleNode("@uid").InnerText;
                             }
                             else
                             {
                                 XmlAttribute xe = xmlDoc.CreateAttribute("uid");
                                 xe.InnerText = "";
                                 xn.Attributes.Append(xe);
                                 xmlDoc.Save(Server.MapPath("~/config/AccountAPI.config"));
                             }
                             if (!string.IsNullOrEmpty(token) && !string.IsNullOrEmpty(uid))
                             {
                                 string graph_url = "https://api.weibo.com/2/users/show.json";
                                 graph_url += "?access_token=" + token + "&uid=" + uid;
                                 Uri url = new Uri(graph_url);
                                 string result = CollectionCommon.GetHttpPage(url, "utf-8");
                                 if (result.IndexOf("error") == -1)
                                 {
                                     isToken = true;
                                 }

                             }

                             if (isToken == false)
                             {
                                 Response.Write(@"状态：<font color=red>未授权或是授权失效，请点击&nbsp;<input type='button' onclick=""top.openWin('登录新浪微博获取授权信息','" + BaseFun.GetRewriteUrl("sinalogin") + @"?tokenfrom=admin',true)"" class='button button_on' value='登录授权'/>&nbsp;重新获取权限！</font>");
                             }
                             else
                             {
                                 Response.Write(@"状态：<font color=green>已获得授权！</font>&nbsp;<input type='button' onclick=""top.openWin('登录新浪微博获取授权信息','" + BaseFun.GetRewriteUrl("sinalogin") + @"?tokenfrom=admin',true)"" class='button button_on' value='切换授权账号'/>");

                             }
                         }
                        
                     }

                     
                 %>
                 <br />
                  <span class="tips">授权成功后发表的文档(如文章，商品，试卷等)将自动转发到新浪微博平台上。</span>                                      
                  </td>
             </tr>

              <tr>
               <td class="lefttd" align="right"><b>腾讯微博营销：</b></td>
               <td class="righttd">
                 <%
                     XmlDocument xmlDoc = new XmlDocument();
                     xmlDoc.Load(Server.MapPath("~/config/AccountAPI.config"));
                    
                     bool isToken = false;
                     XmlNode xn = xmlDoc.DocumentElement.SelectSingleNode("item[@id='qq']");
                     if (xn!= null)
                     {
                         if (xn.SelectSingleNode("@enable").InnerText != "true")
                         {
                             Response.Write("QQ登录API没有开启！");
                         }
                         else
                         {
                             string token = string.Empty;
                             string uid = string.Empty;
                             if (xn.SelectSingleNode("@token") != null)
                             {
                                 token = xn.SelectSingleNode("@token").InnerText;
                             }
                             else
                             {
                                 XmlAttribute xe = xmlDoc.CreateAttribute("token");
                                 xe.InnerText = "";
                                 xn.Attributes.Append(xe);
                                 xmlDoc.Save(Server.MapPath("~/config/AccountAPI.config"));
                             }
                             if (xn.SelectSingleNode("@uid") != null)
                             {
                                 uid = xn.SelectSingleNode("@uid").InnerText;
                             }
                             else
                             {
                                 XmlAttribute xe = xmlDoc.CreateAttribute("uid");
                                 xe.InnerText = "";
                                 xn.Attributes.Append(xe);
                                 xmlDoc.Save(Server.MapPath("~/config/AccountAPI.config"));
                             }
                             
                             if (!string.IsNullOrEmpty(token) && !string.IsNullOrEmpty(uid))
                             {
                                 string graph_url = "https://graph.qq.com/user/get_user_info";
                                 graph_url += "?access_token=" + token + "&oauth_consumer_key="+xn.SelectSingleNode("@apiid").InnerText+"&openid=" + uid;
                                 Uri url = new Uri(graph_url);
                                 string result = CollectionCommon.GetHttpPage(url, "utf-8");
                                 JObject jsonObj = JObject.Parse(result);
                                 if (jsonObj["ret"].ToString()=="0")
                                 {
                                     isToken = true;
                                 }

                             }

                             if (isToken == false)
                             {
                                 Response.Write(@"状态：<font color=red>未授权或是授权失效，请点击&nbsp;<input type='button' onclick=""top.openWin('登录腾讯获取授权信息','" + BaseFun.GetRewriteUrl("qqlogin") + @"?tokenfrom=admin',true)"" class='button button_on' value='登录授权'/>&nbsp;重新获取权限！</font>");
                             }
                             else
                             {
                                 Response.Write(@"状态：<font color=green>已获得授权！</font>&nbsp;<input type='button' onclick=""top.openWin('登录腾讯获取授权信息','" + BaseFun.GetRewriteUrl("qqlogin") + @""" class='button button_on' value='切换授权账号'/>");

                             }
                         }
                        
                     }

                     
                 %>
                 <br />
                  <span class="tips">授权成功后发表的文档(如文章，商品，试卷等)将自动转发到腾讯微博、QQ空间日志及QQ说说分享等平台上。</span>                                      
                  </td>
             </tr>

      </table>


</div>  

       </div>

     </asp:Panel>




 <asp:Panel ID="addPanel" runat="server" Width="100%" Visible="false">
 <div class="content-area mt20">   
        <div class="myTitle">修改第三方登录接口配置信息</div>
     <asp:HiddenField ID="HidID" runat="server" />
        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="CTable no-borderTable"> 
              <tr>
            <td class="lefttd" height="30" align="right" style="width: 198px"><b>接口名称：</b></td>
            <td class="righttd">
                &nbsp;<asp:TextBox CssClass="textbox" ID="TxtName" runat="server"></asp:TextBox> <font color=#ff0000>*</font>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" Display="Dynamic" runat="server" ControlToValidate="TxtName"
                    ErrorMessage="请输入接口名称!"></asp:RequiredFieldValidator></td>
          </tr>    
          <tr>
            <td class="lefttd" height="30" align="right" style="width: 198px"><b>ApiID：</b></td>
            <td class="righttd">
                &nbsp;<asp:TextBox CssClass="textbox" ID="TxtApiID" runat="server"></asp:TextBox> <font color=#ff0000>*</font>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" Display="Dynamic" runat="server" ControlToValidate="TxtApiID"
                    ErrorMessage="请输入规则标识!"></asp:RequiredFieldValidator></td>
          </tr>  
          <%if (KSCMS.S("id") == "alipay")
              { %>
            <tr>
            <td class="lefttd" height="30" align="right" style="width: 198px"><b>商户私匙信息：</b></td>
            <td class="righttd">
                &nbsp;<asp:TextBox CssClass="textbox" ID="TxtPrivateKey" TextMode="MultiLine" runat="server" Width="450" Height="120"></asp:TextBox> <font color=#ff0000>*</font>
                </td>
          </tr>  
            <tr>
            <td class="lefttd" height="30" align="right" style="width: 198px"><b>支付宝公匙信息：</b></td>
            <td class="righttd">
                &nbsp;<asp:TextBox CssClass="textbox" ID="TxtPublicKey" TextMode="MultiLine" runat="server" Width="450" Height="120"></asp:TextBox> <font color=#ff0000>*</font>
                </td>
          </tr>  
            <%}
    else
    { %>
          <tr>
            <td class="lefttd" height="30" align="right" style="width: 198px"><b>ApiKey：</b></td>
            <td class="righttd">
                &nbsp;<asp:TextBox CssClass="textbox" ID="TxtApiKey" runat="server"></asp:TextBox> <font color=#ff0000>*</font>
                </td>
          </tr>   
        <%} %>
          <tr>
            <td class="lefttd" height="30" align="right" style="width: 198px"><b>登录成功返回的URL：</b></td>
            <td class="righttd">
                &nbsp;<asp:TextBox CssClass="textbox" ID="TxtApiReturnUrl" runat="server"></asp:TextBox> <font color=#ff0000>*</font>
                </td>
          </tr>   
            <tr>
                <td align="right" class="lefttd" height="30" style="width: 198px">
                    <strong>是否启用：</strong></td>
                <td class="righttd">
                     &nbsp;<asp:RadioButtonList ID="RdbEnable" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
                         <asp:ListItem Value="true" Selected="True">启用</asp:ListItem>
                         <asp:ListItem Value="false">不启用</asp:ListItem>
                           </asp:RadioButtonList>
               </td>
            </tr>
            
        </table>
        <KS:Foot ID="Foot1" runat="server" OnSubmit="Foot1_Submit"  />
    </asp:Panel>
   
   </div> 

</asp:Content>

