Mini program-uniapp: URL Link / Suitable for opening any page of the mini program on the mobile terminal from SMS, email, web pages outside WeChat, etc.

1. Background introduction

Mini Program URL Scheme and URL Link are addresses generated by the WeChat Mini Program background and are suitable for opening any page of the Mini Program from text messages, emails, web pages outside WeChat, etc. Therefore, the applicability is extremely strong. It can complement the technology of scanning QR code on WeChat and carrying parameters to jump to the specified page of the mini program.

If opened outside WeChat, users can click on the browser page to enter the mini program. After each independent URL Link is accessed by a user, only this user can access and open the corresponding applet again, and other users cannot open the applet through the same URL Link again. The maximum validity period can be set to 30 days.

2. Code implementation

// 这里是前端代码实现了整个逻辑,生产项目应该后端接口封装好,前端调用,传递参数
const getUrlLink = () => {
    uni.request(
      {
        url:`https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=appid&secret=secret`,
        method: 'GET',
        success: ((res:any) =>{
          console.log(res)
          uni.request(
            {
              url:'https://api.weixin.qq.com/wxa/generate_urllink?access_token=' + res.data.access_token,
              method: 'POST',
              data: {
                access_token: wx.getStorageSync('token'),
                path: 'pages/XXX/index',
                query: ''
              },
              success: ((res:any) => {
                console.log(res2)
                // 访问微信中间页面,点击进入小程序,携带参数访问微信小程序指定页面
                location.href = res2.data.url_link
              })
            }
          )
        })
      }
    )
}
getUrlLink()

3. Official website examples

Get URL Scheme | WeChat Open Document

Mobile browser access can be tested

https://postpay-2g5hm2oxbbb721a4-1258211818.tcloudbaseapp.com/jump-mp.html

4. Reference links

Mini program: Scan the QR code on WeChat and jump to the specified page of the mini program with parameters_Scan the QR code on the WeChat mini program to enter different pages_snowball_li's blog-CSDN blog

Get URL Scheme | WeChat Open Document

How many users does the mini program url link support? | WeChat open community

Get URLLink | WeChat Open Document

Announcement on Adjustment of Mini Program Link Generation and Usage Rules | WeChat Open Community

How to use URL Scheme H5 link to directly open the WeChat applet

Query URL Link | WeChat Open Document

Guess you like

Origin blog.csdn.net/snowball_li/article/details/132941316