A brief discussion on the specific steps for building a backend for WeChat mini programs

青灯夜游
Release: 2021-05-19 09:40:21
forward
14350 people have browsed it

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.

A brief discussion on the specific steps for building a backend for WeChat mini programs

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

##Server, domain name (requires filing), SSL certificate (can be applied for free):

The poster here uses Tencent Cloud Server: Tencent Cloud

Domain name registration:

Domain name registration

SSL certificate (application and installation configuration):

Certificate application

Installation configuration

(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
Copy after login

Find \conf\extra\httpd-ssl.conf in your Apache directory, and find at the end of the file

Replace all the code between these two lines with the following code (please delete the text in and after the code):


DocumentRoot "C:\AppServ\www"  你的网站物理地址,即访问你的域名你想展示的页面
ServerName www.data-ordertime.xyz  你的网站域名
ServerAlias data-ordertime.xyz  你的网站域名 不加www
ServerAdmin [email protected]  你的邮箱
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文件的地址

SSLOptions +StdEnvVars
AllowOverride All
Require all granted


SSLOptions +StdEnvVars

BrowserMatch "MSIE [2-5]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
Copy after login

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);
      }
    })
  },

  
})
Copy after login

index.wxml


  
  点击测试服务器
  {{demo}}
  
Copy after login
Backend code:

Copy after login

Result display:

           

Related learning recommendations:

小program development tutorial

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!

Related labels:
source:csdn.net
Statement of this Website
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!