亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home WeChat Applet WeChat Development C# implements prelude to WeChat development

C# implements prelude to WeChat development

Feb 13, 2017 am 11:13 AM

I don’t want to talk nonsense, just write it! Because it is left for you to write essays, so masters, please don’t complain when you see it...

1. You must have a WeChat public account

2. You can also apply for a test WeChat account, the link is given to you http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login

Then, to create mvc, you only need to click a few times and vs will do it for you. This is no nonsense

Next, you need to create a general handler, give it a name casually, passing the test is the key, hurry up...

///?<summary>
????????///?驗(yàn)證微信簽名????????
????????///?</summary>
????????///?<returns></returns>
????????///?*?將token、timestamp、nonce三個(gè)參數(shù)進(jìn)行字典序排序????????
????????///?*?將三個(gè)參數(shù)字符串拼接成一個(gè)字符串進(jìn)行sha1加密????????
????????///?*?開發(fā)者獲得加密后的字符串可與signature對(duì)比,標(biāo)識(shí)該請(qǐng)求來源于微信。
????????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);?????//字典排序
????????????var?tmpStr?=?string.Join("",?ArrTmp);
????????????tmpStr?=?FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr,?"SHA1");//加密方式????????????if?(tmpStr.ToLower()?==?signature)
????????????{????????????????return?true;
????????????}????????????return?false;
????????}

This code is equivalent to a one-to-one token communication handshake with the Token you wrote in [Develop]--"[Basic Configuration] in the WeChat public account. As long as they communicate with each other, then you are done!

Finishing it is a thing later, there is still work to be done, wipe it, and keep writing!

How to configure it? This is the problem. You can only use peanut shells to test it first. At least you need to know whether it works after playing for a long time!

Look at the picture below: peanut shell configuration on the left-----iis website publishing binding on the right

C#實(shí)現(xiàn)微信開發(fā)前奏

Seeing this picture, you will understand how to play the next step. The local iis is equipped with a domain name. This is so fucking awesome......

Down below. We add code. Set up sending and auto-reply tests to see if you can play

?#region?接收消息????????///?<summary>
????????///?接收微信發(fā)送的XML消息并且解析????????///?</summary>
????????private?void?ReceiveXml()
????????{????????????var?requestStream?=?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))
????????????{????????????????//封裝請(qǐng)求類
????????????????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"://文本
????????????????????????wxXmlModel.Content?=?rootElement.SelectSingleNode("Content").InnerText;????????????????????????break;????????????????????case?"image"://圖片
????????????????????????wxXmlModel.PicUrl?=?rootElement.SelectSingleNode("PicUrl").InnerText;????????????????????????break;????????????????????case?"event"://事件
????????????????????????wxXmlModel.Event?=?rootElement.SelectSingleNode("Event").InnerText;????????????????????????if?(wxXmlModel.Event?!=?"TEMPLATESENDJOBFINISH")//關(guān)注類型????????????????????????{
????????????????????????????wxXmlModel.EventKey?=?rootElement.SelectSingleNode("EventKey").InnerText;
????????????????????????}????????????????????????break;????????????????????default:????????????????????????break;
????????????????}

????????????????ResponseXML(wxXmlModel);//回復(fù)消息????????????}
????????}????????#endregion

????????#region?回復(fù)消息????????private?void?ResponseXML(WxXmlModel?WxXmlModel)
????????{????????????var?QrCodeApi?=?new?QrCodeApi();????????????var?XML?=?"";????????????switch?(WxXmlModel.MsgType)
????????????{????????????????case?"text"://文本回復(fù)
????????????????????XML?=?ResponseMessage.GetText(WxXmlModel.FromUserName,?WxXmlModel.ToUserName,?WxXmlModel.Content);????????????????????break;????????????????case?"event":????????????????????switch?(WxXmlModel.Event)
????????????????????{????????????????????????case?"subscribe":????????????????????????????if?(string.IsNullOrEmpty(WxXmlModel.EventKey))
????????????????????????????{
????????????????????????????????XML?=?ResponseMessage.GetText(WxXmlModel.FromUserName,?WxXmlModel.ToUserName,?"關(guān)注成功");
????????????????????????????}????????????????????????????else
????????????????????????????{
????????????????????????????????XML?=?ResponseMessage.SubScanQrcode(WxXmlModel.FromUserName,?WxXmlModel.ToUserName,?WxXmlModel.EventKey);//掃描帶參數(shù)二維碼先關(guān)注后推送事件????????????????????????????}????????????????????????????break;????????????????????????case?"SCAN":
????????????????????????????XML?=?ResponseMessage.ScanQrcode(WxXmlModel.FromUserName,?WxXmlModel.ToUserName,?WxXmlModel.EventKey);//掃描帶參數(shù)二維碼已關(guān)注?直接推送事件
????????????????????????????break;
????????????????????}????????????????????break;????????????????default://默認(rèn)回復(fù)
????????????????????break;
????????????}
????????????HttpContext.Current.Response.Write(XML);
????????????HttpContext.Current.Response.End();
????????}????????#endregion

with one sending and one receiving, still in the WhApi.ashx handler file. I just want to make it clear, haha!

Because your handshake with the public platform was successful, you must send something to try, right~~

The picture below shows the association between a receiving method and an automatic matching reply file. I will upload this file soon!

C#實(shí)現(xiàn)微信開發(fā)前奏

There is still one missing configuration, that is, to set [Debug] ---- [Attach to process] for vs, you only need to change the following [Show all If you check "User Process", you can find w3wp.exe. If there are multiple such processes, you still have to confirm the "User Name" column, select the one with the same name as your program pool, click OK, click Attach, OK Attached!

Next. It’s fun……………………………………………………………………

Scan the test public account on WeChat and send a customized message to see what responses there are , the above tedious configuration can be debugged by adding breakpoints, otherwise there is no point in doing so much, right? Just make sure that the sending and receiving are consistent with your own settings, then it will be ok.

That's it.........it's finished.

For more C# implementation of WeChat development prelude and related articles, please pay attention to the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72