public string RequestLogin(string code, string iv, string encryptedData) { BaseResponseModel <AccountModel> responseModel = new BaseResponseModel <AccountModel>(); AccountModel accountCard = null; WXSmallAppCommon.Models.WXAccountInfo wXAccount = WXSmallAppCommon.WXInteractions.WXLoginAction.ProcessRequest(code, iv, encryptedData); if (wXAccount.OpenId != null) { var filter = Builders <AccountModel> .Filter.And(Builders <AccountModel> .Filter.Eq(x => x.OpenID, wXAccount.OpenId)); var collection = new MongoDBTool().GetMongoCollection <AccountModel>(); var update = Builders <AccountModel> .Update.Set(x => x.LastChangeTime, DateTime.Now); accountCard = collection.FindOneAndUpdate <AccountModel>(filter, update); if (accountCard == null) { int gender = wXAccount.Gender == 1 ? 1 : wXAccount.Gender == 2 ? 2 : 3; //string avatarUrl = DownloadAvatar(wXAccount.AvatarUrl, wXAccount.OpenId); string avatarUrl = wXAccount.AvatarUrl; accountCard = new AccountModel() { OpenID = wXAccount.OpenId, HasRedPocket = false, AccountName = wXAccount.NickName, Gender = gender, AccountAvatar = avatarUrl, CreateTime = DateTime.Now, LastChangeTime = DateTime.Now }; collection.InsertOne(accountCard); } } int stautsCode = (int)(ActionParams.code_error); if (accountCard != null) { responseModel.JsonData = accountCard; stautsCode = (int)(ActionParams.code_ok); } responseModel.StatusCode = stautsCode; JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings(); string[] param = new string[] { "StatusCode", "JsonData", "AccountID", "HasRedPocket" }; jsonSerializerSettings.ContractResolver = new LimitPropsContractResolver(param); string jsonString = JsonConvert.SerializeObject(responseModel, jsonSerializerSettings); Console.WriteLine("json#####UserInfo:" + jsonString); return(jsonString); }
public string RequestLogin(string code, string iv, string encryptedData) { AccountCard accountCard = null; WXSmallAppCommon.Models.WXAccountInfo wXAccount = WXSmallAppCommon.WXInteractions.WXLoginAction.ProcessRequest(code, iv, encryptedData); if (wXAccount.openId != null) { var filter = Builders <AccountCard> .Filter.And(Builders <AccountCard> .Filter.Eq(x => x.OpenId, wXAccount.openId)); var collection = new MongoDBTool().GetMongoCollection <AccountCard>("AccountCard"); var update = Builders <AccountCard> .Update.Set(x => x.LastLoginTime, DateTime.Now); accountCard = collection.FindOneAndUpdate <AccountCard>(filter, update); if (accountCard == null) { accountCard = new AccountCard() { OpenId = wXAccount.openId, AccountName = wXAccount.nickName, Gender = wXAccount.gender, AvatarUrl = wXAccount.avatarUrl, City = wXAccount.city, Province = wXAccount.province, CreateTime = DateTime.Now, LastLoginTime = DateTime.Now }; collection.InsertOne(accountCard); } } BaseResponseModel <AccountCard> responseModel = new BaseResponseModel <AccountCard>(); int stautsCode = (int)(ActionParams.code_error); if (accountCard != null) { responseModel.JsonData = accountCard; stautsCode = (int)(ActionParams.code_ok); } responseModel.StatusCode = stautsCode; string jsonString = JsonConvert.SerializeObject(responseModel); Console.WriteLine("json**3:" + jsonString); return(jsonString); }