Esempio n. 1
0
        public SeccessModel GetApiJsonStringnoappsr(string js_code, string appid)
        {
            JsonSerializerSettings setting = new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            };
            SeccessModel    resultmodel = new SeccessModel();
            UserXcxTemplate umodel      = UserXcxTemplateBLL.SingleModel.GetModelByAppId(appid);

            if (umodel != null)
            {
                XcxAppAccountRelation xcxrelation = XcxAppAccountRelationBLL.SingleModel.GetModelByAppid(appid);
                if (xcxrelation != null)
                {
                    XcxApiBLL.SingleModel._openType = xcxrelation.ThirdOpenType;
                }

                string url    = XcxApiBLL.SingleModel.GetSessionKey(appid.Trim(), js_code);
                string result = HttpHelper.GetData(url);
                if (!string.IsNullOrEmpty(result))
                {
                    XcxApiRequestJson <object> data = JsonConvert.DeserializeObject <XcxApiRequestJson <object> >(result, setting);
                    if (data != null && data.obj != null)
                    {
                        if (!string.IsNullOrEmpty(data.obj.session_key))
                        {
                            resultmodel.session_key = data.obj.session_key;
                            resultmodel.openid      = data.obj.openid;
                            resultmodel.isok        = 1;
                            resultmodel.msg         = "OK";
                        }
                        else
                        {
                            resultmodel.isok = -1;
                            resultmodel.msg  = data.msg;
                        }
                    }
                    else
                    {
                        resultmodel.isok = -1;
                        resultmodel.msg  = "获取秘钥null" + result;
                    }
                }
                else
                {
                    resultmodel.isok = -1;
                    resultmodel.msg  = result;
                }
            }
            else
            {
                resultmodel.isok = -1;
                resultmodel.msg  = "没有上传记录";
            }

            return(resultmodel);
        }
Esempio n. 2
0
        /// <summary>
        /// 小程序登陆通过第三方平台获取密钥
        /// </summary>
        /// <param name="js_code"></param>
        /// <param name="appid"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public UserSession GetAppSessionInfoByThirdPlat(string js_code, string appid, ref string msg)
        {
            UserSession           session     = new UserSession();
            XcxAppAccountRelation xcxrelation = XcxAppAccountRelationBLL.SingleModel.GetModelByAppid(appid);

            if (xcxrelation != null)
            {
                _openType = xcxrelation.ThirdOpenType;
            }

            string url        = GetSessionKey(appid.Trim(), js_code);
            string resultJson = HttpHelper.GetData(url);

            if (string.IsNullOrEmpty(resultJson))
            {
                msg = "获取小程序sessionkey返回值为空";
                return(session);
            }
            XcxApiRequestJson <object> data = JsonConvert.DeserializeObject <XcxApiRequestJson <object> >(resultJson);

            if (data == null || data.obj == null)
            {
                msg = "获取秘钥null" + resultJson;
                return(session);
            }

            if (!string.IsNullOrEmpty(data.obj.session_key))
            {
                session.session_key = data.obj.session_key;
                session.openid      = data.obj.openid;
            }
            else
            {
                msg = data.msg;
            }
            return(session);
        }