外部h5网页跳转微信指定页面
解决所有外部地址跳转微信小程序指定页面
跳转主要是通过后端获取指定的url scheme链接进行跳转
直接上demo
<body>
<div id="app">
<div class="btn" @click='gowx'>
跳转
</div>
</div>
<script src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
<script src="./vue.min.js"></script>
<script src="./jquery-1.8.2.min.js"></script>
<script>
var vue = new Vue({
el: '#app',
data() {
return {
token: '',
userId: ''
}
},
created() {
// this.login()
},
methods: {
login() {
var that = this
var data = {
regPhone: '',
password: '.'
}
return new Promise((resolve, reject) => {
$.ajax({
url: '登录的地址', //获取token用的
type: 'post',
headers: {
"Content-Type": 'application/json',
},
data: JSON.stringify(data),
success(res) {
console.log(res);
if (res.errcode == 0 || res.errcode == '0') {
that.token = res.data.accessToken
that.userId = res.data.userId
console.log(that.token, that.userId);
}
resolve()
},
})
})
},
gowx() {
var that = this
that.login().then(() => {
let data = {
path: 'pages/pay/pay',
type: 4,
// envVersion: 'trial',
query: `token=${this.token}&orderAmount=0.01&userId=${this.userId}&payType=6&payItem=1`
//通过query传递的参数
}
console.log(data);
$.ajax({
url: '获取urlscheme的地址接口generateScheme',
type: 'post',
headers: {
"AccessToken": '7498c53298a9496786d350a97ac3236f',
"Content-Type": 'application/json',
},
data: JSON.stringify(data),
success(res) {
console.log(res, '666');
if (res.errcode == 0 || res.errcode == '0') {
location.href = res.data //拿到的地址给到location跳转即可
}
}
})
})
},
}
})
</script>
</body>
更多推荐
所有评论(0)