Common payment methods in projects
Note: This article only explains from the front-end perspective Alipay PaymentProject Difficulty: The page is an h5 web page. To pay with Alipay, you must obtain Alipay authorization and call Alipay's API. (For how to authorize, please refer to: Calling Alipay API) The general process of Alipay payment is: Call the order interface to obtain the order number, payment amount, etc. Payment process: The following figure is the interface document, payment interface When we select Alipay, radio=1; topay(){ switch(this.radio){ case '3': this.yuer(); break; case '1': this.zhifubao(); case '0': this.getWechatCode(); } }, zhifubao(){ payByZhifubao( { OutTradeNo:'Oct20200909095646265303127', //Merchant order number, the only order number in the merchant website order system, required. The merchant side must be unique. Subject: "Mobile Website Payment Test", //Topic ProductCode: "QUICK_WAP_WAY", body: "Mobile website payment description information", //Product description, optional TotalAmount: 20 //Payment amount, required} ).then(res=>{ console.log(res); if (res.code === 201) { //Save data in vuex // this.$store.dispatch('addAliFrom', res.data.data) this.html = res.data; var form = res.data; const div = document.createElement("div"); div.innerHTML = form; //Here form is the data returned by the background document.body.appendChild(div); document.forms[0].submit(); //return this.$router.push('/aliPay') } else { return alert(res.data.msg); } }) }, WeChat Pay step: <div id="wechatcode" v-loading="loading" element-loading-text="Loading" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)"> </div> Importing modules import QRCode from 'qrcodejs2' // Import qrcode The following is the interface data acquisition and then operation QR code getWechatCode() { Models .getModel("wechatpay") .get({ orderId:this.orderId }) .then(res => { if(res.data.code == 200){ this.wechatPayUrl = res.data.resultData if(!this.flag){ //The key point is here, the rest is for my switching business logic and interface let wechatcode = new QRCode('wechatcode', { width: 200, height: 200, text: this.wechatPayUrl, // QR code address colorDark: "#000", colorLight: "#fff", }) } this.flag = true this.loading = false this.isWechatCodeShow = true } }) }, After WeChat scans and pays, the backend staff can get the payment success result and return it to the frontend staff. Then the frontend staff can only keep calling the interface to check whether the payment has been made. Here we can use the life cycle to do polling, and it needs to be destroyed after jumping out. mounted() { this.getWechatCode() //Implement polling this.interval = window.setInterval(() => { setTimeout(this.getOrderStatus(), 0); }, 3000); }, beforeDestroy() { // Clear polling clearInterval(this.interval) this.interval = null }, The `getOrderStatus() method here is to query the backend payment status. If you successfully jump to the payment page, just do an If else judgment This is the end of this article about the implementation of payment functions in vue projects (WeChat payment and Alipay payment). For more relevant vue project payment content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Pure CSS to achieve hover image pop-out pop-up effect example code
>>: How to align text boxes in multiple forms in HTML
How to install Linux CentOS 7.7 system in Vmware,...
Delayed loading (lazy loading) and preloading are...
1. Overflow Overflow is overflow (container). Whe...
1. Environment and related software Virtual Machi...
Table of contents 1 Use of v-if and v-show 2. Dif...
Table of contents 1. Ref and reactive 1. reactive...
The DATE_ADD() function adds a specified time int...
This article shares with you how to use Vue to im...
The simple installation configuration of mysql5.7...
Table of contents 1. Basic concepts and basic com...
1. Background that needs to be passed through CSS...
Preface In actual development, business requireme...
After starting Docker, let's take a look at t...
1. Download and decompress MySQL 8.0.20 Download ...
Table of contents Introduction Using Strict mode ...