Beispiel #1
0
        public ActionResult UserInfo(AccessTokenModel m, string return_url)
        {
            var url = URL_USERINFO +
                      "?access_token=" + m.access_token +
                      "&openid=" + m.openid +
                      "&lang=zh_CN";
            var result = HttpGet <UserInfoModel>(url);

            if (!result.openid.HasValue())
            {
                throw new Exception("request fail to" + url + "\r\n" +
                                    "AccessTokenModel=>" + m.Serialize() + "\r\n" +
                                    "UserInfoModel=>" + result.Serialize() + "\r\n"
                                    );
            }

            //-----------------这里编写绑定逻辑

            try
            {
                //1.创建账户
                if (_permissionProvider.Regist(result.openid, "12345", result.nickname) &&
                    _IXiaoTuanService.AddUser(result.openid, result.headimgurl))
                {
                    //var account = _accountPayService.CreateAccount(m.openid, AccountTypeEnum.Personal);
                    //5.同步账户
                    //_accountPayService.SyncAccount(account);
                    result.errmsg = "恭喜绑定成功!";
                    return(BackToBLL(result.openid, return_url, m.errmsg, result.nickname));
                }
                else
                {
                    result.errmsg = "绑定失败,请重试!";
                    return(Content(result.Serialize()));
                }
            }
            catch (DbEntityValidationException ex)
            {
                throw new Exception(m.openid + "(openid) Regist Failed" + "\r\n" +
                                    m.access_token + "(access_token)\r\n" +
                                    ex.Message + "\r\n" +
                                    ex.EntityValidationErrors.SelectMany(a => a.ValidationErrors.Select(b => b.ErrorMessage)).Aggregate((c, d) => c + "\r\n" + d) + "\r\n" +
                                    ex.StackTrace);
            }
        }