如何设计网站制作方案/b2b平台营销
小程序开发文档描述:小程序网络请求需要https协议,配置域名,域名必须经过 ICP 备案。这是小程序申请通过的必然条件。
1.购买一个域名,并解析
如果域名没有获得证书,小程序会报错 ***不在以下 request 合法域名列表中,请参考文https://developers.weixin.q....
此时简单方法可以直接在小程序项目设置中取消https等校验。
2.申请免费证书
但是取消检验不是长久之计,总得要走申请发布小程序流程,因为仅仅用于小测试(穷~),免费证书就够了。比如去阿里云申请并下载(平台步骤很详细)。由于我后端是node,下载Nginx版。下载好后有key和pem两个文件。
在node根目录下新建一个文件夹将key文件和pem文件放置此文件夹。
node中配置:
const express = require("express");
const path = require("path");
const fs = require("fs");
const https = require("https");
const app = express();//导入证书
const privateKey = fs.readFileSync(path.join(__dirname, "./httpsSsl/2671777_www.***.***.key"),"utf8"
);
const certificate = fs.readFileSync(path.join(__dirname, "./httpsSsl/2671777_www.***.***.pem"),"utf8"
);
const credentials = {key: privateKey,cert: certificate
};
app.get("/", (req, res) => {res.send("hello world");
});
const httpsServer = https.createServer(credentials, app);
const SSLPORT = 443;
httpsServer.listen(SSLPORT, () => {console.log(`HTTPS Server is running on: https://localhost:${SSLPORT}`);
});
启动node服务,在小程序开发设置界面配置域名。此时小程序请求有ssl证书的域名控制台不再报错,打印出hello world。
*******如果此时接口无法请求,控制台报错对应的服务器证书无效,可能是证书设置错误,重新下载证书即可。
如果需要申请审核此时只需要将域名备案即可。