微信公众平台 是腾讯公司在微信的基础上新增的功能模块,通过这一平台,个人和企业都可以打造一个微信的公众号,并实现和特定群体的文字、图片、语音的全方位沟通、互动。
发布方式
它的最重要的发布和订阅方式,都在设置中会找到一个如下格式的二维码,品牌 ID 放到二维码的中部。 你也可以有其他方式来订阅微信公众帐号。比如,通过微信号进行订阅,在微信上直接点按“添加朋友”——“按号码查找”,输入“帐号(字母,数字,下划数组合且必须以字母开头)”就可以查找并关注您感兴趣的内容。但是对于开放申请的微信公众号,大部分微信号格式类似wangluowenzhai这样的英文数字结合组成的微信号,并不利于记忆和查找(此外,微信上面还可以通过发送名片的方式把你喜欢的微信公众帐号 ID 发送给朋友)。
最近jquery 学堂很多网友问,有没有关于微信公众平台接口的调用的例子啊,没有网友们分享过,只能直接回答没有啦,今天无意中发现了一个asp.net 的例子,于是就把它整理出来分享。
接下来教大家怎么用asp.net 实现微信公众平台接口的调用,直接贴源码:
02
using System.Collections;
03
using System.Configuration;
07
using System.Web.Security;
09
using System.Web.UI.HtmlControls;
10
using System.Web.UI.WebControls;
11
using System.Web.UI.WebControls.WebParts;
12
using System.Xml.Linq;
16
using System.Collections.Generic;
20
public partial class weixin : System.Web.UI.Page
24
protected void Page_Load(object sender, EventArgs e)
28
weixin1 +=
"\"button\":[\n"
;
30
weixin1 +=
"\"type\":\"click\",\n"
;
31
weixin1 +=
"\"name\":\"今日歌曲\",\n"
;
32
weixin1 +=
"\"key\":\"V1001_TODAY_MUSIC123eee\"\n"
;
35
weixin1 +=
"\"type\":\"click\",\n"
;
36
weixin1 +=
"\"name\":\"歌手简介\",\n"
;
37
weixin1 +=
"\"key\":\"V1001_TODAY_SINGER123eee\"\n"
;
40
weixin1 +=
"\"name\":\"菜单\",\n"
;
41
weixin1 +=
"\"sub_button\":[\n"
;
43
weixin1 +=
"\"type\":\"click\",\n"
;
44
weixin1 +=
"\"name\":\"hello word\",\n"
;
45
weixin1 +=
"\"key\":\"V1001_HELLO_WORLD123eee\"\n"
;
48
weixin1 +=
"\"type\":\"click\",\n"
;
49
weixin1 +=
"\"name\":\"赞一下我们\",\n"
;
50
weixin1 +=
"\"key\":\"V1001_GOOD123eee\"\n"
;
57
public string GetPage(string posturl, string postData)
59
Stream outstream =
null
;
60
Stream instream =
null
;
61
StreamReader sr =
null
;
62
HttpWebResponse response =
null
;
63
HttpWebRequest request =
null
;
64
Encoding encoding = Encoding.UTF8;
65
byte[] data = encoding.GetBytes(postData);
70
request = WebRequest.Create(posturl) as HttpWebRequest;
71
CookieContainer cookieContainer =
new
CookieContainer();
72
request.CookieContainer = cookieContainer;
73
request.AllowAutoRedirect =
true
;
74
request.Method =
"POST"
;
75
request.ContentType =
"application/x-www-form-urlencoded"
;
76
request.ContentLength = data.Length;
77
outstream = request.GetRequestStream();
78
outstream.Write(data, 0, data.Length);
81
response = request.GetResponse() as HttpWebResponse;
83
instream = response.GetResponseStream();
84
sr =
new
StreamReader(instream, encoding);
86
string content = sr.ReadToEnd();
87
string err = string.Empty;
92
string err = ex.Message;