Beispiel #1
0
        public HttpRequestMessage UpdateWX()
        {
            string   json   = "";
            UserInfo user   = AdminUtil.GetLoginUser("");
            string   result = WXApi.CreateMenu(AdminUtil.GetAccessToken(""), user.OrgID);

            if (Tools.GetJsonValue(result, "errcode") == "0")
            {
                json = "{\"code\":1,\"msg\":\"\"}";
            }
            else
            {
                json = "{\"code\":0,\"msg\":\"errcode:"
                       + Tools.GetJsonValue(result, "errcode") + ", errmsg:"
                       + Tools.GetJsonValue(result, "errmsg") + "\"}";
            }
            return(null);
        }
Beispiel #2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            //WXApi.DownloadMedia("http://localhost:2454/UploadFile/aa.png");
            //Response.Write(WXApi.UploadMedia(Session["token"].ToString(), "image", "d:\\_临时文件\\aa.png"));
            //获取天气预报
            //string result = HttpRequestUtil.RequestUrl("http://www.weather.com.cn/data/sk/101220101.html", "GET");
            //Response.Write(result);
            //result = Weixin.Mp.Util.Tools.GetJosnValue(result, "WSE");
            //Response.Write(result);
            //Response.Write(AdminUtil.GetRootUrl());
            //string result = WXApi.CreateMenu(AdminUtil.GetAccessToken(this), AdminUtil.GetLoginUser(this).OrgID);
            //Response.Write(AdminUtil.GetRootUrl());

            //string path = MapPath("UploadFile/aa.png");
            //string id = WXApi.UploadMedia(AdminUtil.GetAccessToken(this), "image", path);
            //Response.Write(id);

            Response.Write(WXMsgUtil.CreateTextJson("abc", WXApi.GetOpenIDs(AdminUtil.GetAccessToken(this))));
        }
Beispiel #3
0
        /// <summary>
        /// 群发
        /// </summary>
        public string Send()
        {
            string type = Request["type"];
            string data = Request["data"];

            string        access_token = AdminUtil.GetAccessToken(this); //获取access_token
            List <string> openidList   = WXApi.GetOpenIDs(access_token); //获取关注者OpenID列表
            UserInfo      loginUser    = AdminUtil.GetLoginUser(this);   //当前登录用户

            string resultMsg = null;

            //发送文本
            if (type == "1")
            {
                resultMsg = WXApi.Send(access_token, WXMsgUtil.CreateTextJson(data, openidList));
            }

            //发送图片
            if (type == "2")
            {
                string path = MapPath(data);
                if (!File.Exists(path))
                {
                    return("{\"code\":0,\"msg\":\"要发送的图片不存在\"}");
                }
                string msg      = WXApi.UploadMedia(access_token, "image", path);
                string media_id = Tools.GetJsonValue(msg, "media_id");
                resultMsg = WXApi.Send(access_token, WXMsgUtil.CreateImageJson(media_id, openidList));
            }

            //发送图文消息
            if (type == "3")
            {
                DataTable dt           = ImgItemDal.GetImgItemTable(loginUser.OrgID, data);
                string    articlesJson = ImgItemDal.GetArticlesJsonStr(this, access_token, dt);
                string    newsMsg      = WXApi.UploadNews(access_token, articlesJson);
                string    newsid       = Tools.GetJsonValue(newsMsg, "media_id");
                resultMsg = WXApi.Send(access_token, WXMsgUtil.CreateNewsJson(newsid, openidList));
            }

            //结果处理
            if (!string.IsNullOrWhiteSpace(resultMsg))
            {
                string errcode = Tools.GetJsonValue(resultMsg, "errcode");
                string errmsg  = Tools.GetJsonValue(resultMsg, "errmsg");
                if (errcode == "0")
                {
                    return("{\"code\":1,\"msg\":\"\"}");
                }
                else
                {
                    return("{\"code\":0,\"msg\":\"errcode:"
                           + errcode + ", errmsg:"
                           + errmsg + "\"}");
                }
            }
            else
            {
                return("{\"code\":0,\"msg\":\"type参数错误\"}");
            }
        }
