Ejemplo n.º 1
0
        public ActionResult Presession()
        {
            Response.Buffer          = true;
            Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
            Response.CacheControl    = "no-cache";
            //ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            //logger.Info("weOpenid=" + Session["openid"]);
            JObject json = new JObject();

            try
            {
                string deviceId = Session["openid"].ToString();
                //string language = LANGUAGE_VALUE;
                string language = Session["language"].ToString();
                string result   = authMgr.getPresession(deviceId, language);

                STReturn ret = Global.chkJsonStats(result);
                json.Add("code", ret.retCode);
                json.Add("msg", ret.retMsg);

                if (int.Parse(ret.retCode) != (int)MsgCode.OPR_SUCC)
                {
                    //when retcode status not succ,directly return retcode and msg to frontend
                    return(Content(json.ToString()));
                }

                Presession presession = new Presession().parsePresession(result);
                json.Add("sessionID", presession.sessionID);
                json.Add("randomNo", presession.randomNo);
                json.Add("publicKey", presession.publicKey);

                Session["Presession"] = presession;

                return(Content(json.ToString()));
            }
            catch (WeChatException ex)
            {
                json.RemoveAll();
                json.Add("code", ex.WeChatErrorCode);
                json.Add("msg", ex.WeChatErrorMessage);
                return(Content(json.ToString()));
            }
            catch (Exception)
            {
                json.RemoveAll();
                json.Add("code", (int)MsgCode.SYSTEM_ERR);
                json.Add("msg", ReturnMsg.msgList[(int)MsgCode.SYSTEM_ERR]);
                return(Content(json.ToString()));
            }
        }