private GetContactResponse GetContact(string url) { GetContactResponse contactResponse = new GetContactResponse(); Synergy.Common.Request.WebClient client = new Synergy.Common.Request.WebClient(); HttpWebResponse response = client.Get(GetUrl(url), EnumUtilities.GetDescriptionFromEnumValue(ContentTypes.JSON), GetAuthorization()); if (response.StatusCode == HttpStatusCode.OK) { var responseStream = response.GetResponseStream(); StreamReader streamReader = new StreamReader(responseStream); string rawResponse = streamReader.ReadToEnd(); var Contact = JsonConvert.DeserializeObject <Contact>(rawResponse); contactResponse.Contact = Contact; contactResponse.Status = Status.Success; } else { var responseStream = response.GetResponseStream(); StreamReader streamReader = new StreamReader(responseStream); string rawResponse = streamReader.ReadToEnd(); contactResponse.Status = Status.Error; contactResponse.Message = rawResponse; } return(contactResponse); }
/// <summary> /// 读取用户的联系人列表,其中只包含公众号,个人号,如果返回值seq不为0,那么用户列表还没获取完(因为可能会有几千人的号,不可能一次获取完),则附带上seq的值继续获取。 /// </summary> private void GetContact() { try { //获取联系人列表 finishGetContactList = false; string getContactUrl = string.Format(host + "/cgi-bin/mmwebwx-bin/webwxgetcontact?r={0}&seq={1}&skey={2}", Utils.GetJavaTimeStamp(), 0, baseRequest.Skey); while (!finishGetContactList) { string contactResult = httpClient.GetStringOnce(getContactUrl); GetContactResponse getContactResponse = JsonConvert.DeserializeObject<GetContactResponse>(contactResult); asyncOperation.Post( new SendOrPostCallback((list) => { GetContactComplete?.Invoke(this, new TEventArgs<List<Contact>>((List<Contact>)list)); }), getContactResponse.MemberList); if (getContactResponse.Seq == 0) { finishGetContactList = true; } else { getContactUrl = string.Format(host + "/cgi-bin/mmwebwx-bin/webwxgetcontact?r={0}&seq={1}&skey={2}", Utils.GetJavaTimeStamp(), getContactResponse.Seq, baseRequest.Skey); } } //获取完联系人中的公众号,才能获得名称,这个时候再发送图文消息事件。 asyncOperation.Post( new SendOrPostCallback((obj) => { MPSubscribeMsgListComplete?.Invoke(this, new TEventArgs<List<MPSubscribeMsg>>((List<MPSubscribeMsg>)obj)); }), mpSubscribeMsgList); } catch (Exception e) { if (e is WebException) { WebException we = e as WebException; if (we.Status == WebExceptionStatus.ProtocolError && ((HttpWebResponse)we.Response).StatusCode == HttpStatusCode.ServiceUnavailable) { //过千人账号有时候获取不到联系人列表,服务器返回503,官方测试结果也是反馈503导致获取不到,为了不影响正常使用,跳过获取联系人步骤 asyncOperation.Post( new SendOrPostCallback((obj) => { ExceptionCatched?.Invoke(this, new TEventArgs<Exception>((Exception)obj)); }), new GetContactException("无法获取好友列表")); } } else { asyncOperation.Post( new SendOrPostCallback((obj) => { ExceptionCatched?.Invoke(this, new TEventArgs<Exception>((Exception)obj)); }), e); } } }
void SendResultInfoAsJson(GetContactResponse res) { string strJson = JsonConvert.SerializeObject(res); Response.ContentType = "application/json; charset=utf-8"; Response.Write(strJson); Response.End(); }
private async Task GetContacts() { var contactsUrl = string.Format(UrlEndpoints.Contacts, _clientLoginResponse.BaseUri, _webLoginResponse.PassTicket, _webLoginResponse.Skey, Utility.ConvertDateTimeToInt(DateTime.Now)); var result = await _weChatMessageClient.Get(contactsUrl); _contactsResponse = JsonConvert.DeserializeObject <GetContactResponse>(result); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { GetContactResponse response = new GetContactResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("Contact", targetDepth)) { var unmarshaller = ContactUnmarshaller.Instance; response.Contact = unmarshaller.Unmarshall(context); continue; } } return response; }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { GetContactResponse response = new GetContactResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("Alias", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.Alias = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("ContactArn", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.ContactArn = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("DisplayName", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.DisplayName = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("Plan", targetDepth)) { var unmarshaller = PlanUnmarshaller.Instance; response.Plan = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("Type", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.Type = unmarshaller.Unmarshall(context); continue; } } return(response); }
public static GetContactResponse GetDefaultContact() { GetContactResponse response = new GetContactResponse(); using (ContactInfoDao dao = new ContactInfoDao()) { ContactInfo contact = dao.GetDefaultContact(); if (contact == null) { MakeNoConatctResponse(response); return response; } response.contact_details = new ContactDto(); response.contact_details.contact_id = contact.CinfoID; response.contact_details.description = string.IsNullOrEmpty(contact.Description) ? string.Empty : contact.Description; response.contact_details.image_name = string.IsNullOrEmpty(contact.ContactInfoImage) ? string.Empty : ImagePathService.contactInfoImagePath + contact.ContactInfoImage; response.code = 0; response.has_resource = 1; response.message = MessagesSource.GetMessage("conatct.found"); } return response; }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { GetContactResponse response = new GetContactResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("AttributesData", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.AttributesData = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("ContactListName", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.ContactListName = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("CreatedTimestamp", targetDepth)) { var unmarshaller = DateTimeUnmarshaller.Instance; response.CreatedTimestamp = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("EmailAddress", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.EmailAddress = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("LastUpdatedTimestamp", targetDepth)) { var unmarshaller = DateTimeUnmarshaller.Instance; response.LastUpdatedTimestamp = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("TopicDefaultPreferences", targetDepth)) { var unmarshaller = new ListUnmarshaller <TopicPreference, TopicPreferenceUnmarshaller>(TopicPreferenceUnmarshaller.Instance); response.TopicDefaultPreferences = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("TopicPreferences", targetDepth)) { var unmarshaller = new ListUnmarshaller <TopicPreference, TopicPreferenceUnmarshaller>(TopicPreferenceUnmarshaller.Instance); response.TopicPreferences = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("UnsubscribeAll", targetDepth)) { var unmarshaller = BoolUnmarshaller.Instance; response.UnsubscribeAll = unmarshaller.Unmarshall(context); continue; } } return(response); }
public NegotiatedContentResult <GetContactResponse> GetContact() { GetContactResponse resp = ContactServices.GetDefaultContact(); return(Content(HttpStatusCode.OK, resp)); }
protected void Page_Load(object sender, EventArgs e) { GetContactRequest req; GetContactResponse res = new GetContactResponse(); res.error = String.Empty; // 1. Deserialize the incoming Json. try { req = GetRequestInfo(); } catch (Exception ex) { res.error = ex.Message.ToString(); // Return the results as Json. SendResultInfoAsJson(res); return; } SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); try { connection.Open(); string sql = String.Format("SELECT ContactID, FirstName, LastName, Phone, Email FROM ContactUser.Contacts WHERE CreatedBy = {0}", req.userId); SqlCommand command = new SqlCommand(sql, connection); SqlDataReader reader = command.ExecuteReader(); res.contacts = new List <Contact>(); if (reader.HasRows) { while (reader.Read()) { Contact c = new Contact(); c.ContactID = Convert.ToInt32(reader["ContactID"]); c.firstName = Convert.ToString(reader["FirstName"]); c.lastName = Convert.ToString(reader["LastName"]); c.phone = Convert.ToString(reader["Phone"]); c.email = Convert.ToString(reader["Email"]); res.contacts.Add(c); } } reader.Close(); } catch (Exception ex) { res.error = ex.Message.ToString(); } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } // Return the results as Json. SendResultInfoAsJson(res); }
private void ContactEvent(GetContactResponse response) { try { if (response != null && response.contact != null && response.contact.Count > 0) { System.Collections.Generic.List<RecentLinkInfo> list = this.dataModel.RecentLinkInfoList; foreach (Contact contact in response.contact) { if (contact != null) { list.Add(new RecentLinkInfo { Id = contact.id, RecentTime = contact.createTime, Type = (IsMarkType)System.Enum.Parse(typeof(IsMarkType), response.type.ToString()) }); } } list.Sort(new System.Comparison<RecentLinkInfo>(LocalDataUtil.Instance.CompareRecentLinkValue)); } } catch (System.Exception e) { this.logger.Error(e.ToString()); } }