Beispiel #1
0
        public void GetWXConfig()
        {
            var dtNow = DateTime.Now;
            //string nonceStr = "Wm3WZYTPz0wzccnW";// DateTime.Now.ToString("yyyyMMddHHmmss");
            string nonceStr  = WxJSSDKConfig.create_nonce_str(16);
            long   timestamp = WxJSSDKConfig.create_timestamp(dtNow);
            var    token     = WXInterface.GetAccessToken(Config.AppID, Config.AppSecret).access_token;

            if (token != null)
            {
                string url    = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;//获取当前url
                var    ticket = WXInterface.GetTicket(token, "jsapi");
                if (ticket != null)
                {
                    string signature = create_signature(ticket.ticket, nonceStr, timestamp.ToString(), url);
                    ViewBag.ticket    = ticket.ticket;
                    ViewBag.signature = signature;
                }
                ViewBag.token     = token;
                ViewBag.nonceStr  = nonceStr;
                ViewBag.timestamp = timestamp;
                ViewBag.appId     = Config.AppID;
                ViewBag.url       = url;
            }
        }
Beispiel #2
0
        public ActionResult Edit()
        {
            var auth = WXInterface.GetAccessToken(Config.AppID, Config.AppSecret);
            var json = WXInterface.GetMenu(auth.access_token);

            ViewBag.data = json.ToJsonString();
            return(View());
        }
Beispiel #3
0
        public ActionResult Index()
        {
            var auth       = WXInterface.GetAccessToken(Config.AppID, Config.AppSecret);
            var json       = WXInterface.GetMenu(auth.access_token);
            var returnType = Request["r"];

            if (returnType == "json")
            {
                return(Json(json, JsonRequestBehavior.AllowGet));
            }
            return(View(json));
        }
Beispiel #4
0
        public ActionResult EditConfirm()
        {
            var data = Request["data"];

            if (data == null)
            {
                return(Json(new CommonResult {
                    Success = false, ErrorMessage = "参数data不能为空!"
                }, JsonRequestBehavior.AllowGet));
            }

            var auth = WXInterface.GetAccessToken(Config.AppID, Config.AppSecret);
            var ret  = WXInterface.CreateMenu(auth.access_token, data);

            return(Json(ret, JsonRequestBehavior.AllowGet));
        }
Beispiel #5
0
        public ActionResult Index()
        {
            var token = WXInterface.GetAccessToken(Config.AppID, Config.AppSecret).access_token;

            string        state        = Request["state"];
            List <string> user_openids = null;


            var current_user_openid = System.Web.HttpContext.Current.Session["openid"];

            if (state == "1" && current_user_openid == null)
            {
                user_openids = WXInterface.GetUserList(token);
            }
            WXInterface.ReGetOpenId();
            current_user_openid = System.Web.HttpContext.Current.Session["openid"];
            if (current_user_openid == null)
            {
                return(Content("无法获取用户信息,请确认微信客户端打开链接"));
            }
            if (user_openids != null)
            {
                string content = current_user_openid + "<br /><br />";
                foreach (var id in user_openids)
                {
                    content += id + "<br />";
                }
                return(Content(content));
            }
            else
            {
                if (current_user_openid == null)
                {
                    return(View());
                }
                var user = HttpHelper.ConvertJson <User>("GET", Config.ApiServer + "/users/" + current_user_openid.ToString(), "");
                if (user == null)
                {
                    HttpHelper.Post(Config.ApiServer + "/users/", "wxopenid=" + current_user_openid.ToString());
                    user = HttpHelper.ConvertJson <User>(Config.ApiServer + "/users/" + current_user_openid.ToString(), "");
                }
                return(Content(Newtonsoft.Json.JsonConvert.SerializeObject(user)));
            }
        }