Beispiel #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string action = Request["action"];
            string json   = string.Empty;

            try
            {
                switch (action)
                {
                case "Load":
                    int       pageSize = Convert.ToInt32(Request["rows"]);
                    int       pageNum  = Convert.ToInt32(Request["page"]);
                    string    userName = Session["WebUser"].ToString();
                    DataTable dt       = MenuDal.GetMenuList(userName);
                    int       count    = dt.Rows.Count;
                    Dictionary <string, object> dic = new Dictionary <string, object>();
                    dic.Add("total", count);
                    dic.Add("rows", dt);
                    json = JsonConvert.SerializeObject(dic);
                    break;

                case "edit":
                    string    id      = Request["id"];
                    DataTable menudt  = MenuDal.GetMenuByID(int.Parse(id));
                    string    codelen = menudt.Rows[0]["Code"].ToString();
                    if (codelen.Length == 2)
                    {
                        menudt.Rows[0]["Code"] = "0";
                    }
                    else
                    {
                        menudt.Rows[0]["Code"] = codelen.Substring(0, 2);
                    }
                    json = JsonConvert.SerializeObject(menudt);
                    break;

                case "add":
                    string codes    = Request["code"];
                    string mname    = Request["name"];
                    string mtype    = Request["type"];
                    string mkey     = Request["key"];
                    string murl     = Request["url"];
                    string username = Session["WebUser"].ToString();
                    string mcode    = "";
                    if (codes == "0")
                    {
                        mcode = MenuDal.GetOneCode();
                    }
                    else
                    {
                        mcode = MenuDal.GetTwoCode(codes);
                    }
                    int addrow = MenuDal.AddMenu(mcode, mname, mtype, mkey, murl, username);
                    if (addrow == 1)
                    {
                        json = "1";
                    }
                    break;

                case "update":
                    string menuId = Request["id"];
                    //string code = Request["code"];
                    string name  = Request["name"];
                    string type  = Request["type"];
                    string key   = Request["key"];
                    string url   = Request["url"];
                    int    uprow = MenuDal.UpdateMenu(menuId, name, type, key, url);
                    if (uprow == 1)
                    {
                        json = "1";
                    }
                    break;

                case "deleteMenu":
                    var ids = Request["id"];
                    if (ids != null)
                    {
                        int row = MenuDal.DeleteMenu(ids);
                        if (row == 1)
                        {
                            json = "1";
                        }
                        else
                        {
                            json = "0";
                        }
                    }
                    else
                    {
                        json = "0";
                    }
                    break;

                case "deleteOneMenu":
                    var oneCode = Request["code"];
                    if (oneCode != null)
                    {
                        int row = MenuDal.DeleteOneMenu(oneCode, AdminUtil.GetLoginUser(this));
                        if (row > 0)
                        {
                            json = "1";
                        }
                    }
                    break;

                case "updateWX":     //同步到微信
                    UserInfo user   = AdminUtil.GetLoginUser(this);
                    string   result = WXApi.CreateMenu(AdminUtil.GetAccessToken(this), user.OrgID);
                    if (Tools.GetJsonValue(result, "errcode") == "0")
                    {
                        json = "{\"code\":1,\"msg\":\"\"}";
                    }
                    else
                    {
                        json = "{\"code\":0,\"msg\":\"errcode:"
                               + Tools.GetJsonValue(result, "errcode") + ", errmsg:"
                               + Tools.GetJsonValue(result, "errmsg") + "\"}";
                    }
                    break;

                case "tree":
                    DataTable        menudts  = MenuDal.GetOneMenuList(AdminUtil.GetLoginUser(this));
                    List <MenuModel> flowList = new List <MenuModel>();
                    MenuModel        flow;
                    foreach (DataRow drFlowType in menudts.Rows)
                    {
                        flow          = new MenuModel();
                        flow.id       = drFlowType["Code"].ToString();
                        flow.level    = 0;
                        flow.parent   = "-1";
                        flow.isLeaf   = false;
                        flow.expanded = true;

                        flow.Id      = int.Parse(drFlowType["Id"].ToString());
                        flow.Code    = drFlowType["Code"].ToString();
                        flow.Name    = drFlowType["Name"].ToString();
                        flow.Type    = drFlowType["Type"].ToString();
                        flow.MenuKey = drFlowType["MenuKey"].ToString();
                        flow.Url     = drFlowType["Url"].ToString();
                        flow.OrgID   = drFlowType["OrgID"].ToString();
                        flowList.Add(flow);
                        DataTable menudts2 = MenuDal.GetTwoMenuList(flow.Code);
                        foreach (DataRow twoRow in menudts2.Rows)
                        {
                            MenuModel flow2 = new MenuModel();
                            flow2.id       = twoRow["Code"].ToString();
                            flow2.level    = 1;
                            flow2.parent   = twoRow["Code"].ToString().Substring(0, 2);
                            flow2.isLeaf   = true;
                            flow2.expanded = true;

                            flow2.Id      = int.Parse(twoRow["Id"].ToString());
                            flow2.Code    = twoRow["Code"].ToString();
                            flow2.Name    = twoRow["Name"].ToString();
                            flow2.Type    = twoRow["Type"].ToString();
                            flow2.MenuKey = twoRow["MenuKey"].ToString();
                            flow2.Url     = twoRow["Url"].ToString();
                            flow2.OrgID   = twoRow["OrgID"].ToString();
                            flowList.Add(flow2);
                        }
                    }
                    json = JsonConvert.SerializeObject(flowList);
                    break;

                case "menulist":
                    DataTable onedt  = MenuDal.GetOneMenuList(AdminUtil.GetLoginUser(this));
                    DataRow   onerow = onedt.NewRow();
                    onerow["Code"] = 0;
                    onerow["Name"] = "无";
                    onedt.Rows.InsertAt(onerow, 0);
                    json = JsonConvert.SerializeObject(onedt);
                    break;

                default:
                    break;
                }
            }
            catch (Exception)
            {
                throw;
            }
            if (!string.IsNullOrEmpty(json))
            {
                Response.Write(json);
                Response.End();
            }
        }