Detailed explanation of the payment function code of the Vue project

Detailed explanation of the payment function code of the Vue project

1. Alipay method:

Alipay method: Click Alipay to pay, call the backend interface (with the order number), and the backend returns a form (HTML string structure).

Submit the form to call Alipay payment

Code:

// alipayWap: form fragment returned by the background interface <div v-html="alipayWap" ref="alipayWap"></div>
methods: {
	toAlipay() {
		this.$axios.get('xxx').then(res = > {
			this.alipayWap = res;
             // Wait for DOM to update, and then the form will appear on the page this.$nextTick(() => {
            	this.$refs.alipayWap.children[0].submit()
          	})
		})
	}
}

2. WeChat Pay

Most of the workload is done by the backend. The order generation is done by the backend and connected to Tencent. The frontend is only responsible for displaying the payment QR code returned by the backend (generated by the backend. In some cases, the frontend can also connect to the order generation and then generate the QR code by itself, but this situation is relatively rare) on the terminal for users to scan.

You need to generate a QR code page based on the URL returned by the background, as shown in the figure

QR code display code:

Request the payment QR code interface of the backend

Finally, scan the QR code and pay.

This is the end of this article about the payment function of the vue project. For more relevant vue payment function content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Payment function implementation in vue project (WeChat payment and Alipay payment)
  • springboot+vue+docking Alipay interface+QR code scanning payment function (sandbox environment)
  • Pitfalls encountered in implementing WeChat payment function in Vue
  • Vue's H5 page invokes the Alipay payment function
  • Vue imitates Alipay payment function

<<:  The difference between GB2312, GBK and UTF-8 in web page encoding

>>:  Solution to the ineffective margin of div nested in HTML

Recommend

Method to detect whether ip and port are connectable

Windows cmd telnet format: telnet ip port case: t...

Example of how to configure multiple virtual hosts in nginx

It is very convenient to configure virtual host v...

Mysql string interception and obtaining data in the specified string

Preface: I encountered a requirement to extract s...

Detailed analysis of when tomcat writes back the response datagram

The question arises This question arose when I wa...

How to write configuration files and use MyBatis simply

How to write configuration files and use MyBatis ...

MySQL should never write update statements like this

Table of contents Preface cause Phenomenon why? A...

Pure js to achieve typewriter effect

This article example shares the specific code of ...

Why should you be careful with Nginx's add_header directive?

Preface As we all know, the nginx configuration f...

Detailed explanation of redo log and undo log in MySQL

The most important logs in the MySQL log system a...

How to deploy Tencent Cloud Server from scratch

Since this is my first post, if there are any mis...

Let's talk about the size and length limits of various objects in MySQL

Table of contents Identifier length limit Length ...

Introduction to the use of the indeterminate property of the checkbox

When we use the folder properties dialog box in Wi...

Illustration-style website homepage design New trend in website design

You can see that their visual effects are very bea...