Applet basic network capacity ~

(1) Network - Description

The internet

When using the API in a small network-related program / game, you need to pay attention to the following questions, please developers know in advance.

1. The domain name server configuration

Each program requires a small micro-channel pre-set communications domain, applets can only communicate with a network with the specified domain name . Including ordinary HTTPS request ( wx.request ), upload files ( wx.uploadFile ), download file ( wx.downloadFile ) and WebSocket communication ( wx.connectSocket ).

Starting from the basic library 2.4.0, network interface allows communication with the LAN IP, but pay attention to  not allow IP to communicate with this machine .

2.7.0 From the beginning, provides the UDP communication ( wx.createUDPSocket ), allowed only with non-native IP communication within the same local area network.

Configuration process

Please server domain name in the "applet background - Set - development settings - server domain name" is configured, you need to pay attention to when configuring:

  • Only supports domain name  https ( wx.request , wx.uploadFile , wx.downloadFile ) and  wss ( wx.connectSocket ) protocol;
  • You can not use the IP address of the domain name (applets LAN  IP exception) or localhost;
  • You can configure ports, such as https://myserver.com:8080, but the configuration can only be initiated after a request to the https://myserver.com:8080. If the https: 9091 request will fail, etc. URL: //myserver.com,https: //myserver.com.
  • If you do not configure the port. As https://myserver.com, then the URL request can not contain the port, or even the default 443 port can not. If the request will fail to https://myserver.com:443.
  • The domain must ICP for the record;
  • For security reasons, api.weixin.qq.com it can not be configured as a domain name server, not related to API calls in a small program.  Developers should AppSecret saved to the back-end server by using the server  getAccessToken interface to obtain  access_tokenand call the relevant API;
  • For each interface, respectively, can be configured with up to 20 domain names.

2. Network request

overtime time

  • The default timeout and maximum timeout is  60s ;
  • Timeout may  app.json or  game.json by the  networktimeout configuration.

Limitations

  • The network request  referer header is not provided. The format is fixed  https://servicewechat.com/{appid}/{version}/page-frame.html, which  {appid} is appid small program, {version} the version number, the version number of the applet is  0 expressed as a development version, trial version and audit version, the version number is  devtools expressed as developer tools, the rest is the official version;
  • wx.request , wx.uploadFile , wx.downloadFile  maximum concurrent limit is  10  th;
  • wx.connectSockt  maximum concurrent limit is  5  Ge.
  • After entering the small program running in the background, if  5s  within the network request is not completed, an error message will callback  fail interrupted; before returning to the front desk, network interface call request will not be called.

The return value encoding

  • Return value suggestion server using  UTF-8  encoding. For non-UTF-8 encoding, the program will try to convert the small, but there will be conversion may fail.
  • BOM applet will automatically filter head (BOM header only a filter).

Callback

  • As long as the server receives a successful return, no matter  statusCode how many, will enter  success callback. Please return value of the developer is determined based on business logic.

3. Frequently Asked Questions

HTTPS certificate

Applet must use HTTPS / WSS initiate network requests . HTTPS certificate request using a domain name server system will be verified, if the check fails, the request can not be successfully launched. Due to system limitations, different platforms stringent requirements for the certificate. In order to ensure compatibility applet, it is recommended developers to configure a certificate in accordance with the highest standards and use existing tools to check whether the certificate meets the requirements.

The certificate requirements are as follows:

  • HTTPS certificate must be valid;
    • The certificate must be trusted system, that is, the root certificate is already built-in system
    • Domain deployment of SSL certificate must be issued with a certificate domain matches
    • The certificate must be within the validity period
    • Certificate chain of trust necessary for the complete (server configuration required)
  • iOS It does not support self-signed certificate;
  • iOS The certificate must meet under the Apple  App Transport Security (ATS)  requirements;
  • We must support TLS 1.2 and above. Some of the old  Android models have not yet support TLS 1.2, make sure that the HTTPS server supports TLS version 1.2 and below;
  • CA may not be part of the trusted operating system, please note that the developer-related announcements small programs, and systems in the selection of the certificate.

Validity of the certificate can use the  openssl s_client -connect example.com:443 command to verify, you can use other online tools .

In addition to the network API request, the applet other  HTTPS requests if an exception occurs, please check the above-described process. Https as the picture could not be loaded, such as audio and video can not be played.

Skip domain verification

In the micro-channel developer tool, you can temporarily open the  开发环境不校验请求域名、TLS版本及HTTPS证书 option to skip the verification server domain name. At this time, the micro-channel mobile phones developer tools and open debug mode, the server does not verify the domain name.

After the domain name server configuration is successful, developers who develop this option turned off, and tested at each platform to confirm that the domain name server is configured correctly.

If the phenomenon of "open the debug mode you can send a request to close the debug mode can not send request" on the phone, make sure to skip the domain name check and verify the domain name server and certificate configuration is correct.

 

(2) Network - LAN communication

LAN communication

Infrastructure Library 2.4.0 provides  wx.startLocalServiceDiscovery  series mDNS API, can be used to obtain an IP devices provide mDNS services within the local area network. wx.request / wx.connectSocket / wx.uploadFile / wx.downloadFile  URL parameter allows for the  ${IP}:${PORT}/${PATH} format, if and only if at the same IP and IP phone network and the local IP and not the same (generally speaking, the same is a local area network, such as a wifi connection in the same), a request / connection will succeed.

In this case, does not verify the security domain, is not required to use https / wss, you can use http / ws.

wx.request({
  url: 'http://10.9.176.40:828' // 省略其他参数 }) wx.connectSocket({ url: 'ws://10.9.176.42:828' // 省略其他参数 }) 

Infrastructure Library 2.7.0 is available as of  wx.createUDPSocket  an interface for UDP traffic. Ibid communication rules, allowing only non-native IP in the same LAN.

mDNS

Currently only supports applet to obtain an IP other devices within the LAN through mDNS protocol. iOS mDNS API implemented based on  the Bonjour , it is based on the Android  Android system interface .

serviceType

MDNS services launched a search  wx.startLocalServiceDiscovery  interface has serviceType parameter specifies the type of service you want to search.

serviceType format and specification, the iOS  the Bonjour the Overview  in  Bonjour Names for Existing Service Types  There are mentioned.

Hello serviceType.png

Android documentation  on this is also mentioned.

Android serviceType.png

 

.

 

 

 

 

 

.

Guess you like

Origin www.cnblogs.com/jianxian/p/11106953.html