public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            int             id              = 99999;
            AgentConfig     agentConfig     = new AgentConfig();
            WeixinAgentItem weixinAgentItem = agentConfig.GetItem(id);

            if (weixinAgentItem != null)
            {
                string host      = "http://" + HttpContext.Current.Request.Url.Host;
                string nonce_str = Util.GetRandomString(32, true, true, true, false, "");
                string timestamp = Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds).ToString();
                string sn        = weixinAgentItem.sn;

                Hashtable ht = new Hashtable();
                ht.Add("nonce_str", nonce_str);
                ht.Add("timestamp", timestamp);
                ht.Add("id", id);

                string sign = GetSignX(ht, sn);

                string requestUrl = host + "/api/access_token/";
                requestUrl += "?nonce_str=" + nonce_str + "&timestamp=" + timestamp + "&id=" + id;
                requestUrl += "&sign=" + sign;

                context.Response.Write(HttpService.Get(requestUrl));
            }
            else
            {
                context.Response.Write("示例配置记录不存在");
            }
        }
Exemple #2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            int             id              = 99999;
            AgentConfig     agentConfig     = new AgentConfig();
            WeixinAgentItem weixinAgentItem = agentConfig.GetItem(id);

            if (weixinAgentItem != null)
            {
                string host     = "http://" + HttpContext.Current.Request.Url.Host;
                string redirect = host + "/example/index.html"; //context.Request["redirect"];
                redirect = context.Server.UrlEncode(redirect);

                //***
                string scope = "snsapi_base";
                if (context.Request["scope"] != null)
                {
                    scope = context.Request["scope"];
                }

                string sn        = weixinAgentItem.sn;
                string nonce_str = Util.GetRandomString(32, true, true, true, false, "");
                string timestamp = Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds).ToString();

                Hashtable ht = new Hashtable();
                ht.Add("nonce_str", nonce_str);
                ht.Add("timestamp", timestamp);
                ht.Add("id", id);

                string sign = GetSignX(ht, sn);

                string requestUrl = host + "/api/authorize/";
                requestUrl += "?scope=" + scope + "&redirect=" + redirect;
                requestUrl += "&nonce_str=" + nonce_str + "&timestamp=" + timestamp + "&id=" + id;
                requestUrl += "&sign=" + sign;

                context.Response.Redirect(requestUrl);
            }
            else
            {
                context.Response.Write("示例配置记录不存在");
            }
        }
Exemple #3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");

            AgentConfig agentConfig = new AgentConfig();

            //根据记录ID读取配置内容对象
            //WeixinAgentItem item = agentConfig.GetItem(15);
            //context.Response.Write(item.name);


            //获取SN
            //string sn = agentConfig.CreateSN();
            //context.Response.Write(sn);


            //读取全部配置内容对象
            //List<WeixinAgentItem> items = agentConfig.GetItems();
            //foreach (WeixinAgentItem item in items)
            //{
            //    context.Response.Write(item.name + "\n\r");
            //}


            //获取申请用户
            //List<string> agentNames = agentConfig.GetAgentName();
            //foreach (string name in agentNames)
            //{
            //    context.Response.Write(name + "\n\r");
            //}


            //分派信息配置对象状态
            //WeixinAgentItem item = agentConfig.GetItem(15);
            //bool status = agentConfig.GetAgentStatus(item);
            //context.Response.Write(status);


            //创建记录时获取配置项ID
            //int id = agentConfig.GetIdentity();
            //context.Response.Write(id);


            //添加配置记录
            //List<WeixinAgentItem> items = agentConfig.GetItems();
            //context.Response.Write("countA:" + items.Count + "\n\r");

            //WeixinAgentItem item = new WeixinAgentItem();
            //item.id = agentConfig.GetIdentity();
            //item.agent = agentConfig.GetAgentName()[0];
            //item.name = "项目A";
            //item.authorize = true;
            //item.token = true;
            //item.signature = true;
            //item.url = "www.baidu.com";
            //item.sn = agentConfig.CreateSN();
            //item.begin = "2017-01-01";// DateTime.Parse("2017-01-01");
            //item.end = "2017-12-31";// DateTime.Parse("2017-12-31");

            //context.Response.Write("add:" + agentConfig.AddItem(agentConfig, item) + "\n\r");

            //AgentConfig agentConfig2 = new AgentConfig();
            //List<WeixinAgentItem> items2 = agentConfig2.GetItems();
            //context.Response.Write("countB:" + items2.Count + "\n\r");


            //修改配置记录
            WeixinAgentItem item = agentConfig.GetItem(995);

            if (item != null)
            {
                item.name = "更新NAME-995";

                context.Response.Write("update:" + agentConfig.UpdateItem(item) + "\r\n");
            }

            List <WeixinAgentItem> items = agentConfig.GetItems();

            foreach (WeixinAgentItem i in items)
            {
                context.Response.Write("id:" + i.id + "     ***   name:" + i.name + "\n\r");
            }


            //删除配置记录
            //context.Response.Write("del:" + agentConfig.DelItem(agentConfig, 559) + "\r\n");
            //List<WeixinAgentItem> items = agentConfig.GetItems();
            //foreach (WeixinAgentItem i in items)
            //{
            //    context.Response.Write("id:" + i.id + "     ***   name:" + i.name + "\n\r");
            //}
        }
Exemple #4
0
 public WeixinAgentItem GetItem(int id)
 {
     return(agentConfig.GetItem(id));
 }