# wx.miniapp.launchMiniProgram
App Pull up the WeChat Mini Program
# Precautions before Access
- This ability dependsWeChat Open SDK, need to follow the guidelines in theWeChat Open PlatformCreate a mobile application account to complete the relevant initialization configuration, details can be viewedWeChat mobile application capability initialization guidelines
# parameter
alignmentWeChat opensdk Jump Mini ProgramParameters, easy to understand
attribute | type | Default value | Required | Introductions |
---|---|---|---|---|
userName | string | yes | Mini Program original ID, such as gh_d43f693ca31f,[Click to see how to get it](https://dev.weixin.qq.com/docs/framework/faq/dev.html#_1, how to get the Mini Program original -id) | |
path | string | Default pull up Mini Program home page | no | Pull up the detachable path of the Mini Program page, such as: "?foo=bar"。 |
MiniprogramType | number | Default is the official version | no | Optional Open 0 - Official, 1 - Development, 2 - Experience |
success | function | yes | Successful callback after getting |
# JSAPI Examples of code
// Login
wx.miniapp.launchMiniProgram({
userName: 'gh_d43f693ca31f', //Mini Program Original ID
path: 'originfiles/pages/miniapp/miniapp?action=login',
MiniprogramType: 2, //0 Release ,1 test, 2 preview
success: (res) => {
wx.showModal({
content: res.data,
})
console.log('get wx phone number success:', res)
}
})
# WeChat Mini Program Back to App
Developers can useButton Tags Jump back to App.
Note: in the case of Android, when SDK 1.2.17 In the case of the following version, the developer needs to carry the information of the app in the app-parameter to return the multi-terminal app normally, as follows. IOS doesn't need it.
When multi-terminal apps evoke WeChat mini-programs, they carry app-related information, which developers can get in the parameters of the onLoad function on the page.
The information obtained needs to be returned to the app in the app-parameter of the button tag. You can also bring information that the developer wishes to return.
Android App If you do not do the above, an error may occur:sendOpenReq failed:fail opensdk failed And did not return to the multi-terminal app through WeChat.
onLoad(res) {
// Page corresponds to the onLoad function to get information from the app
transitiveData = res
// The information brought by the app needs to use transitiveData as the key, and the developer's own data can be included in the data.
const Data = {
data: "MsgBackToApp"
transitiveData
}
// Set the required information into data, so that the button tag can get the
this.setData({
dataStr: JSON.stringify(Data)
})
}
<button open-type="launchApp" app-parameter="{{dataStr}}" bindtap="tap" >
Back to App
</button>