Talk about pit development payment function encounter

Original article in Public number: ape Zhou Xiansen program. This platform is not updated regularly, like my article, I welcome attention to the micro-channel public number.
file

Recently because of new requirements, the need to develop Alipay payment function as well as micro-channel payment functions two or three days to develop ran down a few Bug, recorded here for the future can learn new things. Because Alipay function is the H5 end use, so use the function to pay Alipay scan code to generate a payment of two-dimensional code, and then save the user two-dimensional code scan code to Alipay payment operations. Bumps all the way out to improve the function, but ran into a few pit. Alipay problems encountered in the development of:

1. Invalid APP_ID
file

In fact, the problem is most likely to commit a mistake, because Alipay function sandbox test environment.

After a review documents found Alipay app_id and gateway addresses do not match resulting in ineffective app_id this problem occurs, locate the cause of the problem, I will be including the network environment is set to sandbox environment gateway address, and a sandbox environment app_id, then released outside the network then after the environment into a formal environment, then it really solved the problem, and then check the information to carry out inspection operations, Alipay will pay to return a two-dimensional code link, click it will open the two-dimensional code interface
file
file

Then scan code Bao payments made to complete payment function.

2. Alipay callback function multiple times

Probably because of imperfect sandbox environment, Alipay function successfully run in a sandbox environment, and the callback function only once, but will be paid after the release function outside the network, there is a problem Alipay perform multiple callback function, because demand is to catch, so I will be subject to payment of treasure to perform multiple updates to the callback affect database operations performed by the comment, and then this part of the logic of the code written inside polling access user interface payment status, but this creates a problem if the user Screenshot dimensional code scan code to go Alipay payment, the successful return of two-dimensional code interface it can be called a successful update the database interfaces polling operation, but there are some models press the two-dimensional code can jump directly Alipay, but this operating've paid return interface when the two-dimensional code interface disappears, it can not execute a user interface to access polling payment status, which would cause the user to pay for the successful integration but no results recharge credited into account, the final eventually go back to solve The first question: Why Alipay perform multiple back Function?
file

A search of the document I found this sentence: After the implementation of the program must print out "success" (without the quotes). If the merchant back to Alipay's character is not a success this seven characters, Alipay server will continue to resend the notification until more than 24 hours 22 minutes. Explain the perfect development of the document gives reason Alipay multiple callbacks: because users pay for the successful implementation of the database update operation callback function does not return success string to Alipay, so Alipay think I have not succeeded callback, it will ongoing implementation of the callback function, which also led to my database update operations are repeatedly executed. I put the code logic to handle it in accordance with the document, to test again, and sure enough on the causes of the callback function is executed many times not appear.

The development of micro-channel payment problems encountered

1.Native can not click on the payment link to make payments

Micro-channel payment I only use Native scan code to pay, because there are lessons Alipay, so early basic configuration no problems, successfully generated micro-channel payment link, but this time the emergence of a pit, this link may open payment interface directly in the micro-letter
file
file

But then the password will prompt payment transaction does not currently support click on the message link initiated, that is to say although we have successfully generated payment links, but we can not pay
file

Later, I went to read a micro-channel development documents for payment is introduced Native: Native merchant payment system is by generating micro-channel payment agreement to pay two-dimensional code, the user then micro letter "sweep the" complete mode of payment. That Native payments are paid to generate two-dimensional code, then sweep the re-payment, but will only return a micro-channel pay two-dimensional code link, and not directly to Alipay as a two-dimensional code address, so we need to use micro-channel pay two-dimensional code to generate a successful return address pay two-dimensional code, and front-end through negotiation colleagues, this part of the front-end logic implemented in order to test the payment function, I used a little two-dimensional code generator online, the micro-channel payment linked to the successful return of the corresponding payments generated two-dimensional code.
file

Then use the micro-channel scan code payments were finally successful payment, so the payment can not be used directly Native micro-channel payment link to make payments, but need to pay Mr. dimensional code, then sweep sweep sweep code be paid.

2. The actual price paid and to pay the price does not match

While the micro-channel payment can be successfully run up, but there is a problem: we need to pay a dollar, but in the end they can only generate a payment link to pay a penny, check the specific reasons for the development of micro-channel payment documentation did not find this problem, but found in Baidu library a reason, micro-channel pay Alipay not the same micro-channel payment to be divided into units, so if you want to dollar as a unit, parameter total_fee accepted after the front passed over price multiplied by 100, this problem can be solved a.
file

3. The micro-channel repeatedly callback

Micro-channel development near the end, I was in the same pit and fell down again, micro-channel pay repeatedly execute a callback function, and because of pay lessons treasure to pay, I immediately thought it must be a callback to return after successful execution of a micro-channel parameters problem, I went to check the micro-channel pay under development documents: after the micro-channel asynchronous notification, but also need to micro-channel server returns a message, but, all data formats are xml of micro-channel. So we return the data to a micro letter can be. Rather than return to success and Alipay as you can.
file

I follow the documentation requirements in the callback function to return_code and return_msg packaged into xml format returns, micro-channel problem repeatedly callback function successfully resolved. Here micro-channel payment functions to successfully run up. In fact, there are many pit payment function, but I stand on the shoulders of our predecessors, so pre-configured and signature most problematic in those places I have smooth sailing on the success, problems encountered in the development of their own record here, hope you can give a friend in need a little help.

No. I personally welcome attention to the public: Program ape Zhou Xiansen
file

Guess you like

Origin www.cnblogs.com/niyueling/p/11562994.html