根据前辈微信公众号菜单操作实例代码
定义:内部HTTPPOST函数
'定义POST函数
Dim url As String = Args(0) 'post的接口地址
Dim postStream As System.IO.Stream = Args(1) '向接口POST的数据流
Dim encoding As System.Text.Encoding = System.Text.Encoding.GetEncoding("utf-8")'编码格式
Dim sresult As String
Dim request As System.Net.HttpWebRequest = DirectCast(System.Net.WebRequest.Create(url), System.Net.HttpWebRequest)
request.Method = "POST"
request.Timeout = Vars("TimeOut")
'设置标头
request.C
request.ContentLength = IIf(Not postStream Is Nothing, postStream.Length, 0)
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
request.KeepAlive = True
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36"
'向接口POST数据
If (Not postStream Is Nothing) Then
postStream.Position = 0
Dim requestStream As System.IO.Stream = request.GetRequestStream
Dim buffer4 As Byte() = New Byte(&H400 - 1) {}
Dim num3 As Integer = postStream.Read(buffer4, 0, buffer4.Length)
Do While (num3 <> 0)
requestStream.Write(buffer4, 0, num3)
num3 = postStream.Read(buffer4, 0, buffer4.Length)
Loop
postStream.Close()
End If
'获取接口的返回值
Dim response As System.Net.HttpWebResponse = DirectCast(request.GetResponse, System.Net.HttpWebResponse)
Using stream3 As System.IO.Stream = response.GetResponseStream
Using reader As System.IO.StreamReader = New System.IO.StreamReader(stream3, encoding)
sresult = reader.ReadToEnd
End Using
End Using
Return sresult
调用内部HttpPost函数,实现POST提交数据修改菜单
If MessageBox.Show("提交后会覆盖原有的菜单,确定要提交?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
Dim menujsonstring As String = Functions.Execute("GetMenuJson") ' 获取菜单Json
Dim accesstoken = Functions.Execute("GetAccessToken") '获取AccessToken
'定义接口url
Dim url = String.Format("https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}", accesstoken.access_token)
'把菜单Json序列化到内存流
Using ms As New System.IO.MemoryStream()
Dim bytes = ConvertHelper.EncodingToBytes(menujsonstring, System.Text.Encoding.UTF8)
ms.Write(bytes, 0, bytes.Length)
ms.Seek(0, System.IO.SeekOrigin.Begin)
Dim jsonString = Functions.Execute("HttpPost",url, ms) '通过POST向接口传输菜单数据,并取得返回结果
Dim mresult = ConvertHelper.FromJson(Of MmsgResult)(jsonString)
If mresult.errcode = ReturnCode.请求成功 Then
Functions.Execute("LogText","成功创建菜单!")
msgbox("成功创建菜单!")
Else
Functions.Execute("LogText","创建菜单失败!错误代码: " & mresult.errcode & ";错误原因:" & mresult.errmsg)
msgbox("创建菜单失败!错误代码: " & mresult.errcode & ";错误原因:" & mresult.errmsg)
End If
End Using
End If
接口调用请求说明
接口分析数据接口(包括接口列表中的所有接口)需要向相应接口调用地址POST以下示例数据包:
{
"begin_date": "2014-12-07",
"end_date": "2014-12-07"
}
调用参数说明
想对应修改到获取图文群发每日数据,怎么操作呢?烦请各位大大指导下!谢谢
下面是仿写 结果总报错 烦请指导 谢谢
Dim xmlhttp= CreateObject("msxml2.xmlhttp")
With xmlhttp
.open ("POST", "https://api.weixin.qq.com/datacube/getarticlesummary?access_token=ACCESS_TOKEN", False)
.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded")
.send ("&"begin_date": "2014-12-07","end_date": "2014-12-07"")
MsgBox .responseText '显示POST之后网页返回的结果
End With
Set xmlhttp = Nothing
[此贴子已经被作者于2016/10/9 21:40:42编辑过]