公众号跳转小程序 (亲测有效)
html
<wx-open-launch-weapp id="launch-btn" username="gh_965e01ff" path="pages/phoneLogin/phoneLogin.html" style="width: 200px; height: 100px">
<template>
<div class="slider-img mt-3 px-2">
图片支持线上的和base64
<img src="../../images/img/ms-15.jpg" alt="img" data-animation="fadeInRight" data-delay=".6s">
</div>
</template></wx-open-launch-weapp>
js
$(function () {
$.ajax({
//请求方式
type: "GET",
//请求的媒体类型
contentType: "application/json;charset=UTF-8",
//请求地址
url: '/SignatureHandler.ashx',
//数据,json字符串
data: {//把经过encodeURIComponent()url传到后端,后端拿到了也要code一下
local_url: encodeURIComponent(window.location.href.split('#')[0]),
},
//请求成功
success: (data) => {
wx.config({
debug: false,//打开关闭调试
appId: data.appId,
timestamp: data.timestamp,
nonceStr: data.nonceStr,
signature: data.signature,
jsApiList: ['checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'hideMenuItems',
'showMenuItems',
'hideAllNonBaseMenuItem',
'showAllNonBaseMenuItem',
'translateVoice',
'startRecord',
'stopRecord',
'onRecordEnd',
'playVoice',
'pauseVoice',
'stopVoice',
'uploadVoice',
'downloadVoice',
'chooseImage',
'previewImage',
'uploadImage',
'downloadImage',
'getNetworkType',
'openLocation',
'getLocation',
'hideOptionMenu',
'showOptionMenu',
'closeWindow',
'scanQRCode',
'chooseWXPay',
'openProductSpecificView',
'addCard',
'chooseCard',
'openCard'
],
openTagList: [
'wx-open-launch-weapp',
'wx-open-launch-app'
]
})
},
//请求失败,包含具体的错误信息
error: function (e) {
console.log(e.status);
console.log(e.responseText);
}
});
});