Flask + ngrok WeChat official account construction test, flaskngrok

Source: Internet
Author: User

Flask + ngrok public account construction test, flaskngrok

Using ngrok + flask to build a public platform consists of three steps: 1. ngrok configuration; 2. Public platform configuration; 3. flask construction. Shows the basic data flow trend:

 

1. ngrok Configuration

Ngrok provides an intranet-to-Internet ing tool for users who use nat to access the Internet and have no Internet address resources. It can access intranet resources through the Internet.

First download the ngrok tool from the ngrok official website. This version is 2.1.18. It is used in win7 and the command is ngrok.exe http 80.

As shown in, the link circled in blue is an external link, which is mapped to port 80 of the local machine. If flask is used, you need to change 80 to the default port 5000 or custom port of flask. In this way, you can access the corresponding resources on the public network by copying the link.

Ngrok can also add the parameter-subdomain = xxx to customize the sub-domain name. However, currently, the fee is charged, and the basic fee is USD 5/month to enjoy the service. It is worth noting that if you do not buy its service, the link changes every time you enable ngrok.

 

2. Public platform Configuration

The public platform configuration includes two steps: 1. write the authentication code on the server. For details about the authentication code, see the development documentation. 2. set the authentication link on the public platform, as shown in:

The public platform configuration mainly involves entering the required verification link on the basic configuration interface. If the verification is in the root directory of the link in step 1, you can directly copy the token. the token can be set at will, but ensure that the settings here are consistent with those in the code.

Def wechat_auth (): if request. method = 'get': if len (request. args)> 3: token = 'xxxxxxx' query = request. args signature = query ['signature'] timestamp = query ['timestamp'] nonce = query ['nonce '] echostr = query ['echostr'] s = [timestamp, nonce, token] s. sort () s = ''. join (s) sha1str = hashlib. sha1 (s. encode ('utf-8 ')). hexdigest () if sha1str = signature: return make_response (echostr) else: return make_response ("authentication failed") else: return "authentication failed"

 

2017-03-0511: 49: 45

If you are not professional, please correct me!

 

Related Article

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.