


A brief discussion on the specific steps for building a backend for WeChat mini programs
This article will introduce to you how to build your own backend for WeChat applet. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
Ideas
①: First we need to have our own AppID (a bit nonsense).
②: We need to have a backend, that is, server. Domain name (requires registration). sslcertificate. (In short, we need to access our server through https://www.xxxxxx.com)
③: Configure the domain name information in the WeChat public platform.
④: The mini program accesses our background function through the wx.request() function. The background accepts the parameters passed by the mini program and returns them to the mini program value after processing. The mini program then receives the parameters passed by the background. parameters and perform operations.Process
Get AppID:
WeChat Public Platform
The poster here uses Tencent Cloud Server: Tencent Cloud
Domain name registration
SSL certificate (application and installation configuration):Certificate application
(The author here is to configure the SSL certificate in the windows Apache environment. If you want to install it in other environments, you can refer to the certificate installation):Download your SSL certificate and put the three files in the Apache folder into the conf folder in the Apache directory.
Find \conf\httpd in your Apache directory. conf and open it, find the following two lines, and remove the comment symbol # in front of these two lines. (If not, just remove the # sign and insert it into the file)
# LoadModule ssl_module modules/mod_ssl.so # Include conf/extra/httpd-ssl.conf
Find \conf\extra\httpd-ssl.conf in your Apache directory, and find
Replace all the code between these two lines with the following code (please delete the text in and after the code):
<VirtualHost _default_:443> DocumentRoot "C:\AppServ\www" 你的网站物理地址,即访问你的域名你想展示的页面 ServerName www.data-ordertime.xyz 你的网站域名 ServerAlias data-ordertime.xyz 你的网站域名 不加www ServerAdmin 1910722307@qq.com 你的邮箱 DirectoryIndex index.html index.htm index.php default.php app.php u.php ErrorLog logs/example_error.log CustomLog logs/example_access.log \ "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" SSLEngine on SSLCertificateFile conf/2_data-ordertime.xyz.crt 你申请的证书文件的地址 SSLCertificateKeyFile conf/3_data-ordertime.xyz.key 你申请的key文件的地址 <Directory "sslroot/"> SSLOptions +StdEnvVars AllowOverride All Require all granted </Directory> <FilesMatch "\.(shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> BrowserMatch "MSIE [2-5]" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 </VirtualHost>WeChat public
Configure domain name information in the platform: At this time, the domain name will be considered a safe and available domain name in the WeChat developer tools (note that we are setting it up for the projects in the two pictures below You can access our backend even if the option "Do not verify legal domain name" is checked, because our domain name is theoretically secure (difference between http and https))
#Test a small demo (the poster here uses PHP backend):
Write the following code into the WeChat developer tools,
index.js
//index.js Page({ data: { }, ceshifuwuqi:function(){ var that = this wx.request({ url: `https://www.data-ordertime.xyz/wxdemo.php`,//你的后台url地址 data:{ name:'超超1号' }, header: { 'content-type': 'application/x-www-form-urlencoded' }, method: "GET", success(result) { console.log(result); that.setData({ demo: result.data }) }, fail(error) { util.showModel('请求失败', error); console.log('request fail', error); } }) }, })
index.wxml<!--index.wxml-->
<view class="container">
<view bindtap='ceshifuwuqi'>点击测试服务器
<view>{{demo}}</view></view>
</view>
Backend code:
<?php $myName = $_GET['name']; //GET方式获取传来的name参数 echo $myName."真帅";
Result display:
Related learning recommendations:
The above is the detailed content of A brief discussion on the specific steps for building a backend for WeChat mini programs. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