Beispiel #6
0
        // GET: Menu
        public ActionResult CreateDefault()
        {
            MenuInfo productInfo = new MenuInfo("软件产品", new MenuInfo[] {
                new MenuInfo("移动办公平台", MenuInfo.ButtonType.click, "patient"),
                new MenuInfo("安全审核办公平台", MenuInfo.ButtonType.click, "aqscgl")
            });

            MenuInfo frameworkInfo = new MenuInfo("框架产品", new MenuInfo[] {
                new MenuInfo("Web开发框架", MenuInfo.ButtonType.click, "web"),
                new MenuInfo("代码生成工具", MenuInfo.ButtonType.click, "database2sharp")
            });

            MenuInfo relatedInfo = new MenuInfo("相关链接", new MenuInfo[] {
                new MenuInfo("公司介绍", MenuInfo.ButtonType.click, "Event_Company"),
                new MenuInfo("官方网站", MenuInfo.ButtonType.view, "http://www.bjdflld.com/wx"),
                //new MenuInfo("官方网站", ButtonType.click, "http://www.bjdflld.com"),
                new MenuInfo("提点建议", MenuInfo.ButtonType.click, "Event_Suggestion"),
                new MenuInfo("联系客服", MenuInfo.ButtonType.click, "Event_Contact"),
                //new MenuInfo("发邮件", ButtonType.view, "http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=S31yfX15fn8LOjplKCQm")
                new MenuInfo("发邮件", MenuInfo.ButtonType.click, "Event_Mail")
            });

            MenuJson menuJson = new MenuJson();

            menuJson.button.AddRange(new MenuInfo[] { productInfo, frameworkInfo, relatedInfo });

            var auth = WXInterface.GetAccessToken(Config.AppID, Config.AppSecret);

            if (WXInterface.DeleteMenu(auth.access_token).Success)
            {
                var ret = WXInterface.CreateMenu(auth.access_token, menuJson);
                if (!ret.Success)
                {
                    return(Content("创建微信公众号菜单失败!\n" + ret.ErrorMessage));
                }
            }

            return(View());
        }
Beispiel #7
0
        public ActionResult EditConfirm(string id)
        {
            var account  = Request["account"];
            var openid   = Request["openid"];
            var content  = Request["content"];
            var cate     = Request["cate"];
            var subcate  = Request["subcate"];
            var resp     = Request["resp"];
            var isdanger = Request["isdanger"];

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("content", content);
            parameters.Add("SourceType", cate);
            parameters.Add("SouceSubType", subcate);
            parameters.Add("DangerType", isdanger == "1" ? "隐患" : "");
            parameters.Add("ResponsiblePerson", resp);

            //string data = "";
            //foreach (KeyValuePair<string, object> item in parameters)
            //{
            //    data += string.Format("{0}={1}&", item.Key, item.Value);
            //}
            //HttpHelper.Post(Config.ApiServer + "/safetycheckrecords/", data.Substring(0, data.Length - 1));

            Log log = new Log();

            log.log2("PUT " + Config.ApiServer + "/SafetyCheckRecord/\n");
            try
            {
                var user = (User)Session["current_user"];
                if (user != null)
                {
                    parameters.Add("creator", user.Account);
                    parameters.Add("findTime", DateTime.Now.Ticks);

                    log.log("current_user:"******", " + user.WxOpenId + "\n");
                }
                else
                {
                    log.log("current_user:null\n");
                }
                var serverid = "";
                var token    = WXInterface.GetAccessToken(Config.AppID, Config.AppSecret);

                List <string> uploadFiles = new List <string>();

                for (int i = 0; i < 20; i++)
                {
                    serverid = Request["file_" + i.ToString()];
                    if (!string.IsNullOrEmpty(serverid))
                    {
                        var fullFileName = WXInterface.GetMultimedia(token.access_token, serverid);
                        uploadFiles.Add(fullFileName);
                    }
                }

                var output = HttpHelper.Reqest("PUT", Config.ApiServer + "/SafetyCheckRecord/", parameters, uploadFiles.ToArray());
                log.log("output: " + output + "\n");
            }
            catch (Exception ex)
            {
                log.log("exception: " + ex.Message + "\n");
            }

            return(RedirectToAction("Index", "Home"));
        }