1.登录 支付宝开放平台 创建 网页/移动应用


2.填写创建应用信息

3.配置开发设置

4.网页/移动应用:需要手动上线。提交审核后,预计 1 个工作日的审核时间。详细步骤可点击查看 上线应用 。应用上线后,还需要完成产品开通才能在线上环境(生产环境)使用产品。
5.把以下东西提供给后端
APPID

商户id

应用私钥(RSA2私钥)

支付宝公钥

接口内容加密密钥

h5接入支付宝支付
1.新建一个页面拿后端返回的form表单渲染成页面
javascript
<template>
<view>
<div class="body">
</div>
</view>
</template>
<script>
export default {
data() {
return {
formUrl: '' // 用于展示form表单的URL
};
},
onLoad() {
const Form = uni.getStorageSync('Form'); //获取你本地存储的form表单渲染成页面
this.formUrl = Form
//将接口返回的Form表单显示到页面
document.querySelector('body').innerHTML = this.formUrl; // body对应上面的class
this.$nextTick(() => {
console.log(document.forms,"form"); //跳转之前,可以先打印看看forms,确保后台数据和forms正确,否则,可能会出现一些奇奇怪怪的问题 ╮(╯▽╰)╭
document.forms['0'].submit(); //重点--这个才是跳转页面的核心,获取第一个表单并提交
});
},
methods:{
}
};
</script>
<style scoped>
</style>
2.点击支付调用该方法
javascript
openPayment(){
var that = this
that.$httpRequest({
url: '路径',
method: 'POST',
data:{
参数
}
}).then(res => {
uni.setStorageSync('Form', res.data.data)
console.log('支付宝订单数据', res);
//跳转到新建的页面
uni.navigateTo({
url: `/pages_subPackages/orders/zfb`
});
})
},
3.支付成功后不会跳转页面需要后端设置支付成功后需要跳转的页面即可