No micro-channel public service and development --- verification reply message

After the first phase of work, server configuration aspects of the public number has been completed, the next step is the development of the built environment.

Preparations See the article:

0. message transmission path

1. Start XShell, open port forwarding

Follow the on XShell article configuration, after initiating a connection to the server, port forwarding will work, so you can request to be forwarded to the local operation of the server to.

2. Start the HTTP service, public acceptance of the request sent from the server No.

Open an HTTP service locally, the local receiver port to port and the first step in configuring the same. Click the public at the time of verification of the number of servers, number of public official will send a GET request over the relevant parameters are as follows.

1, signature micro-channel encrypted signature, signature combines a timestamp parameter developer filled token request parameters, nonce parameters.
2, timestamp time stamp
3, nonce random number
4, echostr verification succeeds, the returned string.
5, token for the token number in a public setting.
After receiving the GET request, parses the four parameters from the GET request. After calculating the following steps to complete.

Verify flowchart

C ++ code example below

void CHttpServer::Get_Chat(std::shared_ptr<HttpServer::Response> response, std::shared_ptr<HttpServer::Request> request) {
		std::string strSignature = GetHttpParamValue(request, "signature");
		std::string strTimeStamp = GetHttpParamValue(request, "timestamp");
		std::string strNonce = GetHttpParamValue(request, "nonce");
		std::string strEchoStr = GetHttpParamValue(request, "echostr");
		{
			std::vector<std::string> strArray;
			strArray.push_back(strTimeStamp);
			strArray.push_back(strNonce);
			strArray.push_back(g_strTOKEN);
			std::sort(strArray.begin(), strArray.end());

			std::string strSHA1Src = strArray[0] + strArray[1] + strArray[2];

			SHA1Util util;
			util.update(strSHA1Src);
			std::string strSha1 = util.final();
			if (strSha1 == strSignature)
			{
				LOG_INFO(ms_loger, "My Base64:{} Org Base 64:{}", strSha1, strSignature);
			}
			else
			{
				LOG_ERR(ms_loger, "My Base64:{} Org Base 64:{}", strSha1, strSignature);
			}

		}
		*response << "HTTP/1.1 200 OK\r\nContent-Length: " << strEchoStr.length() << "\r\n\r\n"
			<< strEchoStr;
	}

Thus, the verification process is completed.

3. Text message transceiver

Public message number in the form of a transceiver with a URL request different ways.

For example, the step verification URL is https://www.dennisthink.com/WeChat , request method to GET. Then receive a message URL is https://www.dennisthink.com/WeChat , just the way the request becomes a POST.

Received from the POST message is in XML format, the specific meaning of each part of the official documentation to receive a common message definition.

After receiving the message, according to official documents reply message passive reply message.

For subscription number already support this feature, and if you have any questions, please give me a message exchange.

Guess you like

Origin www.cnblogs.com/Dennis-mi/p/12592231.html