- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章微信公众号开发客服接口实例代码由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
最近,开发微信公众号,负责开发客服功能,这里简单记录下:
kf_account.cs代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
public
partial
class
kf_account : form
{
private
readonly datatable adt_user =
new
datatable();
private
readonly string as_inifile = application.startuppath +
"\\user.ini"
;
public
kf_account()
{
binduser();
}
private
void binduser()
{
if
(!file.exists(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"
);
//streamwriter sw = default(streamwriter);
//sw = file.createtext(ls_inifile);
//sw.writeline(str.tostring());
//sw.close();
file.writealltext(as_inifile, str.tostring(), encoding.unicode);
file.setattributes(as_inifile, fileattributes.hidden);
}
checkforillegalcrossthreadcalls = false;
initializecomponent();
icon = resource1.ico;
lkl_num.text = inifile.contentvalue(
"total"
,
"total"
, as_inifile);
lkl_num_c.text = inifile.contentvalue(
"count"
,
"count"
, as_inifile);
picturebox1.visible = true;
var
sr =
new
streamreader(as_inifile, encoding.unicode);
string line;
int li_count = 0;
adt_user.columns.clear();
adt_user.columns.add(
"username"
, type.
gettype
(
"system.string"
));
adt_user.columns.add(
"openid"
, type.
gettype
(
"system.string"
));
while
((line = sr.readline()) != null)
{
li_count++;
if
(li_count > 6)
{
line = sysvisitor.current.getformatstr(line);
datarow newrow;
newrow = adt_user.newrow();
newrow[
"username"
] = line.substring(0, line.lastindexof(
'='
));
newrow[
"openid"
] = line.substring(line.lastindexof(
'='
) + 1);
adt_user.rows.add(newrow);
}
}
sr.close();
datagridview1.autogeneratecolumns = false;
datagridview1.datasource = adt_user;
//datagridview1.autosizecolumnsmode = system.windows.forms.datagridviewautosizecolumnsmode.displayedcells;
lbl_count.text =
"共"
+ (li_count - 6) +
"行"
;
picturebox1.visible = false;
}
private
void btn_getuser_click(object sender, eventargs e)
{
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);
fs.close();
lab_nums.text =
"已拉取"
+ i +
"个,还剩"
+ (li_count - i) +
"个,请耐心等待"
;
}
lab_nums.text =
""
;
//binduser();
btn_getuser.enabled = true;
picturebox1.visible = false;
messagebox.show(
"已全部拉取完毕,请重新打开该窗口"
);
}
/// <summary>
/// 获取用户信息详情,返回json
/// </summary>
///<param name="as_openid">
private
string get_user(string as_openid)
{
string ls_json =
""
;
string access_token =
""
;
access_token = sysvisitor.current.get_access_token();
ls_json =
sysvisitor.current.getpageinfo(
"https://api.weixin.qq.com/cgi-bin/user/info?access_token="
+ access_token +
"&openid="
+ as_openid +
"&lang=zh_cn"
);
return
ls_json;
}
/// <summary>
/// 获取用户用户的昵称
/// </summary>
private
string get_username(string as_openid)
{
string ls_json =
""
;
ls_json = get_user(as_openid);
string username =
""
;
jobject json = jobject.parse(ls_json);
username = json[
"nickname"
].tostring();
username = sysvisitor.current.getformatstr(username);
return
username;
}
private
void btn_search_click(object sender, eventargs e)
{
string username = txt_search.text.trim();
if
(string.isnullorwhitespace(username))
{
return
;
}
datarow[] datarows = adt_user.select(
"username like '%"
+ username +
"%'"
);
var
ldt =
new
datatable();
ldt.columns.clear();
ldt.columns.add(
"username"
, type.
gettype
(
"system.string"
));
ldt.columns.add(
"openid"
, type.
gettype
(
"system.string"
));
ldt = todatatable(datarows);
try
{
lbl_count.text = ldt.rows.
count
.tostring();
}
catch
{
}
datagridview1.autogeneratecolumns = false;
datagridview1.datasource = ldt;
}
public
datatable todatatable(datarow[] rows)
{
if
(rows == null || rows.length == 0)
return
null;
datatable tmp = rows[0].table.
clone
();
// 复制datarow的表结构
foreach
(datarow row in rows)
tmp.rows.add(row.itemarray);
// 将datarow添加到datatable中
return
tmp;
}
private
void datagridview1_cellmouseclick(object sender, datagridviewcellmouseeventargs e)
{
try
{
sysvisitor.current.wx_openid =
datagridview1.rows[datagridview1.currentcell.rowindex].cells[1].value.tostring();
sysvisitor.current.wx_username =
datagridview1.rows[datagridview1.currentcell.rowindex].cells[0].value.tostring();
//messagebox.show(str);
grb_chat.enabled = true;
grb_chat.text = sysvisitor.current.wx_username;
}
catch
{
}
webbrowser_msg.documenttext =
""
;
string url = string.format(
"https://api.weixin.qq.com/cgi-bin/customservice/getrecord?access_token={0}"
,
sysvisitor.current.get_access_token());
string ls_text = @
"{"
;
ls_text +=
"\"starttime\" : "
+ datetime.now.adddays(-3).ticks +
","
;
ls_text +=
"\"endtime\" : "
+ datetime.now.ticks +
","
;
ls_text +=
"\"openid\" : \""
+ sysvisitor.current.wx_openid +
"\","
;
ls_text +=
"\"pagesize\" : 1000,"
;
ls_text +=
"\"pageindex\" : 1,"
;
ls_text +=
"}"
;
string ls_history = sysvisitor.current.postpage(url, ls_text);
webbrowser_msg.documenttext = ls_history;
}
private
void btn_send_click(object sender, eventargs e)
{
string ls_msg = richtextbox_msg.text;
string ls_text = @
"{"
;
ls_text +=
"\"touser\":\""
+ sysvisitor.current.wx_openid +
"\","
;
ls_text +=
"\"msgtype\":\"text\","
;
ls_text +=
"\"text\":"
;
ls_text +=
"{"
;
ls_text +=
"\"content\":\""
+ ls_msg +
"\""
;
ls_text +=
"}"
;
ls_text +=
"}"
;
string url = string.format(
"https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}"
,
sysvisitor.current.get_access_token());
string ls_isright = sysvisitor.current.postpage(url, ls_text);
webbrowser_msg.documenttext += "
" + ls_isright + "
"; } private void btn_addkf_click(object sender, eventargs e) { string url = string.format("
https:
//api.weixin.qq.com/customservice/kfaccount/add?access_token={0}", sysvisitor.current.get_access_token()); //客服账号 设置 xxx@你的公众号 这样的格式才是正确的哟。 string ls_text = "{"; ls_text += "\"kf_account\":test2@gz-sisosoft,"; ls_text += "\"nickname\":\"客服2\","; ls_text += "\"password\":\"12345\","; ls_text += "}"; string ls_kf = @"{ 'kf_account' : 'test1@gz-sisosoft', 'nickname' : '客服1', 'password' : '123456', }"; string ls_isok = sysvisitor.current.postpage(url, ls_text); messagebox.show(ls_isok); } private void kf_account_load(object sender, eventargs e) { } }
|
sysvisitor.cs代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
class
sysvisitor
{
private
static
sysvisitor visit = null;
public
static
sysvisitor current
{
get
{
if
(visit == null)
visit =
new
sysvisitor();
return
visit;
}
}
/// <summary>
/// 获取access_token
/// </summary>
///<param name="appid">appid
///<param name="secret">appsecret
/// <returns></returns>
public
string get_access_token(string appid, string appsecret)
{
string secondappid = inifile.contentvalue(
"weixin"
,
"secondappid"
);
if
(appid.tolower() == secondappid.tolower())
{
string ls_time = inifile.contentvalue(
"weixin"
,
"gettime"
);
decimal ldt;
try
{
ldt = convert.todecimal(ls_time);
if
(convert.todecimal(datetime.now.tostring(
"yyyymmddhhmmss"
)) - ldt < 7100)
//每两个小时刷新一次
{
return
inifile.contentvalue(
"weixin"
,
"access_token"
);
}
}
catch
{ }
}
string ls_appid = appid.replace(
" "
,
""
);
string ls_secret = appsecret.replace(
" "
,
""
);
string access_token =
""
;
string url = string.format(
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}"
, ls_appid, ls_secret);
string json_access_token = getpageinfo(url);
//datatable dt = json.jsontodatatable(json_access_token);
datatable dt = jsonhelper.jsontodatatable(json_access_token);
try
{
access_token = dt.rows[0][
"access_token"
].tostring();
}
catch
{
return
""
;
}
inifile.setinistring(
"weixin"
,
"gettime"
, datetime.now.tostring(
"yyyymmddhhmmss"
));
inifile.setinistring(
"weixin"
,
"access_token"
, access_token);
inifile.setinistring(
"weixin"
,
"secondappid"
, ls_appid);
return
access_token;
}
/// <summary>
/// 获取access_token
/// </summary>
public
string get_access_token()
{
string ls_appid = inifile.contentvalue(
"weixin"
,
"appid"
);
string ls_secret = inifile.contentvalue(
"weixin"
,
"appsecret"
);
return
get_access_token(ls_appid, ls_secret);
}
/// <summary>
/// get方法请求url并接收返回消息
/// </summary>
///<param name="strurl">url地址
/// <returns></returns>
public
string getpageinfo(string url)
{
httpwebrequest request = (httpwebrequest)httpwebrequest.create(url);
httpwebresponse response = (httpwebresponse)request.getresponse();
string ret = string.
empty
;
stream s;
string strdate =
""
;
string strvalue =
""
;
if
(response.statuscode == httpstatuscode.ok)
{
s = response.getresponsestream();
////在这儿处理返回的文本
streamreader reader =
new
streamreader(s, encoding.utf8);
while
((strdate = reader.readline()) != null)
{
strvalue += strdate +
"\r\n"
;
}
//strvalue = reader.readtoend();
}
return
strvalue;
}
/// <summary>
/// post方法
/// </summary>
///<param name="posturl">url
///<param name="postdata">post数据
/// <returns></returns>
public
string postpage(string posturl, string postdata)
{
stream outstream = null;
stream instream = null;
streamreader sr = null;
httpwebresponse response = null;
httpwebrequest request = null;
encoding encoding = encoding.utf8;
byte[] data = encoding.getbytes(postdata);
// 准备请求...
try
{
// 设置参数
request = webrequest.create(posturl)
as
httpwebrequest;
cookiecontainer cookiecontainer =
new
cookiecontainer();
request.cookiecontainer = cookiecontainer;
request.allowautoredirect = true;
request.method =
"post"
;
request.contenttype =
"application/x-www-form-urlencoded"
;
request.contentlength = data.length;
outstream = request.getrequeststream();
outstream.write(data, 0, data.length);
outstream.close();
//发送请求并获取相应回应数据
response = request.getresponse()
as
httpwebresponse;
//直到request.getresponse()程序才开始向目标网页发送post请求
instream = response.getresponsestream();
sr =
new
streamreader(instream, encoding);
//返回结果网页(html)代码
string content = sr.readtoend();
string err = string.
empty
;
return
content;
}
catch
(exception ex)
{
string err = ex.message;
return
string.
empty
;
}
}
/// <summary>
/// 格式化字符串
/// </summary>
///<param name="str">
/// <returns></returns>
public
string getformatstr(string str)
{
if
(
""
== str)
return
""
;
else
{
str = str.trim();
str = str.replace(
"'"
,
"'"
);
str = str.replace(
"〈"
,
"<"
);
str = str.replace(
"〉"
,
">"
);
str = str.replace(
","
,
","
);
return
str;
}
}
string ls_username =
""
;
/// <summary>
/// 用户名
/// </summary>
public
string wx_username
{
get
{
return
ls_username;
}
set
{
ls_username = value;
}
}
string ls_openid =
""
;
/// <summary>
/// openid
/// </summary>
public
string wx_openid
{
get
{
return
ls_openid;
}
set
{
ls_openid = value;
}
}
}
|
inifile.cs代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
class
inifile
{
///// <summary>
///// 设置ini文件参数
///// </summary>
/////<param name="section">ini文件中的段落
/////<param name="key">ini文件中的关键字
/////<param name="val">ini文件中关键字的数值
/////<param name="filepath">ini文件的完整的路径和名称
///// <returns></returns>
//[dllimport("kernel32")]
//private static extern long writeprivateprofilestring(
// string section, string key, string val, string filepath);
///// <summary>
///// 获取ini文件参数
///// </summary>
/////<param name="section">ini文件中的段落名称
/////<param name="key">ini文件中的关键字
/////<param name="def">无法读取时候时候的缺省数值
/////<param name="retval">读取数值
/////<param name="size">数值的大小
/////<param name="filepath">ini文件的完整路径和名称
//[dllimport("kernel32")]
//private static extern int getprivateprofilestring(
// string section, string key, string def, stringbuilder retval, int size, string filepath);
//static string gs_filename = system.appdomain.currentdomain.basedirectory + "config.ini";
///// <summary>
///// 获取ini文件参数
///// </summary>
/////<param name="as_section">ini文件中的段落名称
/////<param name="as_key">ini文件中的关键字
/////<param name="as_filename">ini文件的完整路径和名称
//public static string getinistring(string as_section, string as_key, string as_filename)
//{
// stringbuilder temp = new stringbuilder(255);
// int i = getprivateprofilestring(as_section, as_key, "", temp, 255, as_filename);
// return temp.tostring();
//}
///// <summary>
///// 获取ini文件参数
///// </summary>
/////<param name="as_section">ini文件中的段落名称
/////<param name="as_key">ini文件中的关键字
/////<param name="as_filename">ini文件的完整路径和名称
//public static string getinistring(string as_section, string as_key)
//{
// return getinistring(as_section, as_key, gs_filename);
//}
///// <summary>
///// 设置ini文件参数
///// </summary>
/////<param name="as_section">ini文件中的段落
/////<param name="as_key">ini文件中的关键字
/////<param name="as_value">ini文件中关键字的数值
/////<param name="as_filename">ini文件的完整路径和名称
//public static long setinistring(string as_section, string as_key, string as_value, string as_filename)
//{
// return writeprivateprofilestring(as_section, as_key, as_value, as_filename);
//}
///// <summary>
///// 设置ini文件参数
///// </summary>
/////<param name="as_section">ini文件中的段落
/////<param name="as_key">ini文件中的关键字
/////<param name="as_value">ini文件中关键字的数值
//public static long setinistring(string as_section, string as_key, string as_value)
//{
// return setinistring(as_section, as_key, as_value, gs_filename);
//}
/// <summary>
/// 写入ini文件
/// </summary>
///<param name="section">节点名称[如[typename]]
///<param name="key">键
///<param name="val">值
///<param name="filepath">文件路径
/// <returns></returns>
[dllimport(
"kernel32"
)]
public
static
extern long writeprivateprofilestring(string section, string key, string val, string filepath);
[dllimport(
"kernel32.dll"
)]
public
extern
static
int getprivateprofilesectionnamesa(byte[] buffer, int ilen, string filename);
/// <summary>
/// 写入ini文件(section:节点名称 key:键 val:值)
/// </summary>
///<param name="section">节点名称
///<param name="key">键
///<param name="val">值
/// <returns></returns>
public
static
long setinistring(string section, string key, string val, string as_filepath =
""
)
{
if
(as_filepath ==
""
)
{
return
(writeprivateprofilestring(section, key, val, strfilepath));
}
else
{
return
(writeprivateprofilestring(section, key, val, as_filepath));
}
}
/// <summary>
/// 读取ini文件
/// </summary>
///<param name="section">节点名称
///<param name="key">键
///<param name="def">值
///<param name="retval">stringbulider对象
///<param name="size">字节大小
///<param name="filepath">文件路径
/// <returns></returns>
[dllimport(
"kernel32"
)]
public
static
extern int getprivateprofilestring(string section, string key, string def, stringbuilder retval, int size, string filepath);
public
static
string strfilepath = application.startuppath +
"\\config.ini"
;
//获取ini文件默认路径
public
static
string strsec =
""
;
//ini文件名
/// <summary>
/// 读取ini文件中的内容方法 (section 节点名称;key 键)
/// </summary>
///<param name="section">节点名称
///<param name="key">键
/// <returns></returns>
public
static
string contentvalue(string section, string key, string as_filepath =
""
)
{
stringbuilder temp =
new
stringbuilder(1024);
if
(as_filepath ==
""
)
{
getprivateprofilestring(section, key,
""
, temp, 1024, strfilepath);
}
else
{
getprivateprofilestring(section, key,
""
, temp, 1024, as_filepath);
}
return
temp.tostring();
}
/// <summary>
/// 获取指定小节所有项名和值的一个列表
/// </summary>
///<param name="section">节 段,欲获取的小节。注意这个字串不区分大小写
///<param name="buffer">缓冲区 返回的是一个二进制的串,字符串之间是用"\0"分隔的
///<param name="nsize">缓冲区的大小
///<param name="filepath">初始化文件的名字。如没有指定完整路径名,windows就在windows目录中查找文件
/// <returns></returns>
[dllimport(
"kernel32"
)]
public
static
extern int getprivateprofilesection(string section, byte[] buffer, int nsize, string filepath);
/// <summary>
/// 获取指定段section下的所有键值对 返回集合的每一个键形如"key=value"
/// </summary>
///<param name="section">指定的段落
///<param name="filepath">ini文件的绝对路径
/// <returns></returns>
public
static
list<string> readkeyvalues(string section, string as_filepath =
""
)
{
byte[] buffer =
new
byte[32767];
list<string> list =
new
list<string>();
int length = 0;
if
(as_filepath ==
""
)
{
length = getprivateprofilesection(section, buffer, buffer.getupperbound(0), strfilepath);
}
else
{
length = getprivateprofilesection(section, buffer, buffer.getupperbound(0), as_filepath);
}
string temp;
int postion = 0;
for
(int i = 0; i < length; i++)
{
if
(buffer[i] == 0x00)
//以'\0'来作为分隔
{
temp = system.text.asciiencoding.
default
.getstring(buffer, postion, i - postion).trim();
postion = i + 1;
if
(temp.length > 0)
{
list.add(temp);
}
}
}
return
list;
}
/// <summary>
/// 删除指定的key
/// </summary>
///<param name="section">要写入的段落名
///<param name="key">要删除的键
///<param name="filename">ini文件的完整路径和文件名
public
static
void delkey(string section, string key, string as_filepath =
""
)
{
if
(as_filepath ==
""
)
{
writeprivateprofilestring(section, key, null, strfilepath);
}
else
{
writeprivateprofilestring(section, key, null, as_filepath);
}
}
/// <summary>
/// 返回该配置文件中所有section名称的集合
/// </summary>
public
static
arraylist readsections()
{
byte[] buffer =
new
byte[65535];
int rel = getprivateprofilesectionnamesa(buffer, buffer.getupperbound(0), strfilepath);
int icnt, ipos;
arraylist arraylist =
new
arraylist();
string tmp;
if
(rel > 0)
{
icnt = 0; ipos = 0;
for
(icnt = 0; icnt < rel; icnt++)
{
if
(buffer[icnt] == 0x00)
{
tmp = system.text.asciiencoding.utf8.getstring(buffer, ipos, icnt - ipos).trim();
ipos = icnt + 1;
if
(tmp !=
""
)
arraylist.add(tmp);
}
}
}
return
arraylist;
}
}</string></string></string>
|
运行结果
这里写图片描述 。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持! 。
最后此篇关于微信公众号开发客服接口实例代码的文章就讲到这里了,如果你想了解更多关于微信公众号开发客服接口实例代码的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我尝试理解[c代码 -> 汇编]代码 void node::Check( data & _data1, vector& _data2) { -> push ebp -> mov ebp,esp ->
我需要在当前表单(代码)的上下文中运行文本文件中的代码。其中一项要求是让代码创建新控件并将其添加到当前窗体。 例如,在Form1.cs中: using System.Windows.Forms; ..
我有此 C++ 代码并将其转换为 C# (.net Framework 4) 代码。有没有人给我一些关于 malloc、free 和 sprintf 方法的提示? int monate = ee; d
我的网络服务器代码有问题 #include #include #include #include #include #include #include int
给定以下 html 代码,将列表中的第三个元素(即“美丽”一词)以斜体显示的 CSS 代码是什么?当然,我可以给这个元素一个 id 或一个 class,但 html 代码必须保持不变。谢谢
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
我试图制作一个宏来避免重复代码和注释。 我试过这个: #define GrowOnPage(any Page, any Component) Component.Width := Page.Surfa
我正在尝试将我的旧 C++ 代码“翻译”成头条新闻所暗示的 C# 代码。问题是我是 C# 中的新手,并不是所有的东西都像 C++ 中那样。在 C++ 中这些解决方案运行良好,但在 C# 中只是不能。我
在 Windows 10 上工作,R 语言的格式化程序似乎没有在 Visual Studio Code 中完成它的工作。我试过R support for Visual Studio Code和 R-T
我正在处理一些报告(计数),我必须获取不同参数的计数。非常简单但乏味。 一个参数的示例查询: qCountsEmployee = ( "select count(*) from %s wher
最近几天我尝试从 d00m 调试网络错误。我开始用尽想法/线索,我希望其他 SO 用户拥有可能有用的宝贵经验。我希望能够提供所有相关信息,但我个人无法控制服务器环境。 整个事情始于用户注意到我们应用程
我有一个 app.js 文件,其中包含如下 dojo amd 模式代码: require(["dojo/dom", ..], function(dom){ dom.byId('someId').i
我对“-gencode”语句中的“code=sm_X”选项有点困惑。 一个例子:NVCC 编译器选项有什么作用 -gencode arch=compute_13,code=sm_13 嵌入库中? 只有
我为我的表格使用 X-editable 框架。 但是我有一些问题。 $(document).ready(function() { $('.access').editable({
我一直在通过本教程学习 flask/python http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-wo
我想将 Vim 和 EMACS 用于 CNC、G 代码和 M 代码。 Vim 或 EMACS 是否有任何语法或模式来处理这种类型的代码? 最佳答案 一些快速搜索使我找到了 this vim 和 thi
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve this
这个问题在这里已经有了答案: Enabling markdown highlighting in Vim (5 个回答) 6年前关闭。 当我在 Vim 中编辑包含 Markdown 代码的 READM
我正在 Swift3 iOS 中开发视频应用程序。基本上我必须将视频 Assets 和音频与淡入淡出效果合并为一个并将其保存到 iPhone 画廊。为此,我使用以下方法: private func d
pipeline { agent any stages { stage('Build') { steps { e
我是一名优秀的程序员,十分优秀!