WeChat payment can only be called once.

Source: Internet
Author: User

Payment can be called only once.

I have been using Android for some time, but I have not systematically studied it. I have been focusing on server-side development for many years. I always feel that it is only temporary because the project needs to be connected to Android mobile development, so I am not so worried, as a result, I encountered a big problem for a day, and finally I was prompted by experienced friends to solve the problem. I felt like I was not alone, and I was very happy. After all, I grew up one by one, here, we can't tell you how to change places, haha. Let's talk about it here and share it with you:

It is necessary to briefly describe the overall process of the payment Calling Interface (currently, most of the information on the Internet is applicable to the old version of the Payment Code. The latest payment official documentation does not contain the server Demo, and some interfaces have changed, the parameter name also changes, so we hope you can pay attention to it ):

1. You do not need to access the Token interface for payment;

2. Access the https://api.mch.weixin.qq.com/pay/unifiedorder directly to get the Prepayid, the parameter can be transmitted in xml format;

3. With Prepayid and some other parameters mentioned on the official website, you can call the client's payment interface;

 

At this point, the problem occurs: the first call is very OK, and the payment interface is displayed, there is a self-generated order number and there is still amount, but after the payment is abandoned, and then enter, even the client cannot call it, the same is true for changing an order. Changing a mobile phone number is also the first order to call the client and display the order number and amount. However, the second order does not work. It is fixed on the Payment interface of your APP and no error is reported, no response.

The reason is here: When we apply for payment, there is a place for you to fill in your application Key:

After the application you see is the application signature on the image, how is this signature generated here are introduced: https://pay.weixin.qq.com/wiki/doc/api/app/app.php? Chapter = 8_5

The problem is that the Key is generated based on the signature package during the official release, when releasing an Android app, we add this Key as the app key to prevent malicious coverage, when applying to register an application, we must provide the officially generated application Key to the official website.

Therefore, this is ignored, so that during the development process, we run the package locally, and when the access server calls the payment, the first time we received the request from our application, it seemed that a connection had started to heartbeat,

At this time, it will be verified asynchronously Based on the reserved application package name and application Key and the package name and application Key you sent now. I believe that even if you make the payment for the first time, it is very likely that it will fail, however, I have not verified the verification, because the verification result callback has been returned at this time.

So when the O & M personnel took the Release, they sent the Key to the command in the APK installation package to package the formal Key. The command is as follows:

1 ''' cordova build -- release android2 3 jarsigner-verbose-sigalg SHA256withRSA-digestalg SHA1-keystore E: \ android-release-key.keystore E: \ Project name \ platforms \ android \ build \ outputs \ apk \ android-release-unsigned.apk android-release-key.keystore4 5 // after running this command, enter the password 6 7 zipalign-v 4 E: \ Project name \ platforms \ android \ build \ outputs \ apk \ android-release-unsigned.apk a.apk 8 9 '''

 

The problem is solved. Payment can be successfully called every visit. I have to feel that I have strictly controlled the applications registered with him. I want to register a Key and use it again. Let's go through the process again.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.