{
if (MessageBox.Show(@"拉取用户信息的速度取决于你的关注数与网络速度,
可能需要几分钟甚至更长时间。
使用此功能将消耗大量用户管理接口配额。
要继续此操作吗?",
"提示:", MessageBoxButtons.YesNo) == DialogResult.No)
{
return;
}
var thr = new Thread(Get_user_list);
thr.Start();
}
private void Get_user_list()
{
File.Delete(as_INIFile);
var str = new StringBuilder();
str.Append(";内容由程序自动生成,请不要修改此文件内容\r\n");
str.Append("[total]\r\n");
str.Append("total=\r\n");
str.Append("[count]\r\n");
str.Append("count=\r\n");
str.Append("[user]\r\n");
File.WriteAllText(as_INIFile, str.ToString(), Encoding.Unicode);
File.SetAttributes(as_INIFile, FileAttributes.Hidden);
string ls_appid = INIFile.ContentValue("weixin", "Appid");
string ls_secret = INIFile.ContentValue("weixin", "AppSecret");
string access_token = "";
string menu = "";
if (ls_appid.Length != 18 || ls_secret.Length != 32)
{
MessageBox.Show("你的Appid或AppSecret不对,请检查后再操作");
return;
}
access_token = SysVisitor.Current.Get_Access_token(ls_appid, ls_secret);
if (access_token == "")
{
MessageBox.Show("Appid或AppSecret不对,请检查后再操作");
return;
}
menu = SysVisitor.Current.GetPageInfo("https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + access_token);
if (menu.Substring(2, 7) == "errcode")
{
MessageBox.Show("拉取失败,返回消息:\r\n" + menu);
}
JObject json = JObject.Parse(menu);
lkl_num.Text = json["total"].ToString();
INIFile.SetINIString("total", "total", lkl_num.Text, as_INIFile);
lkl_num_c.Text = json["count"].ToString();
INIFile.SetINIString("count", "count", lkl_num_c.Text, as_INIFile);
int li_count = int.Parse(json["count"].ToString());
btn_GetUser.Enabled = false;
pictureBox1.Visible = true;
FileStream fs = null;
Encoding encoder = Encoding.Unicode;
for (int i = 0; i < li_count; i++)
{
string openid, username;
openid = Get_UserName(json["data"]["openid"][i].ToString());
username = json["data"]["openid"][i].ToString();
//INIFile.SetINIString("user", openid, username, as_INIFile);
byte[] bytes = encoder.GetBytes(openid + "=" + username + " \r\n");
fs = File.OpenWrite(as_INIFile);
//设定书写的開始位置为文件的末尾
fs.Position = fs.Length;
//将待写入内容追加到文件末尾
fs.Write(bytes, 0, bytes.Length);
评论0
最新资源