A:

Recently, the SDK of Alipay, wechat and UnionPay have been updated, among which the SDK of Alipay has been greatly changed, and six files need to be imported from the original:

  • AlipaySDK.framework
  • AlipaySDK.bundle
  • Order. H and Order. M
  • Until the folder
  • Openssl folder
  • Libcrypto. A and libssl. A

After the new version, you only need to import two files, which are as follows:

  • AlipaySDK.framework
  • AlipaySDK.bundle

Below I on the basis of the old version of the article, for you to introduce in detail the latest version of alipay payment development process.

Because of the needs of work, I have summarized the iOS development pays nearly five classes related articles, pay treasure to pay, pay treasure to pay page turn client, WeChat, unionpay payment, Apple_pay, do the summary after the first it is convenient to consult, second also provide convenience for everyone, so as not to repeat on pit where used.

Start filling the hole!!

Two: interactive process

It is recommended to take a look at the development document carefully first, be sure to see, at the beginning of the time there is no honest to finish, the results encountered a lot of pits, waste a lot of time, so it is recommended to take a good look, especially this part of the interactive process.

2.1 Function Flow

Process description:

  • Step 4: Invoke the payment interface
  • Step 5: Payment request
  • Step 8: The interface returns the payment result
  • Step 12: Send payment notifications asynchronously

2.2 Data Interaction

Data interaction description:

  1. Construct the order data and sign it
  2. Send request data
  3. The payment development kit of mobile phone Alipay will process the requested data
  4. Returns the result data of the process
  5. The merchant processes the returned result data obtained

Three: Download alipay SDK

Alipay has a lot of business, it will take some time to find the payment SDK you want. Here is the latest SDK address (note that there is no legendary development document in the SDK package downloaded, you need to find it in other places or look at the website).

The use of public key, private key, PID, sellerID, and key and how to obtain them are all described in detail in the documentation, which will not be described here. You must clearly define the concepts before you do them, otherwise you will get confused later. We can discuss it together if we run into problems.

Four: Import library integration SDK

4.1 Import files and key libraries

Official Demo file

Copy the following files from the compressed file in the iOS package to the project folder and import them to the project:

  • AlipaySDK.framework
  • AlipaySDK.bundle

Add the following dependencies to the Link Binary With Libraries in the Build Phases TAB:

  • For Xcode versions later than 7.0, add libc++. TBD and libz.tbd.
  • For versions prior to Xcode 7.0, you need to add libc++. Dylib, libz.dylib (as shown below).

At this point, if you start the project, chances are you’ll find an error. #include <openssl/opensslconf.h> not find #include <openssl/opensslconf.h> not find #include <openssl/opensslconf.h>

Targets -> Header Search Paths under Build Settings Add the following directory “$(SRCROOT)/ project name/absolute address of file “as shown:

4.2

Add a header reference to the file where AlipaySDK needs to be called.

import <AlipaySDK/AlipaySDK.h>
Copy the code

4.3 Invoking the Payment Interface

In the access document of Alipay, the step of generating an order is put on the client side to do, but this is best put on the server side to do. Background generation order and then splicing, signature, and then the server side directly to the client side of an encrypted signature of the parameters can be, so it is safer. All order information, merchant information and so on are in their own hands, so that the APP side is not afraid of being intercepted data, and it is particularly simple to call, just need to call the interface of payment. If all you need to do is send the order and process the payment return result, you just need to add alipaysdK. bundle and AlipaysdK. framework, which are easy to find in the downloaded SDK. The quick payment method is this:

-(void)payOrder:(NSString *)orderStr fromScheme:(NSString *)schemeStr callback:(CompletionBlock)completionBlock;
Copy the code

In the button of payment, use alipay this class, and then call this method! Such as:

[[AlipaySDK defaultService] payOrder:credential fromScheme:fromScheme callback:^(NSDictionary* resultDic) {
            
    NSLog(@"% @",resultDic);
          
}];
Copy the code

4.4 Configuring the processing method of url Returned by alipay Client

As in the example AliSDKDemo\ apappdelegate. m file, add the reference code:

import <AlipaySDK/AlipaySDK.h>
Copy the code

Change the NSLog in the *@*implementation AppDelegate code to the actual business processing code:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    
    if ([url.host isEqualToString:@"safepay"] {// Jump to alipay wallet for payment, Handle payment results [[AlipaySDK defaultService] processOrderWithPaymentResult: url standbyCallback: ^ (NSDictionary * resultDic) { NSLog(@"result = %@",resultDic);
        }];
    }
    returnYES; } // NOTE: - (BOOL)application (UIApplication *)app openURL (NSURL *)url options:(NSDictionary<NSString*, id> *)options {if ([url.host isEqualToString:@"safepay"] {// Jump to alipay wallet for payment, Handle payment results [[AlipaySDK defaultService] processOrderWithPaymentResult: url standbyCallback: ^ (NSDictionary * resultDic) { NSLog(@"result = %@",resultDic);
        }];
    }
    return YES;
}
Copy the code

4.5 Project Configuration

Finally, don’t forget to also write a URL Scheme, the last one can be found under Targets -> Info, click the “Info” TAB, in the “URL Types” option, click “+”.

Here alipay payment is basically completed, if you encounter any problems in the integration process, you can leave a message to me or add QQ, online help you solve.

Pay attention to [net development] wechat public number, net the world method, convenient for you and ME to develop, more iOS technology dry goods waiting to receive, all documents will continue to update, welcome to pay attention to grow together!

Hope to help you, if you have questions can add QQ group: 668562416 exchange

If there is anything wrong or inadequate place, but also look for readers to make suggestions or suggestions

If you need to reprint, please contact me, after authorization can be reprinted, thank you