Preface
A mobile Internet company, in the final analysis, payers are always required to make profits. It is obviously not wise for a company with limited resources to develop its own payment system. Ali is one of many mature mobile payment providers in China.
Following Android App Payment Series (1): Detailed Guide to Wechat Payment Access Later, some of them came from Guo Lin's public address: guolin_blog readers and blog readers, hoping to write an access blog for Alipay app to pay sdk.
The author summed up the Alipay under Ali. Android SDK payment access process for later reference.
This article is authorized WeChat The public number guolin_blog (Guo Lin) was released exclusively.
The access process is as follows:
1 sign up to become Alipay merchants
Signing address: https://b.alipay.com/,
Only developers who become contracted merchants can have the qualifications to integrate Alipay app payment.
Signing materials: 1) Business license 2) APP description document 3) Business operation information, business contacts and other information.
APP apk is also required for audit if necessary. Code integration can be implemented after audit.
After the approval is passed, the information such as the merchant number assigned by Alipay can be obtained.
2 Client Code Integration Preparation
2.1 Import jar package resources
The latest version of Alipay's jar package download address: http://download.csdn.net/detail/xiong_it/9566771
After downloading, copy the libs directory and Eclipse automatically adds dependencies. Android Studio needs to add a line to app gradle
<code class="language-Groovy hljs livecodeserver has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">compile <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">files</span>(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'libs/alipaySdk-20160223.jar'</span>)</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>
Click on the top right corner: Sync Now, wait a moment.
2.2 Modify the Android Manifest. XML List
Statement of necessary activities
Add the necessary permissions
3 Client Code Integration
Schematic diagram of Alipay interaction process
Interpretation of Flow Chart in Vernacular
- app carries the payment information to call the payment interface request, and the Alipay client transfers the payment interface.
- User operation, input password payment, payment success; directly return to cancel payment; error, payment failure; enter the payment interface, but enter password payment, payment to be confirmed;
- The Alipay client tells the app client the result of payment, and the merchant server notifies the app server of the payment result.
- app client handles payment results.
- The app server processes the payment results.
The payment process of Alipay is more than that of WeChat Payment flow chart is one step less than the generation of APP server-side orders, but in its demo code, it is recommended to use app server for sign ature process, so the author simply follows the process of micro-payment.( Wechat Payment Interactive Process ) De-integrated.
- The client code obtains the information of the goods purchased by the user and passes it to the app server of the company. The parameters include, but are not limited to, the following:
Note: Alipay pays RMB units and WeChat pays, and UnionPay payment is slightly different. The other two payment units are:
All other parameters can be handed over to our app server. For more details, please click: https://doc.open.alipay.com/doc2/detail?treeId=59&articleId=103663&docType=1
- The app server refers to the link of the above detailed parameters, gets the sign field and returns the sign field to the mobile client.
- The mobile client uses sign signature information to initiate payment client in non-UI thread for payment.
User operation: input password to pay; return key to cancel payment; enter the payment interface, the user did not pay, the user returned, pending payment; network connectionless payment failure; - The client gets the payment result.
- Alipay server asynchronously notifications our company app server payment result (the server's work has nothing to do with the client).
Benefits of doing so: Signature logic is done on the server, app does not need to expose public and private keys, and is safer. It is also recommended in demo.
For more detailed explanation of Alipay access interaction process, please click: https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.7WO30X&treeId=59&articleId=103658&docType=1
4 Client Code Example
Payment callup code (must be in sub-threads)
Note: AliPay Result. Java PayResult. from Alipay demo Java
At this point, the integration of Alipay SDK ends. I wish you all successful integration of Alipay payment!
Concluding remarks
The author of this paper: xiong_it, Links to this article: http://blog.csdn.net/xiong_it/article/details/51819559
Attentions for Access to app Server: The official address given to fill in rsa public key is incorrect. Whatever prompt you fill in, the public key format is incorrect. Need to move to: Alipay public key to fill in the correct address fill in
udpate 20160714
Recent login development platform, found that the revision, in the original address to fill in rsa public key. Please know.
According to convention, the official demo download link of Alipay SDK access is attached: https://doc.open.alipay.com/doc2/detail.htm?treeId=54&articleId=104509&docType=1