Home  >  Article  >  WeChat Applet  >  Summarize and share some practical knowledge in small program development

Summarize and share some practical knowledge in small program development

青灯夜游
青灯夜游forward
2022-01-26 10:50:103012browse

This article summarizes and shares with you some practical knowledge in small program development. I hope it will be helpful to everyone!

Summarize and share some practical knowledge in small program development

Understand the rendering principle of the mini program

Background

In web development, since js is single-threaded, scripts sometimes run for a long time, causing the page to lose response. There are currently three ways to render pages:

  • Pure client-side native technology rendering
  • Pure web technology rendering
  • Hybrid rendering, that is, a combination of web and native rendering Method

In the mini program, the Hybrid rendering method is selected, the logic layer and the view layer are separated, and run using dual threads. WebView is used to render the interface of the view layer, and the logic layer runs in JSCore.

Dual-thread model of mini program:

  • Logic layer: Create a separate thread to execute javascript. All code related to the business logic of the mini program is executed here, responsible for the logic Processing, data requests, interface calls.
  • View layer: Interface rendering is executed in the webView thread, and which interfaces are controlled through the logic layer code
  • jsBridge: Enables small programs to use native functions through the API

Summarize and share some practical knowledge in small program development

Do you really understand the connection between appId, uniId and openId

openID

openID is assigned uniformly to users by the WeChat public platform. As we all know, WeChat mini programs and WeChat public accounts are maintained on the WeChat public platform. In order to distinguish users, each public account and mini program provides a unique ID for each user. Each user generates a unique openID

Summarize and share some practical knowledge in small program development

UnionID

UnionID is the ID assigned to WeChat users by the WeChat open platform. For applications under the same open platform, WeChat users will have a unique UnionID

For example: your company has two applications, mini program A and WeChat official account B, user information of A and B is required By opening up, two applications A and B can be bound to the same open platform. The WeChat open platform will generate a unique UnionID for WeChat users. After authorized login and registration, the UnionID will be stored in the user table, and will be opened from the same open platform in the future. After other applications under the platform are authorized to log in and get the UnionID, they can directly return the user information,

Summarize and share some practical knowledge in small program development

AppID

AppID is the unique identifier of different applications

For example: your company has one mini program, one official account and two applications, AppId is the unique identifier of these two applications

Summarize and share some practical knowledge in small program development

Take you to summarize the jumping ability of the mini program, so that you can accept leadership inspection at any time

A friend today He complained to me that he is currently working in a small and medium-sized company. The bosses are having a meeting in the conference room. The big boss has a question about mini program jump. A leader A, who didn't know which part he was responsible for, came out and first asked about operation and maintenance, and then asked about back-end Java. Java boss said that this belongs to the front-end category, and they were more clear. After hearing this, leader A directly said, what does the front-end know? Then he walked into the conference room and gave feedback to the big boss. No one knew. He told me before that their company’s front-end status is low. This is really low.

h5 Jump Mini Program

Product: Xiaoyang , our official account needs to jump to a certain applet by clicking this button. This function must be implemented

Okay, now that we have the requirements, let’s start with the plan

  • Option 1: Click the button, give a pop-up box, and put it in the pop-up box A QR code. Guide users to long press to identify the
    • operation process field, the user conversion rate is low, and most users are basically too lazy to operate
  • Option 2: Use WeChat’s open label wx -open-launch-weapp
    • You can jump to any legal and compliant mini program (I feel there will be more restrictions on this function later)

Passed After discussing with the product, the second option is more suitable. Start with:

Steps:

  • Certified service account, bind the service account to the "js interface security domain name" Web pages under "can use this tag to jump to any legal and compliant mini program
  • Introduce js files https://res.wx.qq.com/open/js/jweixin-1.6.0.js
  • Inject permission configuration through the config interface, and apply for the required open tags through the openTagList field
wx.config({
  debug: false,
  appId: '',   // 公众号唯一标识
  timestamp: '',  // 生成签名的时间戳
  nonceStr: '',   // 生成签名的随机串
  signature: '',  // 签名
  jsApiList: ["wx-open-launch-weapp"],
  openTagList: ["wx-open-launch-weapp"] // 微信开放标签 小程序跳转按钮:<wx-open-launch-weapp>
});
// 通过ready处理成功验证
wx.ready(function () {
  console.log(&#39;ready&#39;)

})
// 处理失败验证
wx.error(function(error) {
  console.error("err", error);
});

<wx-open-launch-weapp
  id="launch-btn"
  username="gh_xxxxxxxx"
  path="pages/home/index?user=123&action=abc"
>
  <script type="text/wxtag-template">
    <style>.btn { padding: 12px }</style>
    <button class="btn">打开小程序</button>
  </script>
</wx-open-launch-weapp>

The WeChat customer service message contains a jump applet link

文本内容....<a href=&#39;&#39; data-miniprogram-appid=&#39;{{appid}}&#39; data-miniprogram-path=&#39;pages/index/index&#39;>点击跳小程序</a>
  • data-miniprogram-appid填写小程序链接,表示跳转小程序
  • data-miniprogram-path 小程序路径,可带参数
  • 公众号必须和小程序相关联
  • 链接中的各个属性值必须使用单引号

小程序跳转小程序

wx.navigateToMiniProgram({
    envVersion: &#39;release&#39;, // 要打开的小程序版本,develop: 开发版,trial:体验版,release:正式版。仅在当前小程序为开发版或体验版时此参数有效。
    appId: ’‘, // 跳转appid
    path: ’‘  //  跳转路径
})
  • 需要用户手动触发
  • 需要用户确认跳转

【相关学习推荐:小程序开发教程

The above is the detailed content of Summarize and share some practical knowledge in small program development. For more information, please follow other related articles on the PHP Chinese website!

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