WeChat Mini Program Ecology 12 - Server Domain Name and Business Domain Name in WeChat Mini Program Development Settings

article navigation

WeChat Mini Program Ecology 1- Get to know Mini Programs
WeChat Mini Program Ecology 2- Create a WeChat Mini Program
WeChat Mini Program Ecology 3- WeChat Mini Program Login Process Design
WeChat Mini Program Ecology 4- Scan the ordinary QR code to enter the Mini Program and open the short message Link to Mini Program
WeChat Mini Program Ecology 5-WeChat Official Account Scan QR Code to Log in to PC-side Webpage
WeChat Mini Program Ecology 6-WeChat Official Account Authorization Login (Applicable to H5 Mini Programs)
WeChat Mini Program Ecology 7-WeChat Official Account Setting IP Whitelist
WeChat mini-program ecology 8- based on weixin-java-mp to realize WeChat public account passive reply message
WeChat mini-program ecology 9- WeChat open platform unionId mechanism introduction
WeChat mini-program ecology 10- WeChat public account token verification failure
WeChat mini-program ecology 11-one QR codes support WeChat, DingTalk, and Alipay at the same time Scan codes to open applets WeChat
applet ecology 12-Server domain name and business domain name in WeChat applet development settings
WeChat applet ecology 13-WeChat public account custom menu, personalized menu configuration
WeChat Mini Program Ecology 14-Release released mini programsWeChat
Mini Program Ecology 15- A way to submit WeChat Mini Programs for review in batches

foreword

There are two domain name settings in the applet: server domain name and business domain name

In fact, it is written very clearly:

"After configuring the server domain name, you can use the applet for network communication";

"After configuring the business domain name, you can call the web-view component to open it in the applet."

But for beginners, these two domain name configurations can really make people dizzy, especially the evil verification file of the business domain name. Although WeChat officials also wrote a self-checking guide for verification file verification failures, it is useless. Let's talk about how to configure these two domain names.

1. Server domain name

Each WeChat applet needs to set the communication domain name in advance, and the applet can only communicate with the specified domain name. This includes normal HTTPS requests ([wx.request), uploading files ([wx.uploadFile, downloading files ( wx.downloadFile ) and WebSocket communications ( wx.connectSocket ).

configuration process

Please configure the server domain name in "Mini Program Background-Development-Development Settings-Server Domain Name". When configuring, please pay attention to:

  • The domain name only supports https ( wx.request , wx.uploadFile , wx.downloadFile ) and wss ( wx.connectSocket ) protocols;
  • The domain name cannot use IP address (except the LAN IP of the applet ) or localhost;
  • You can configure the port, such as https://myserver.com:8080, but after configuration, you can only initiate a request to https://myserver.com:8080. Requests to URLs such as https://myserver.com, https://myserver.com:9091, etc. will fail.
  • If no port is configured. Such as https://myserver.com, then the port cannot be included in the requested URL, even the default port 443 is not allowed. A request to https://myserver.com:443 will fail.
  • The domain name must go through the ICP record;
  • For security reasons, api.weixin.qq.com cannot be configured as the server domain name, and related APIs cannot be called within the Mini Program. The developer should save the AppSecret in the background server, obtain the access_token through the server using the getAccessToken interface, and call the relevant API;
  • It is not supported to configure the parent domain name and use the subdomain name.
  • The request and upload domain names need to be configured separately. If your request and upload are both the same domain name, you need to configure them twice.
  • Any domain name that has data interaction with the applet needs to be configured, such as CDN, third-party website, etc.

总体来说,服务器域名理解起来不难,配置上也没有一些隐藏问题,除非域名写错,多了个空格或特殊符号啥的。

2. Business domain name

1. Why configure

In our actual development process, some scenarios need to jump from the WeChat applet to the H5 page, just use the web-view component, which is equivalent to directly jumping to the external link.
However, due to the increasingly severe network security issues, many websites will ask you whether to jump out after you click the jump out, and ask you to sign a disclaimer.
In order to ensure that external jumps are safe, the official WeChat applet issued such a rule: 所有外跳的链接域名都需要配置安全校验文件,如果配置不了那就不要跳. This one-size-fits-all approach hurts us developers.

2. Two ways to configure files

(1) Upload the file to the root directory of the domain name

This method is mainly to download files and then upload them. It should be noted that the correct routing should be set

(2) Write an interface yourself to return the string in the verification file

Since the verification file of WeChat only needs to judge whether the string you returned is the content in the file, we can change our thinking:
把校验的内容加到配置文件,直接通过接口返回。
I have tried this solution, and it is feasible, but it also has some pitfalls. Record it here for convenience. It is also convenient for future generations.

Not much nonsense, just go to the code:

@RestController
@RequestMapping("/")
public class WeChatDomainCheckController {
    
    
    @RequestMapping(value = "/{extension:.+.txt}", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
    public Object checkDomain(@PathVariable String extension) {
    
    
          return "校验文件中的字符串";
    }
}

value = "/{extension:.+.txt}"是请求的一种通配符写法,意思是可以让所有以txt结尾的请求访问

Notice:

  1. Do not add subpaths yourself, because the verification file access is: www.test.com/aaa.txt. Once a subpath is added, it cannot be found;
  2. The string can be returned by the VM template, but remember not to add any redundant content;
  3. Sometimes it is clear that there is no problem with the writing, but an error is reported when configuring. Here I suggest not to use the return value method, you can use
    httpServletResponse.getWriter().print("校验文件中的字符串");the return. The reason for this situation is that it is possible that I added HttpMessageConverters to the project

3. WeChat developer tools

Domain name verification can be skipped during WeChat developer tool development

insert image description here

The configured request legal domain name and web-view (business domain name) can also be seen on the development tool

insert image description here

Case Studies

Recently, an older brother also came to ask me if there is any other way to do this. I thought about it and tried to embed the externally redirected domain name into my own domain name page, and configure the verification file under my own domain name, but still No, really fucked up.

Let's configure the verification file honestly.
insert image description here

Guess you like

Origin blog.csdn.net/weixin_33005117/article/details/125220169