C # develop WeChat portals and applications (16)-configure and use WeChat enterprise accounts,

Source: Internet
Author: User

C # configure and use the development portal and application (16)-enterprise number,

In front of this series of essays, I mainly introduced the development of public account portal applications. Recently, I added an extension to the entire framework and added the API encapsulation and development of the latest enterprise account, in the future, I will mainly introduce how to use C # To develop enterprise numbers. This article is the first part of enterprise number development and describes how to configure and use enterprise numbers.

1. Registration and login of enterprise numbers

The enterprise number is another type of public number and subscription number. It mainly targets enterprises. The enterprise number is the mobile application portal provided for enterprise customers. IT helps enterprises establish connections between employees, upstream and downstream supply chains, and enterprise IT systems. With the enterprise ID, enterprises or third-party partners can help enterprises quickly and cost-effectively implement high-quality mobile and light applications, and achieve the mobilization of production, management, collaboration, and operation.

I personally think that the biggest highlight of the enterprise number is the unlimited number of messages that can be sent, that is, they can communicate smoothly between employees. Compared with the public account and subscription account, the enterprise account is a bright display of messages. However, the enterprise number requires an internal address book. The publisher needs to match the address book number, email address, and phone number to pay attention to the address book. That is, the enterprise number can prevent other outsiders from paying attention to the address book freely, in addition, for the sake of security, you can also set secondary verification, that is, a review process.

The Enterprise ID certification is the same as the public ID. The relevant enterprise qualification documents must be provided, and the annual fee is charged for the certification. Otherwise, there may be restrictions on personnel and functions. I think I really want to make money by using the methods. The existing charging modes include subscription number, public number, enterprise number, and open platform. It seems that there are charges for certification, in addition, the store also needs to receive a deposit of 20 thousand. Everything is money.

Well, other not to mention, the registration address is: https://qy.weixin.qq.com, a mailbox can not be registered with the public number and enterprise number at the same time.

Four steps are required for enterprises to activate the enterprise ID and start using it

1) Enterprises to the official website (http://qy.weixin.qq.com) to apply for activation;

2) After activation, the Enterprise will import members in the enterprise account management background and release the QR code;

3) The enterprise calls the enterprise ID api to connect with its own system for development;

4) employees pay attention to and receive information, and interact with enterprises

After registering the enterprise number, you can scan the QR code to log on to the enterprise. During the scan, you need to confirm before entering the password to log on, the operation interface is as follows (mobile phone on the left and webpage on the right ).

 

After logging on, we can see the corresponding computer management interface.

2. Set the development callback mode.

If we have developed a public account, we know that if we need to establish a connection between the server and the website server to forward and process messages, we should set a callback mode, you must configure relevant parameters. Create an entry for processing server messages on your website server.

 

After entering the configuration, we need to modify the relevant URL, Token, EncodingAESKey, and other parameters, mainly URL. This is the same as the public number portal, we need to publish the processing entry to the website server.

The Token and AESKey can be dynamically generated according to the prompt. The AESKey seems to have to be 23 bits, so this is generally generated by itself. This is mainly used for encryption and decryption.

URL, Token, and EncodingAESKey parameters.

1) a URL is the access protocol and address used by an enterprise application to receive enterprise number push requests. It supports http or https.

2) the Token can be entered by the Enterprise at will to generate a signature.

3) EncodingAESKey is used to encrypt the message body and is base64-encoded by the AES key.

For more information about URL verification, tokens, and encryption, see "encryption and decryption when receiving messages.

The following figure shows the interface after the enterprise number is configured.

The page function pointed to in this URL needs to parse the data and return it to the server. Therefore, we need to pre-deploy this processing function entry on the server.

In addition to the above functions, there is also a CorpID parameter to be used, we can view it in the main interface-settings in the background.

Then, in order to facilitate the use of the website background, we put it in Web. Config like the public account configuration, as shown below.

3. Implement the function development of the callback page

We have introduced several configuration items that need to be used on the callback page. This section continues to introduce how to implement enterprise number message sending back so that it can pass the callback test operation.

Since the data in the callback test is sent through the Get method, our processing logic code is as follows, similar to the public number, but the implementation is not the same.

/// <Summary> /// interface for enterprise number callback information. Portal for receiving and processing information in a unified manner. /// </Summary> public class corpapi: IHttpHandler {// <summary> // process the enterprise ID information /// </summary> /// <param name = "context"> </param> public void ProcessRequest (HttpContext context) {string postString = string. empty; if (HttpContext. current. request. httpMethod. toUpper () = "POST") {using (Stream stream = HttpContext. current. request. inputStream) {Byte [] postBytes = new Byte [stream. length]; stream. rea D (postBytes, 0, (Int32) stream. Length); postString = Encoding. UTF8.GetString (postBytes);} if (! String. isNullOrEmpty (postString) {Execute (postString) ;}} else {Auth () ;}/// <summary >/// this is the first step for developers, verify the data of the corresponding server. // </summary> private void Auth () {# region obtains the key parameter string token = ConfigurationManager. deleettoken ["CorpToken"]; // obtain the Token if (string. isNullOrEmpty (token) {LogTextHelper. error (string. format ("CorpToken configuration item not configured! ");} String encodingAESKey = ConfigurationManager. appSettings ["EncodingAESKey"]; // obtain the EncodingAESKey from the configuration file if (string. isNullOrEmpty (encodingAESKey) {LogTextHelper. error (string. format ("EncodingAESKey is not configured! ");} String corpId = ConfigurationManager. appSettings ["CorpId"]; // obtain corpId if (string. isNullOrEmpty (corpId) {LogTextHelper. error (string. format ("CorpId configuration item not configured! ") ;}# Endregion string echoString = HttpContext. current. request. queryString ["echoStr"]; string signature = HttpContext. current. request. queryString ["msg_signature"]; // msg_signature string timestamp = HttpContext of the enterprise number. current. request. queryString ["timestamp"]; string nonce = HttpContext. current. request. queryString ["nonce"]; string decryptEchoString = ""; if (new CorpBasicApi (). checkSignature (token, Signature, timestamp, nonce, corpId, encodingAESKey, echoString, ref decryptEchoString) {if (! String. IsNullOrEmpty (decryptEchoString) {HttpContext. Current. Response. Write (decryptEchoString); HttpContext. Current. Response. End ();}}}

