preface
Finally, wechat applet support in the form of URL Scheme aroused from the outside.
We can only use the “wX-open-launch-appellate” button to activate appellate apps on wechat web pages. There is only one scenario when appellate apps can be unlocked.
In actual business, we hope to open small programs in marketing SMS, email or other channels such as APP to quickly obtain user traffic and complete the purpose of drainage and shopping guide.
He has come, he has come, wechat small program qimimi online new features: support URL Scheme open small program.
New product launch
URL Scheme open small program new online, quick to taste fresh.
You can follow brother Hu’s point of view for you one by one, summary analysis, you can also click the official document portal to view the official document yo ~
Let’s first take a look at the current micro channel official provided two ways to open micro channel small program and related application scenarios.
Open the way | Applicable scenario | Scene: the value | use | note |
---|---|---|---|---|
URL Scheme | Text messages, emails,WeChat outsideWeb page open applet | 1065 | location.href = 'weixin://dl/business/? t= *TICKET*' |
TICKET Is returned by the server interface |
<wx-open-launch-weapp> |
Within the WeChatWeb page | 1167 | Configuration page<wx-open-launch-weapp> The label |
Need to configure JS interface domain name or cloud development static web hosting binding domain name web pages |
It is important to distinguish between the two scenarios: URL scheme applies to external wechat web pages, while < wX-open-launch-aggregated P > applies to internal wechat.
Get the applets URL Scheme
The structure of the applets URL Scheme is weixin://dl/business/? T = *TICKET*, TICKET is returned by the server interface. Server-side interfaces distinguish between two forms: HTTPS calls and cloud development calls.
HTTPS call
-
Get ACCESS_TOKEN
Requested address:
GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET Copy the code
The corresponding APPID and APPSECRET can be replaced by their own applets.
The data structure returned is as follows:
{ "access_token": "ACCESS_TOKEN", "expires_in": 7200 } Copy the code
-
Get the URL Scheme
Requested address:
POST https://api.weixin.qq.com/wxa/generatescheme?access_token=ACCESS_TOKEN Copy the code
Request parameters:
attribute type The default value mandatory instructions access_token string is Interface call credentials jump_wxa Object no Jump to target applet information. is_expire boolean false no The generated Scheme code type, expired: true, permanent: false. expire_time number no The expiry time of the expired Scheme code is the Unix timestamp. The generated expired Scheme code is valid before this time. The maximum validity period is 1 year. This parameter is mandatory when an expired scheme is generated. The structure of jump_wxa
attribute type The default value mandatory instructions path string is The path to the page of the published applet must be the same as that of the published applet. Query is not allowed. If path is empty, the applet home page is redirected. query string is Query when the scheme code is used to enter a small program. The scheme code contains a maximum of 128 characters and only supports digits, upper and lower case English characters and some special characters. # $& ‘() *, + / :; =? @ – _ ~ Example request:
{ "jump_wxa": { "path": "/pages/index/index", query": "" }, "is_expire": true, "expire_time": 1606737600 } Copy the code
Return result:
{ "errcode": 0, "errmsg": "ok", "openlink": Scheme, } Copy the code
Openlink is the URL Scheme we need
Second, cloud call
Cloud call is the ability to call wechat open interface in cloud function provided by small program · Cloud development, which needs to be used in cloud function through WX-server-SDK
Request parameters:
attribute | type | The default value | mandatory | instructions |
---|---|---|---|---|
access_token | string | is | Interface call credentials | |
jump_wxa | Object | no | Jump to target applet information. | |
isExpire | boolean | false | no | The generated Scheme code type, expired: true, permanent: false. |
expireTime | number | no | The expiry time of the expired Scheme code is the Unix timestamp. The generated expired Scheme code is valid before this time. The maximum validity period is 1 year. This parameter is mandatory when an expired scheme is generated. |
Note The case that the case is different from the case in HTTPS
The structure of jump_wxa
attribute | type | The default value | mandatory | instructions |
---|---|---|---|---|
path | string | is | The path to the page of the published applet must be the same as that of the published applet. Query is not allowed. If path is empty, the applet home page is redirected. | |
query | string | is | Query when the scheme code is used to enter a small program. The scheme code contains a maximum of 128 characters and only supports digits, upper and lower case English characters and some special characters. # $& ‘() *, + / :; =? @ – _ ~ |
Example request:
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV,
})
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.urlscheme.generate({
jumpWxa: {
path: '/pages/index/index',
query: ''
},
isExpire: true,
expireTime: 1606737600
})
return result
} catch (err) {
return err
}
}
Copy the code
Return result:
{
"errcode": 0,
"errmsg": "ok",
"openlink": Scheme,
}
Copy the code
Openlink is the URL Scheme we need
The use of applets URL Scheme
The structure of the applets URL Scheme is: weixin://dl/business/? So t is equal to TICKET star, what if we get this scheme and we use it.
In IOS, URL schemes can be directly identified. Therefore, you can send URL schemes to SMS messages or emails for users. However, the Android system does not support the direct recognition of URL Scheme, so users cannot open the mini program normally in Scheme. Therefore, the developer needs to use the H5 page for transfer, and then switch to open the wechat mini program in Scheme mode.
end | use | note |
---|---|---|
Android | location.href='weixin://dl/business/? t= *TICKET*' |
There’s only one way |
IOS | Identify the URL Scheme directly or use the location.href approach | One of two ways |
But, we have to pay attention to a problem. When we make SMS contact, we cannot determine whether the user is using IOS or Android.
So, we need an H5 page for transfer processing from the actual business triggers.
Applets evoke business flow diagrams
Dangdang when, two ways of open the small program (URL Scheme and < wx – open – launch – weapp >), the full version of small programs to raise business process diagrams to ~
Afterword.
The above is brother Hu to share the content today, like partners remember to like, collect ah, pay attention to Brother Hu has words, learning front end don’t get lost, welcome a lot of messages exchange…
Hu Ge has words, focus on the field of front-end technology, share front-end system architecture, framework implementation principle, the latest and most efficient technology practice!