123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net.Http;
- using Codeplex.Data;
- namespace LYFZ.Weixin.SDK
- {
-
-
-
-
-
- public class UserAdminAPI
- {
-
-
-
-
-
-
-
- public static bool CreateGroup(string access_token, string name)
- {
- var builder = new StringBuilder();
- builder.Append("{")
- .Append('"' + "group" + '"' + ":")
- .Append("{")
- .Append('"' + "name" + '"' + ":").Append(name)
- .Append("}")
- .Append("}");
- var client = new HttpClient();
- var result = client.PostAsync(string.Format("https://api.weixin.qq.com/cgi-bin/groups/create?access_token={0}", access_token), new StringContent(builder.ToString())).Result;
- return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result).errcode == 0;
- }
-
-
-
-
-
- public static dynamic GetGroups(string access_token)
- {
- var client = new HttpClient();
- var result = client.PostAsync(string.Format("https://api.weixin.qq.com/cgi-bin/groups/get?access_token={0}", access_token), new StringContent("")).Result;
- if (!result.IsSuccessStatusCode) return null;
- return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result);
- }
-
-
-
-
-
-
- public static string GetUserGroup(string access_token, string openid)
- {
- var builder = new StringBuilder();
- builder.Append("{").Append('"' + "openid" + '"' + ":").Append(openid).Append("}");
- var client = new HttpClient();
- var result = client.PostAsync(string.Format("https://api.weixin.qq.com/cgi-bin/groups/getid?access_token={0}", access_token), new StringContent(builder.ToString())).Result;
- if (!result.IsSuccessStatusCode) return string.Empty;
- return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result).groupid;
- }
-
-
-
-
-
-
-
- public static bool UpdateGroup(string access_token, string id, string name)
- {
- var builder = new StringBuilder();
- builder.Append("{")
- .Append('"' + "group" + '"' + ":")
- .Append("{")
- .Append('"' + "id" + '"' + ":").Append(id).Append(",")
- .Append('"' + "name" + '"' + ":").Append(name)
- .Append("}")
- .Append("}");
- var client = new HttpClient();
- var result = client.PostAsync(string.Format("https://api.weixin.qq.com/cgi-bin/groups/update?access_token={0}", access_token), new StringContent(builder.ToString())).Result;
- return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result).errcode == 0;
- }
-
-
-
-
-
-
-
- public static bool MoveGroup(string access_token, string openid, string to_groupid)
- {
- var builder = new StringBuilder();
- builder.Append("{")
- .Append('"' + "openid" + '"' + ":").Append(openid).Append(",")
- .Append('"' + "to_groupid" + '"' + ":").Append(to_groupid)
- .Append("}");
- var client = new HttpClient();
- var result = client.PostAsync(string.Format("https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token={0}", access_token), new StringContent(builder.ToString())).Result;
- return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result).errcode == 0;
- }
-
-
-
-
-
-
-
- public static bool SetRemark(string access_token, string openid, string remark)
- {
- var builder = new StringBuilder();
- builder.Append("{")
- .Append('"' + "openid" + '"' + ":").Append(openid).Append(",")
- .Append('"' + "remark" + '"' + ":").Append(remark)
- .Append("}");
- var client = new HttpClient();
- var result = client.PostAsync(string.Format("https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token={0}", access_token), new StringContent(builder.ToString())).Result;
- return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result).errcode == 0;
- }
-
-
-
-
-
-
-
-
- public static dynamic GetInfo(string access_token, string openId)
- {
- var client = new HttpClient();
- var result = client.GetAsync(string.Format("https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN", access_token, openId)).Result;
- if (!result.IsSuccessStatusCode) return null;
- return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result);
- }
-
-
-
-
-
-
- public static dynamic GetSubscribes(string access_token, string nextOpenId)
- {
- var client = new HttpClient();
- var result = client.GetAsync(string.Format("https://api.weixin.qq.com/cgi-bin/user/get?access_token={0}&next_openid={1}", access_token, nextOpenId)).Result;
- if (!result.IsSuccessStatusCode) return null;
- return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result);
- }
- }
- }
|