Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does WeChat Mini Programs build a server to access the node.js interface

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to build access node.js interface server for Weixin Mini Programs (Mini)." In daily operation, I believe many people have doubts about how to build access node.js interface server for Weixin Mini Programs. Xiao Bian consulted various materials and sorted out simple and easy operation methods. I hope to answer your doubts about "how to build access node.js interface server for Weixin Mini Programs"! Next, please follow the small series to learn together!

The tutorial is as follows:

First of all, I tried the previous expired certificate. I can access the interface normally when simulating it in developer tools. When testing it in mobile phone, wx.request of Weixin Mini Programs (Mini) will report SSL handshake failure error (request error: fail ssl hand shake error), so I can only reapply for a certificate.

Symantec SSL Certificates Request

After the application is completed, the review cycle is generally 1~3 days. You can download the certificate file. We choose other types of certificates.

After extracting the directory as shown in the figure below, we need to use the first two files, that is, our private key file.

Then we need to set up 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);});

At this time, it should be noted that WeChat Mini programs only support domain name interfaces without ports, but do not support IP addresses and interfaces, so we need to map to port 80 and bind the registered domain name to be accessed by Weixin Mini Programs (Mini).

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

Printing interface data in real machine debugging mode

At this point, the study of "How to build an access node.js interface server for Weixin Mini Programs" is over. I hope we can solve your doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report