Exemplo n.º 1
0
        private string get_jsapi_ticket(string access_token)
        {
            var ticket = WXInterface.GetTicket(access_token, "jsapi");

            if (ticket != null)
            {
                return(ticket.ticket);
            }
            return("");

            /*
             * if (null == apiticket) {
             * String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket";
             * String jsonStrTicket = Tools.sendGet(url, "access_token=" + access_token + "&type=jsapi");
             *
             * logger.debug("[jsonStrTicket] = " + jsonStrTicket);
             *
             * JSONObject json = JSONObject.fromObject(jsonStrTicket);
             * ticket = (String) json.get("ticket");
             *
             * } else {
             * ticket = (String) apiticket;
             * }
             * */
        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
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());
        }
Exemplo n.º 4
0
        public User GetCurrentUser()
        {
            //从url参数中获取用户openid
            var current_user_openid = Request["openid"];

            //从session中获取用户openid
            if (current_user_openid == null)
            {
                var current_user_openid_session = System.Web.HttpContext.Current.Session["openid"];
                if (current_user_openid_session != null)
                {
                    current_user_openid = current_user_openid_session.ToString();
                }
            }
            else
            {
                System.Web.HttpContext.Current.Session["openid"] = current_user_openid;
            }

            //重新从微信中获取用户openid
            if (current_user_openid == null)
            {
                WXInterface.ReGetOpenId();
                var current_user_openid_session = System.Web.HttpContext.Current.Session["openid"];
                if (current_user_openid_session != null)
                {
                    current_user_openid = current_user_openid_session.ToString();
                }
            }
            if (current_user_openid == null)
            {
                return(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
            //{

            var user = HttpHelper.ConvertJson <User>("GET", Config.ApiServer + "/users/" + current_user_openid.ToString(), "");

            if (user != null)
            {
                System.Web.HttpContext.Current.Session["current_user"] = user;
            }
            //return Content(Newtonsoft.Json.JsonConvert.SerializeObject(user));
            return(user);
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
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)));
            }
        }
Exemplo n.º 8
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());
        }
Exemplo n.º 9
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"));
        }