【无标题】vue pc支付宝支付/微信支付

微信支付

实现思路:安装插件qrcode,通过后端接口返回数据(微信支付链接),生成二维码回显在页面上进行支付,回调调用后台接口获取订单状态是否改变
实现步骤:
1.npm install --save qrcode
2.在需要用到的页面引入
import QRCode from ‘qrcode’
3.获取接口数据,使用qrcode回显
createQR(codeUrl) {
let opts = {
errorCorrectionLevel: “H”,
type: “image/png”,
quality: 0.3,
margin: 5,
width: 300,
height: 300,
color: {
dark: “#000”,
light: “#FFF”
}
}
QRCode.toDataURL(codeUrl, opts, (err, url) => {
if (url == undefined) {
this.KaTeX parse error: Expected 'EOF', got '}' at position 30: …'支付调起失败') }̲ else { c…message.success(“支付成功~”);
clearInterval(this.timer);
window.clearInterval(this.timer)
this.timer = null
setTimeout(() => {
this.$router.go(-1)
}, 1500);
}
});
}, 5000);
//离开页面时清除掉定时器
beforeDestroy() {
clearInterval(this.timer)
this.timer = null
},

支付宝支付 前置二维码

1.跳转页面
const div = document.createElement(“div”);
div.innerHTML = from;
document.body.appendChild(div);
document.forms[0].submit();// 执行后会唤起支付宝
2.内嵌使用

< iframe :srcdoc=“form接口数据” frameborder=“no” border=“0” marginwidth=“0” marginheight=“0” scrolling=“no” width=“300” height=“300” style=“overflow: hidden” > < /iframe>

### Vue实现扫码进行微信支付的方法 在Vue中实现扫码进行微信支付,大部分工作量在于后端,订单的生成由后端和腾讯对接。前端的主要工作是展示后端返回的支付二维码供用户扫码。 1. **安装生成二维码的插件**:可以安装`qrcode`插件用于生成二维码,命令如下: ```bash npm install --save qrcode ``` 2. **在页面引入插件**:在需要使用二维码的页面引入`qrcode`。 ```vue <template> <div> <img :src="qrCodeUrl" alt="微信支付二维码"> </div> </template> <script> import QRCode from 'qrcode'; export default { data() { return { qrCodeUrl: '' }; }, mounted() { // 请求后端的支付二维码接口 this.getWechatPayQrCode(); }, methods: { async getWechatPayQrCode() { try { // 假设这是请求后端支付二维码接口 const response = await fetch('/api/wechat-pay-qrcode'); const codeUrl = await response.text(); this.createQR(codeUrl); } catch (error) { console.error('获取微信支付二维码失败', error); } }, createQR(codeUrl) { let opts = { errorCorrectionLevel: "H", type: "image/png", quality: 0.3, margin: 5, width: 300, height: 300, color: { dark: "#000", light: "#FFF" } }; QRCode.toDataURL(codeUrl, opts, (err, url) => { if (err) { console.error('生成二维码失败', err); } else { this.qrCodeUrl = url; } }); } } }; </script> ``` 3. **后续业务逻辑**:扫码完成支付后,后续完成支付就是项目中的业务逻辑,比如回调调用后台接口获取订单状态是否改变等操作。 ### Vue实现扫码进行支付宝支付的方法 #### PC端 同样,PC支付宝支付主要工作量在后端,后端生成订单后返回支付二维码,前端展示二维码供用户扫码。前端操作和微信PC支付类似,展示后端返回的二维码即可。 #### 移动端H5支付 后端完成订单的生成之后返给前端的是form表单,前端负责页面的跳转。 ```vue <template> <div> <button @click="onSubmit">立即支付</button> </div> </template> <script> export default { data() { return { payWay: 1, // 1表示支付宝支付 orderId: '123456' // 假设的订单ID }; }, methods: { onSubmit() { if (this.payWay === 1) { // 支付宝支付 window.location.href = `/api/alipay-h5-pay?orderId=${this.orderId}`; } } } }; </script> ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值