If you have successfully integrated WeChat login and sharing, then this article will help you quickly integrate WeChat payment. This article is based on WeChat payment SDK3.1.1, which is the latest SDK so far. 1) WeChat official integration documentation 2) Download WeChat official resources Resource Downloads But I believe that even if you read WeChat's official documentation, you still don't know how to integrate WeChat Pay, because WeChat Pay's official documentation is simply too... If you have prepared the resource package, then start the integration The resources we need are actually the following. Before we start, let’s prepare these: 1) WeChat Pay APPID 2) WeChat payment dependency package >>> libammsdk.jar 3) An Activity class >>> WXPayEntryActivity.java Here we need to explain that this Activity class can be copied directly from the sample code downloaded above to your own project. This page is called when you call WeChat Pay to complete the payment (or cancel or fail) and then return to your App. The layout of the page can be your own layout. Here is a picture to explain: Let me first talk about the path of this class. There are a lot of introductions on the Internet. I will just put the picture. The path is certain and must be like this: Path to WXPayEntryActivity There are two things to note in this class: 1. The layout in this class can be customized. If you don't need to display any layout, but want to jump to the page, just delete this code. Callback page layout 2. The processing of callback results. The following is the official processing method. A dialog is given directly. Many people will be confused. If you don’t need this dialog, just delete it directly. There is no need to copy the layout and resources in the official demo. The official approach The following is my custom processing method, which is relatively simple. It just displays the payment result. If you need to jump after the payment is successful, you can start the Activity directly here. Don't forget to finish() this page. Custom processing method We don't need to operate the rest of the callback methods in this class Then we can start paying. Payment is very simple, really simple. Parameter List These are the parameters that WeChat Pay requires us to carry. For newcomers, it may be confusing how do I generate these parameters? In fact, these parameters are returned to us by the server. We can save the APPID locally, and the rest are returned to us by the server. Here is a brief introduction to the process: The process of initiating payment and submitting the order parameters are configured according to project needs ***, after the server returns the WeChat payment parameters to us, we can pay happily. This is a key step, pay attention!! Key steps to initiate payment At this point we can already call up the WeChat payment page to pay ***Another thing to note is that many people are trapped by this step, which is the issue of WeChat open platform signature. In fact, as long as the signature of the program on your phone is consistent with the signature you registered on the WeChat platform, it will be fine regardless of whether it is a debug version or a release version. WeChat Open Platform Signature For the convenience of testing, I temporarily filled in my debug signature. Of course, this can be changed. There will be a review period after the modification. I don’t know how many days it will take, but sometimes it will be very fast. When the application is about to go online, remember to change it to the official signature. I don’t know the number of modifications, you can Baidu it yourself! |
<<: Android Studio generates signature files, automatically signs, and obtains SHA1 and MD5 values
>>: Android nested sliding mechanism NestedScrolling
Is the performance of the mobile phone good? Just...
Suddenly, it is hard to say whether it is hype or...
[[162446]] CEO Zhang Yong said at the Global B2B ...
Employees can make authorization decisions, check...
Yesterday morning, Apple pushed the iOS 16.2 Bet...
The day before yesterday morning, a girl from Mai...
The changes of the times and channels will bring ...
Starting a business requires costs, and mini prog...
On June 21, the Hebei Provincial Public Security ...
Every time Apple releases a new version of iOS, it...
January 23 (Reporter Zhang Qian) If the battery l...
As a winner of Toutiao's Qingyun Plan and Bai...
Judging from the domestic SUV sales ranking for O...
Although according to my personality, I like to n...