Ejemplo n.º 1
0
        /// <summary>
        /// 根据OpenId判断是否有账号,根据OpenId进行登录
        /// </summary>
        /// <returns></returns>
        public JsonResult <Result <dynamic> > GetLoginByOpenId(string openId = "")
        {
            //string oauthType = "Himall.Plugin.OAuth.WeiXin";//默认小程序微信端登录
            string unionid    = "";
            var    wxuserinfo = ApiHelper.GetAppletUserInfo(Request);

            if (wxuserinfo != null)
            {
                unionid = wxuserinfo.unionId;
            }
            if (!string.IsNullOrEmpty(openId))
            {
                MemberInfo member = new MemberInfo();
                if (!string.IsNullOrWhiteSpace(unionid))
                {
                    member = MemberApplication.GetMemberByUnionIdAndProvider(SmallProgServiceProvider, unionid) ?? new MemberInfo();
                }

                if (member.Id == 0)
                {
                    member = MemberApplication.GetMemberByOpenId(SmallProgServiceProvider, openId) ?? new MemberInfo();
                }
                if (member.Id > 0)
                {
                    //信任登录并且已绑定
                    string memberId = UserCookieEncryptHelper.Encrypt(member.Id, CookieKeysCollection.USERROLE_USER);
                    MemberApplication.AddIntegel(member);//给用户加积分//执行登录后初始化相关操作
                    return(GetMember(member, openId));
                }
                else
                {
                    //信任登录未绑定
                    return(Json(ErrorResult <dynamic>("未绑定商城帐号")));
                }
            }
            return(Json(ErrorResult <dynamic>(string.Empty)));
        }