整了一天,終於弄明白了 component_verify_ticket 怎么獲取的了。在此先批一下微信公眾號平台,文檔又沒寫清楚,又沒有客服,想搞哪樣哈! 好,回歸正題。
第一,先通過開發者資質認證,再創建一個第三方開發平台,待審核通過后。
如果你的填寫的接收url 是asp.net的,如下案例
protected void Page_Load(object sender, EventArgs e)
{
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Request.InputStream);
string xml = xmlDoc.InnerXml;
string postData = xml;
////公眾號第三方平台的appid
string appId = ConfigurationManager.AppSettings["WeixinAppID"];
////第三方平台申請時填寫的接收消息的校驗token
string token = ConfigurationManager.AppSettings["WeixinToken"];
//第三方平台申請時填寫的接收消息的加密symmetric_key
string encodingAesKey = ConfigurationManager.AppSettings["WeixinEncodingAESKey"];
string sMsg = "";//解密后的內容
var msg = new WXBizMsgCrypt(token, encodingAesKey, appId);
int ret = msg.DecryptMsg(
Request.QueryString["msg_signature"],
Request.QueryString["timestamp"],
Request.QueryString["nonce"],
postData,
ref sMsg);
string path = "~/" + DateTime.Today.ToString("yyMMdd") + ".txt";
if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath(path)))
{
File.Create(System.Web.HttpContext.Current.Server.MapPath(path)).Close();
}
using (StreamWriter w = File.AppendText(System.Web.HttpContext.Current.Server.MapPath(path)))
{
w.WriteLine("\r\nLog Entry : ");
w.WriteLine("{0}", DateTime.Now.ToString(CultureInfo.InvariantCulture));
w.WriteLine(xml);
w.WriteLine("________________________________________________________");
w.WriteLine(sMsg);
w.WriteLine("_____________________________________________1___________");
w.Flush();
w.Close();
if (sMsg != "") { Response.Write("success"); }
}
}
catch (Exception ex)
{
}
}
記住不能打開直接打開連接,它接收到微信的component_verify_ticket 會記錄到日志中,或者你可以在記錄日志的那個步驟 換成你 記錄到數據庫里面!
在接收到component_verify_ticket 后,記得返回success。
希望可以幫到你!