Don't want to talk nonsense, write directly! Because it is for oneself to do essays, so the great god see don't spray ...
1. Must have a micro-credit public account
2. You can also apply for a test micro-signal, link to you Http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox /login
Then, to build MVC, you just need to take a few points vs to help you get it done. It's not nonsense. &NBSP
Then, to create a general handler, casually name, test pass is the focus, seize the time ...
<summary>
///Verification Micro-letter signature
///</summary>
///<returns></returns>
///* will token , timestamp, nonce three parameters for dictionary ordering
///* Concatenation of three parameter strings into a string for SHA1 encryption
///* The developer obtains the encrypted string to compare with the signature, which identifies the request from the micro-letter.
private bool Checksignature ()
{
var token = "token";
var signature = httpcontext.current.request.querystring["signature"];
var timestamp = httpcontext.current.request.querystring["timestamp"];
var nonce = httpcontext.current.request.querystring["nonce"];
var echostr = httpcontext.current.request.querystring["Echostr"];
String[] Arrtmp = {token, timestamp, nonce};
Array.Sort (ARRTMP); Dictionary sort
var tmpstr = string. Join ("", arrtmp);
Tmpstr = FormsAuthentication.HashPasswordForStoringInConfigFile (tmpstr, "SHA1");//Encryption Mode
if (tmpstr.tolower () = Signature)
{return
true;
}
return false;
}
This code is equivalent to the "development" in the micro-public number "" "" Basic Configuration "in which you write the token a one-to-one token communication handshake, as long as each other, then you are done!
Fix is something, still have work not finished, keep on writing!
How to configure, this is the problem, hey can only use peanut shells to test first, at least know to play a half-day is not pass!
Look at the picture: Left Peanut Shell configuration-----Right IIS Web site publishing bindings
See this picture, you also understand how to play next. Local IIS is assigned a domain name. This is a blast ... it's just.
Below. We add code. Set up send and auto reply test to see if you can play
#region Receive Message///<summary>///receive the XML message sent by the micro-mail and parse///</summary> private void Receivexml () {var request
Stream = HttpContext.Current.Request.InputStream;
var requestbyte = new Byte[requeststream.length];
Requeststream.read (requestbyte, 0, (int) requeststream.length);
var requeststr = Encoding.UTF8.GetString (requestbyte); if (!string.
IsNullOrEmpty (REQUESTSTR)) {//Encapsulation request class var requestdocxml = new XmlDocument ();
Requestdocxml.loadxml (REQUESTSTR);
var rootelement = requestdocxml.documentelement;
if (rootelement = null) return; var Wxxmlmodel = new Wxxmlmodel {tousername = Rootelement.selectsinglenode ("Tousername"). innertext, Fromusername = Rootelement.selectsinglenode ("Fromusername"). innertext, Createtime = Rootelement.selectsinglenode ("Createtime"). innertext, Msgtype = Rootelement.selectsinglenode ("Msgtype").
InnerText}; Switch (wxxmlmodel.msgtype) {case "text"://Text wxxmlmodel.content = Rootelement.selectsinglenode ("Content").
InnerText; BreAk Case "image"://Picture Wxxmlmodel.picurl = Rootelement.selectsinglenode ("Picurl").
InnerText;
Break Case "Event"://Event wxxmlmodel.event = Rootelement.selectsinglenode ("event").
InnerText; if (wxxmlmodel.event!= "templatesendjobfinish")//attention type {Wxxmlmodel.eventkey = Rootelement.selectsinglenode ("EventKey ").
InnerText;
} break;
Default:break; Responsexml (Wxxmlmodel);//Reply message}} #endregion #region reply message private void Responsexml (Wxxmlmodel wxxmlmodel) {V
Ar qrcodeapi = new Qrcodeapi ();
var XML = ""; Switch (wxxmlmodel.msgtype) {case "text"://Text reply XML = Responsemessage.gettext (Wxxmlmodel.fromusername, Wxxmlmodel.tou
Sername, wxxmlmodel.content);
Break Case ' event ': switch (wxxmlmodel.event) {case "subscribe": if (string. IsNullOrEmpty (Wxxmlmodel.eventkey)) {XML = Responsemessage.gettext (Wxxmlmodel.fromusername, WxXmlModel.ToUserName,
"Focus on success"); else {XML = Responsemessage.subscanqrcode (Wxxmlmodel.fromusername, Wxxmlmodel.touseRname, Wxxmlmodel.eventkey);//scan with parameters two-dimensional code first attention after the push event} break; Case "SCAN": XML = Responsemessage.scanqrcode (Wxxmlmodel.fromusername, Wxxmlmodel.tousername, Wxxmlmodel.eventkey);
/scan with parameter two-dimensional code has been concerned with direct push event break;
} break;
default://default reply break;
} HttpContext.Current.Response.Write (XML);
HttpContext.Current.Response.End ();
} #endregion
The above one is sent, one receives, or in the Whapi.ashx handler file. I want to say clearly, hehe!
Because you have a public platform shaking hands successfully, you must send something to go over and try, right?
The following figure is a receipt method and an automatic matching response file association, don't worry I will upload this file!
A configuration is missing, vs. to set the debug----"Attach to process", just tick the "Show all user Processes" button below, and you'll find w3wp.exe. If there are more than one such process, you still have to confirm the "username" column, select the same as your program pool name on OK, dot attach , OK Attach!
Next. It's fun ...... .................. ................ ........ ...
Micro-letter sweep that test public number, send a custom message, see what reply, the above cumbersome configuration, you can add breakpoints debugging, or make so much also meaningless is it, see Send and receive with your own set the match, that's OK.
That's it............ Finished.
Wonderful topic sharing: ASP.net micro-credit Development tutorial Summary, Welcome to learn.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.