In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to achieve WeChat Pay development based on H5. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
I. Preface
Why am I still writing a blog about WeChat Pay interface? First, we must know that much of the so-called work experience is summed up. Only when you sum up more knowledge and accumulate more experience can you stand out in the industry. I personally think that today's recruitment, many need work experience (1 year, 3 years, 5 years.), in fact, the long working hours can not measure a person's technical level. Some people with one year's work experience can be paid by programmers with three years' work experience, while others with three years' work experience may be lower than those with only one year's work experience, so summing up can make their own knowledge system. The depth of experience is stronger and more stable (although it takes time to write a blog post) Second, there is a sense of achievement in writing a blog post and sharing it with you. First of all, it allows beginners to learn from the blog post I share, and can quickly apply the technology explained in the blog post to practice. So my blog post can basically make the newcomers quickly read and easy to understand. In addition, the words of the great god of technology, you can also point out that there is something wrong with the blog post, and you can communicate, so why not do it? What we need is sharing and communication.
If you go too far, go straight to the detailed explanation of the subject.
There are now N ways of WeChat Pay. See the picture below, there are payment by card, official account, scan code and APP, as well as the development of payment tools. This blog chooses official account payment as an excuse to develop and explain. The development of other payment interfaces is basically the same, as long as you can understand the basic ideas explained in my blog. You can basically develop several other payment interfaces on your own.
Second, a detailed explanation of the train of thought
We can take a look at the business process sequence diagram in the WeChat Pay interface document. As shown in the following figure, the basic idea is as follows: first, generate a link in the background and show it to the user for click (for example, there is a WeChat Pay button on the page). After the user clicks the button, the website backend will generate a payment order based on the relevant information of the order. At this time, the unified order issuing API will be called. After initiating a request to WeChat Pay's system, WeChat Pay's system will generate a prepaid transaction session ID (prepay_id, which is used to identify the order) based on the requested data. After receiving the response from WeChat Pay's system, our website will get prepay_id, then construct the parameters needed by WeChat Pay ourselves, and then return the required parameters for payment to the client. At this time, the user may have an order information page, there will be a button, click on the payment, at this time, the JSAPI API will be called to initiate a request for payment to the WeChat Pay system. After WeChat Pay's system checks the relevant validity of the request, it will prompt for a password, the user will enter the password to confirm, WeChat Pay's system will verify it, and if it passes, it will return the payment result, and then Wechat will jump to the H5 page. One of the steps is to notify the website of the payment result asynchronously, which needs to be processed by our website (for example, after the asynchronous payment result is passed, you need to update the data table or order information, such as indicating that the user has paid the order. At the same time, you also need to update the order log to prevent users from submitting orders repeatedly).
Third, code explanation
This development environment uses php5.6 + MySQL + Redis + Linux + Apache, the CI framework of the selected framework (these environments do not necessarily need to be consistent with mine, the framework can also choose their own, anyway, their own slight changes to the code can be ported to the past).
I have written the development code of the WeChat Pay interface in advance. Here I analyze and explain it so that you can easily understand it. Of course, if you have a certain foundation, you can sort out all the processes by looking directly at the code. And my code is basically commented (for beginners, this is better than the code provided by Wechat documentation).
1. Construct a link and show it to the user
We need to know one point in advance here, that is, the openid of Wechat users is required for the API to request a unified order (for more information, please see the https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1). To obtain the openid, you need to obtain the code (for more information, see the Wechat login API), so we need to construct a URL to obtain the code:
Wxpay.php file:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.