The specific processing code is as follows. An encryption/Decryption processing class is provided in the enterprise ID appendix. I only use the C # SDK.

/// <Summary> /// API implementation for basic operations on the enterprise account /// </summary> public class CorpBasicApi: ICorpBasicApi {// <summary> // verify the enterprise ID signature /// </summary> /// <param name = "token"> the Token configured for the enterprise id </param> /// <param name = "signature"> signature content </param> /// <param name = "timestamp"> timestamp </param> /// <param name = "nonce"> nonce parameter </param> /// <param name = "corpId"> enterprise ID </param> /// <param name = "encodingAESKey"> encryption key </param> /// <param name = "ec Hostr "> content string </param> /// <param name =" retEchostr "> returned string </param> /// <returns> </returns> public bool CheckSignature (string token, string signature, string timestamp, string nonce, string corpId, string encodingAESKey, string echostr, ref string retEchostr) {symbol wxcpt = new WXBizMsgCrypt (token, encodingAESKey, corpId ); int result = wxcpt. verifyURL (signature, timestamp, nonce, echostr, re F retEchostr); if (result! = 0) {LogTextHelper. error ("ERR: VerifyURL fail, ret:" + result); return false;} return true; // ret = 0 indicates the verification is successful, and retEchostr indicates the plaintext, you need to use retEchostr as the return parameter of the get request and return it to the enterprise number. // HttpUtils. SetResponse (retEchostr );}

 

 

If you are interested in this series of C # development portals and applications, you can follow my other articles as follows:

C # development portal and application (15)-added the scan, image sending, and geographic location functions in the menu

C # development portal and application (14)-use redirection in the menu to obtain user data

C # development portal and application (13)-use geographic location Extension

C # development portal and application (12)-use voice processing

C # development portal and application (11)-menu presentation

C # development portal and application (10) -- synchronize user group information in the management system

C # development portal and application (9)-portal menu management and submission to server

C # development portal and application (8)-portal application management system function Introduction

C # development portal and application (7)-Multi-customer service functions and development integration

C # development portal and application (6)-portal menu management operations

C # development portal and application (5) -- User Group Information Management

C # development portal and application (4) -- Focus on the user list and detailed information management

C # development portal and application (3) -- Response to text messages and text messages

C # development portal and application (2) -- Message Processing and response

C # development portal and application (1) -- getting started with Interfaces


& In C Language

& Can be used as the bitwise AND or address fetch Operator
The following describes two usage methods:
1. bitwise and operation bitwise AND operator "&" are binary operators. Its function is the binary phase corresponding to the two numbers involved in the operation. The result bit is 1 only when the two binary numbers are 1. Otherwise, the result bit is 0. The number of involved operations is supplemented.
For example, 9 & 5 can be written as follows: 00001001 (Binary complement of 9) & 00000101 (Binary complement of 5) 00000001 (Binary complement of 1) Visible 9 & 5 = 1.
Bitwise AND operations are usually used to clear some bits or retain some bits. For example, if a clears the high eight bits of 0 and retains the low eight bits, it can be used as a & 255 operation (255 of the binary number is 0000000011111111 ).
2. Get the address
& As The unary operator, the result is the address of the right operation object.
For example, & x returns the address of x.
The address itself is an abstract concept used to indicate the logical location of an object in the memory.

& In C Language

& Can be used as the bitwise AND or address fetch Operator
The following describes two usage methods:
1. bitwise and operation bitwise AND operator "&" are binary operators. Its function is the binary phase corresponding to the two numbers involved in the operation. The result bit is 1 only when the two binary numbers are 1. Otherwise, the result bit is 0. The number of involved operations is supplemented.
For example, 9 & 5 can be written as follows: 00001001 (Binary complement of 9) & 00000101 (Binary complement of 5) 00000001 (Binary complement of 1) Visible 9 & 5 = 1.
Bitwise AND operations are usually used to clear some bits or retain some bits. For example, if a clears the high eight bits of 0 and retains the low eight bits, it can be used as a & 255 operation (255 of the binary number is 0000000011111111 ).
2. Get the address
& As The unary operator, the result is the address of the right operation object.
For example, & x returns the address of x.
The address itself is an abstract concept used to indicate the logical location of an object in the memory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.