1. Introduction This article is a summary of previous projects. Due to the iteration of related payment SDK, the original article no longer meets the needs, so it is updated as follows for your reference, and a summary of common problems is added. Today we will mainly introduce Alipay payment, and the introduction of other payment methods will be updated as soon as possible later. Before making the payment, I searched for information online, and most of the information said that there are too many pitfalls in payment access, WeChat has the most pitfalls, and UnionPay documents are too complicated. In fact, if there are more connections, those routines can be avoided. Most of the experiences on the Internet are relatively old, and there are not many new articles that can be used (but there are still some good articles, which have helped me a lot). Below I will give you a detailed introduction to help you avoid pitfalls. 2. Interaction process It is recommended to read the development documentation carefully first. You must read it. If you don’t read it carefully at the beginning, you will encounter many pitfalls and waste a lot of time. Therefore, it is recommended to read it carefully, especially the part about the interaction process. 2.1 Functional Flow 2.2 Data Interaction The functional process of Alipay payment is much simpler than that of WeChat payment. As shown in the two pictures above, our App (that is, the merchant client) only has three steps:
3. Download Alipay SDK Alipay has many businesses, and it takes some effort to find the payment SDK you want. Here is the latest SDK address Please note that the downloaded SDK package does not contain the legendary development documentation, so you need to look for it elsewhere or on the web. The purpose and acquisition methods of public key, private key, PID, sellerID, key are all described in detail in the document, so I won't repeat them here. You must understand the concepts clearly before doing it, otherwise it will be confusing. If you encounter any problems, we can discuss them together. 4. Import library and integrate SDK 4.1 Import files and key libraries Import via CocoaPods
Manual import Official demo screenshots Open the iOS project, the new version SDK file Order file, you need to copy and paste it into your own project:
Some of the above files cannot be seen in the opened project and need to be found in the project folder. In the Link Binary With Libraries section of the Build Phases tab, add the following dependencies: Among them, it is important to note that:
At this point, if you start the project, you will most likely get an error. 4.2 Import header files In the file that needs to call AlipaySDK, add the header file reference.
4.3 Calling the payment interface In the access document of Alipay, the step of generating an order is done on the client side, but it is better to do it on the server side. The order is generated in the background, spliced and signed, and then the server directly passes an encrypted and signed parameter to the client, which is safer. All order information, merchant information, etc. are in your own hands, so there is no need to worry about data interception on the APP side, and it is also very simple to call, you only need to call the payment interface. If you only need to send orders and process payment return results, you only need to add AlipaySDK.bundle and AlipaySDK.framework, which are easy to find in the downloaded SDK. The quick payment method is this:
In the payment button, use the Alipay class and call this method! As follows:
4.4 Configure the URL processing method returned by the Alipay client For example, in the AliSDKDemo\APAppDelegate.m file, add the reference code:
In @implementation AppDelegate, change the NSLog in the following code to the actual business processing code:
4.5 Project Configuration Finally, don't forget to write a URL Scheme, which can be found in the last one under Targets -> Info. Click the Info tab, and in the URL Types option, click +. 5. FAQ Summary 5.1 Unable to return to the App after payment This is usually because the whitelist is not set up correctly
The appScheme parameter in the above code needs to be the same as the URL Schemes set in the project configuration in article 4.5, so that the corresponding App can be returned. 5.2 #include not find This is a mysterious pitfall. I Googled it for a long time but couldn't figure it out. Then, after being reminded by netizens, I remembered the difference between #import "" and #import <>. Solution: Header Search Paths under Targets -> Build Settings. Add the following directory "$(SRCROOT)/project name/absolute address of the file" As shown in the figure: 5.3 'openssl/asn1.h' file not found Since the openssl library is introduced into the project, this problem occurs because the library file project cannot be found. You only need to add $(PROJECT_DIR)/project name/openssl in the Header Search Paths, as shown in the following figure: 5.4 Undefined symbol: OBJC_METACLASS$_WKWebView If the above problem occurs, you need to add the system library to the project configuration: WebKit.framework 5.5 If an error message is displayed after running, it is similar to the following message:
Then you need to open the file where the error is reported and add the header file.
5.6 Problems encountered when accessing SDK in Swift If the project uses Swift as the development language, you need to add a bridging file, such as Bridging-Header.h Also, set the location of the bridge file in the project Build Settings. If the following error occurs during runtime, write #import in the bridge file 5.7 Click on payment to jump to the Alipay card startup page In this case, the page where the user is stuck will display a corresponding error message. Generally, there are the following situations:
|
<<: WeChat 8.0.1 is here! Finally, you can display your online status
Li Ruigang, a legendary figure in China's med...
All rivers flow into the sea, which not only refe...
This time, the editor will continue to share with...
What’s the most popular thing in the past six mon...
LONDON, United Kingdom — Three years after the Un...
Even if they are 300 kilometers away, humans can ...
Author: Hu Bingjie Zhou Yi Xi'an Medical Coll...
With the transformation of my country's econo...
The theory of "growth hacking" has beco...
As earthlings, it is easy for us to believe that ...
Due to the impact of the epidemic, the summer enr...
The recent "Feel Good" team Going out f...
How much does it cost to invest in the Haikou chi...
What is Fengwu? Fengwu is a major innovation in t...
On October 20, 2015, OPPO held its autumn new pro...