菜单接口
企业微信不同的应用,可以设置不同的菜单,所以在调用企业微信的菜单接口时,除了提交AccessTokn,还需要提交AgentId(应用ID)。
实际开发额时候,可以设计一个窗口,用于 菜管理菜单:
"设置菜单"按钮的代码为:
Dim
ul As
String =
"https://qyapi.weixin.qq.com/cgi-bin/menu/create?access_token={0}&agentid={1}"
Dim
AccessToken =
Functions.Execute("GetQYAccessToken")
'AccessTiken
Dim
AgentId As
String = e.Form.Controls("NumericComboBox1").Value
'应用ID
Dim
MenuJson As
String = e.Form.Controls("TextBox1").Value
'在文本框中输入的Json格式的菜单
Dim
hc As
New HttpClient(CExp(ul,
AccessToken, AgentId))
hc.Content
= MenuJson
Dim
jo As
JObject = JObject.Parse(hc.GetData)
If
jo("errcode")
= "0" Then
MessageBox.Show("菜单设置成功!")
Else
MessageBox.Show(jo.ToString)
End
If
"删除菜单"按钮的代码为:
Dim
ul As
String =
"https://qyapi.weixin.qq.com/cgi-bin/menu/delete?access_token={0}&agentid={1}"
Dim
AccessToken =
Functions.Execute("GetQYAccessToken")
'AccessTiken
Dim
AgentId As
String = e.Form.Controls("NumericComboBox1").Value
'应用ID
Dim
hc As
New HttpClient(CExp(ul,
AccessToken, AgentId))
Dim
jo As
JObject = JObject.Parse(hc.GetData)
If
jo("errcode")
= "0" Then
MessageBox.Show("菜单已经删除!")
Else
MessageBox.Show(jo.ToString)
End
If
"提取菜单"按钮用于提取现有菜单设置,其代码为:
Dim
ul As
String =
"https://qyapi.weixin.qq.com/cgi-bin/menu/get?access_token={0}&agentid={1}"
Dim
AccessToken =
Functions.Execute("GetQYAccessToken")
'AccessTiken
Dim
AgentId As
String = e.Form.Controls("NumericComboBox1").Value
'应用ID
Dim
hc As
New HttpClient(CExp(ul,
AccessToken, AgentId))
Dim
jo As
JObject = JObject.Parse(hc.GetData)
If
jo("menu")
IsNot Nothing
Then
e.Form.Controls("TextBox1").Value
= jo("menu").ToString()
Else
MessageBox.Show(jo.ToString)
End
If
实际测试的时候,发现必须先给应用开启回调(接入HTTP服务)才能为其设置菜单。