예제 #1
0
        public HttpResponseMessage GetAppLinkInformation(string Id)
        {
            HttpResponseMessage response = null;

            try
            {
                var oAESDecrypt = new AESDecrypt();
                var oAppLink    = new AppLinkBusiness();
                var result      = oAppLink.GetAppLinkInformation(oAESDecrypt.DecryptStringAES(Id));
                if (result == null || !result.Any())
                {
                    response = Request.CreateResponse(HttpStatusCode.NotFound, "No Data found");
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.OK, result);
                }
            }
            catch (Exception ex)
            {
                // Log the message
                response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }
            return(response);
        }
예제 #2
0
        /// <summary>
        /// 用户登录/注册
        /// </summary>
        /// <param name="code">微信授权Code</param>
        /// <param name="iv">初始向量</param>
        /// <param name="data">加密数据</param>
        /// <param name="signature">加密签名</param>
        /// <returns>微信用户数据(Json)</returns>
        public ActionResult CheckUserLogin(string code, string iv, string data, string signature, string appid, string appsr = "")
        {
            if (string.IsNullOrWhiteSpace(code) || string.IsNullOrWhiteSpace(iv) || string.IsNullOrWhiteSpace(data) || string.IsNullOrWhiteSpace(signature) || string.IsNullOrWhiteSpace(appid))
            {
                return(Json(new { result = false, msg = "参数缺省", errcode = 0 }, JsonRequestBehavior.AllowGet));
            }

            //微信授权Code,调用接口获得session_key
            var JsonResult = new DecryptUserInfo().GetApiJsonStringnew(code, appid, appsr);
            var session    = JsonConvert.DeserializeObject <UserSession>(JsonResult);

            session.code      = code;
            session.vector    = iv;
            session.enData    = data;
            session.signature = signature;
            if (!session.verify())
            {
                return(CheckUserLoginNoappsr(code, iv, data, signature, appid));
                //return Json(new { result = false, msg = "获取Session_key异常,appsr=" + appsr, errcode = -1, Oject = UserSession }, JsonRequestBehavior.AllowGet);
            }
            //AES解密,委托参数session_key和初始向量
            session.deData = AESDecrypt.Decrypt(session.enData, session.session_key, session.vector);
            C_ApiUserInfo userInfo = JsonConvert.DeserializeObject <C_ApiUserInfo>(session.deData);
            //保存用户会话
            //var SessionId = AESDecrypt.MD5(UserSession.session_key + UserInfo.unionId);
            //返回sessionId
            C_UserInfo userinfopost = C_UserInfoBLL.SingleModel.GetModelFromCache(userInfo.openId);

            if (userinfopost == null)
            {
                userinfopost = C_UserInfoBLL.SingleModel.RegisterByXiaoChenXun(new C_UserInfo()
                {
                    NickName = userInfo.nickName, HeadImgUrl = userInfo.avatarUrl, UnionId = userInfo.unionId, appId = appid, OpenId = userInfo.openId, Sex = int.Parse(userInfo.gender)
                });
            }
            userInfo.nickName         = userinfopost.NickName;
            userInfo.avatarUrl        = userinfopost.HeadImgUrl;
            userInfo.gender           = userinfopost.Sex.ToString();
            userInfo.tel              = userinfopost.TelePhone;
            userInfo.IsValidTelePhone = userinfopost.IsValidTelePhone;
            return(Json(new BaseResult()
            {
                result = true, msg = "解密完成", obj = userInfo
            }, JsonRequestBehavior.AllowGet));
        }