private async Task UpdateUser(string userId, string access_token) { //查询 var first = _middleDB.WechatEeappUser.FirstOrDefault(w => w.UserId == userId); //理论上不会出现找到的情况 if (first != null) { //每天更新一次 if (DateTime.Now < (first.UpdateTime ?? DateTime.Now).AddDays(1)) { return; } //获取通讯录 var userGet = await WxEEContext.UserApi.GetContactUser(access_token, userId); if (userGet.errcode != 0) { return; } //更新 first.Name = userGet.name; //修改岗位 first.Position = userGet.position; first.Mobile = userGet.mobile; first.Gender = userGet.gender == 1; first.Email = userGet.email; first.Avatar = userGet.avatar; first.QrCode = userGet.qr_code; first.UpdateTime = DateTime.Now; if (string.IsNullOrEmpty(first.Openid)) { //转OpenId var convert = await WxEEContext.UserApi.UserIdToOpenId(access_token, userId); first.Openid = convert.errcode == 0 ? convert.openid : convert.errmsg; } } await _middleDB.SaveChangesAsync(); }