Home  >  Article  >  WeChat Applet  >  A brief discussion on the specific steps for building a backend for WeChat mini programs

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

青灯夜游
青灯夜游forward
2021-05-07 10:10:5314550browse

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

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

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:&#39;超超1号&#39;
      },
      header: {
        &#39;content-type&#39;: &#39;application/x-www-form-urlencoded&#39;
      },
      method: "GET",
      success(result) {
        console.log(result);
        that.setData({
          demo: result.data
        })
      },
      fail(error) {
        util.showModel(&#39;请求失败&#39;, error);
        console.log(&#39;request fail&#39;, error);
      }
    })
  },

  
})

index.wxml
<!--index.wxml-->
<view class="container">
  
  <view bindtap=&#39;ceshifuwuqi&#39;>点击测试服务器
  <view>{{demo}}</view></view>
  
</view>
Backend code:

<?php
$myName = $_GET[&#39;name&#39;];  //GET方式获取传来的name参数
echo $myName."真帅";

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete