search
HomeWeChat AppletMini Program DevelopmentShare a tutorial on setting up a WeChat applet to access the nodejs interface server

Recently I am developing a WeChat application account applet. The background data interface of the applet requires https secure request, so my nodejs server needs to be able to provide https support. Now I will talk about the entire https server building process.

First of all, I tried the previous expired certificate. When simulating in the developer tools, I can access the interface normally. When testing on the mobile phone, the wx.request of the WeChat applet will report an SSL handshake failure. error (request error : request: fail ssl hand shake error), so you can only reapply for a certificate. It is recommended to use Alibaba Cloud's Symantec SSL/TLS certificate, which is supported by WeChat and can be applied for free for one year.

Share a tutorial on setting up a WeChat applet to access the nodejs interface server

Symantec SSL Certificate Application

After the application is completed, the review period is usually 1 to 3 days, and you can download the certificate file. We Select other categories of certificates

Share a tutorial on setting up a WeChat applet to access the nodejs interface server


The directory after decompression is as shown below. The files we need to use are The first two files are our private key files.

Share a tutorial on setting up a WeChat applet to access the nodejs interface server


Then we need to build our https server. Here we use the https module that comes with nodejs

var https = require('https')
    ,fs = require("fs");

var express = require('express');
var app = express();

var options = {
    key: fs.readFileSync('./213988289600767.key'),
    cert: fs.readFileSync('./213988289600767.pem')
};

https.createServer(options, app).listen(8081, function () {
    console.log('Https server listening on port ' + 8081);
});

It should be noted at this time that WeChat’s mini program only supports domain name interfaces without ports, and does not support IP addresses and interfaces, so we need to map to port 80 and bind the registered domain name in order to be Accessed by WeChat applet.

Finally we can access our nodejs server interface through the wx.request method.

Share a tutorial on setting up a WeChat applet to access the nodejs interface server

Printing interface data in real machine debugging mode

The above is the detailed content of Share a tutorial on setting up a WeChat applet to access the nodejs interface server. For more information, please follow other related articles on the PHP Chinese website!

Statement
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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft