Home > Article > WeChat Applet > 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.
①: 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.##Server, domain name (requires filing), SSL certificate (can be applied for free):
(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 02c98f1f4b649f2d9e6fcf9caab285dc at the end of the file ee672f0beb03b42be69279368a66a410
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
#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--> <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:
小program development tutorialThe 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!