1. Integrated Alipay Payment
Alipay Integrates Official Tutorials https://docs.open.alipay.com/204/105295/
Alipay Integration Official demo https://docs.open.alipay.com/54/104509/
1. Import SDK and add dependent Libraries
Launch an IDE (such as Xcode) to iOS Package The following files from the compressed file in are copied to the project folder and imported into the project.
AlipaySDK.bundle
AlipaySDK.framework
In LinBinary With Libraries on the Build Phases tab, add the following dependencies
2. Add code to Appdelegate
Introduce header file
#import <AlipaySDK/AlipaySDK.h>
Add Payment Callback Method
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { if ([url.host isEqualToString:@"safepay"]) { // Payment Skip Alipay Wallet for Payment, Processing Payment Result [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) { NSLog(@"result = %@",resultDic); }]; // Authorize Skip Alipay Wallet to make payments and process payment results [[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) { NSLog(@"result = %@",resultDic); // analysis auth code NSString *result = resultDic[@"result"]; NSString *authCode = nil; if (result.length>0) { NSArray *resultArr = [result componentsSeparatedByString:@"&"]; for (NSString *subResult in resultArr) { if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) { authCode = [subResult substringFromIndex:10]; break; } } } NSLog(@"Authorization Results authCode = %@", authCode?:@""); }]; } //Here is WeChat payment if ([url.scheme isEqualToString:@"wxf6e443649d826e8e"]) { return [WXApi handleOpenURL:url delegate:(id<WXApiDelegate>)self]; } return YES; } // NOTE: 9.0 Use New Later API Interface - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options { if ([url.host isEqualToString:@"safepay"]) { // Payment Skip Alipay Wallet for Payment, Processing Payment Result [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) { NSLog(@"result = %@",resultDic); }]; // Authorize Skip Alipay Wallet to make payments and process payment results [[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) { NSLog(@"result = %@",resultDic); // analysis auth code NSString *result = resultDic[@"result"]; NSString *authCode = nil; if (result.length>0) { NSArray *resultArr = [result componentsSeparatedByString:@"&"]; for (NSString *subResult in resultArr) { if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) { authCode = [subResult substringFromIndex:10]; break; } } } NSLog(@"Authorization Results authCode = %@", authCode?:@""); }]; } //Here is WeChat payment if ([url.scheme isEqualToString:@"wxf6e443649d826e8e"]) { return [WXApi handleOpenURL:url delegate:(id<WXApiDelegate>)self]; } return YES; }
3. Add URL Scheme Configuration
Find the last URL Scheme under Targets -> Info,
Click the Info tab, in the URL Types option, click'+'.
4. Add the hanging Alipay method where the payment is made
Introduce header file
#import <AlipaySDK/AlipaySDK.h>
Payment Place Add Call Alipay Code
[[AlipaySDK defaultService] payOrder:@"Here is the order signature information from the background" fromScheme:@"Fill in the configuration for step 3 here URL Scheme" callback:^(NSDictionary *resultDic) { NSLog(@"=====%@",resultDic); if ([resultDic[@"resultStatus"]intValue] == 9000) { NSLog(@"Success"); } else { NSLog(@"fail"); } }];
2. Integrated WeChat Payment
WeChat Payment Integration Official Document https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_5
WeChat Integration Official demo https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=11_1
1: Import SDK and add dependent Libraries
Remember to add these two configurations (drawing focus) Pay attention to README inside the official Demo, pick up the notebook and write it down
2: Add code inside APPDelegate
Introduce header file
#import <WXApi.h> And add callback proxy @interface AppDelegate ()<WXApiDelegate>
Register WeChat
Add a payment callback method, the same code inside the Alipay integration code above
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { if ([url.host isEqualToString:@"safepay"]) { // Payment Skip Alipay Wallet for Payment, Processing Payment Result [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) { NSLog(@"result = %@",resultDic); }]; // Authorize Skip Alipay Wallet to make payments and process payment results [[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) { NSLog(@"result = %@",resultDic); // analysis auth code NSString *result = resultDic[@"result"]; NSString *authCode = nil; if (result.length>0) { NSArray *resultArr = [result componentsSeparatedByString:@"&"]; for (NSString *subResult in resultArr) { if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) { authCode = [subResult substringFromIndex:10]; break; } } } NSLog(@"Authorization Results authCode = %@", authCode?:@""); }]; } //Here is WeChat payment if ([url.scheme isEqualToString:@"wxf6e443649d826e8e"]) { return [WXApi handleOpenURL:url delegate:(id<WXApiDelegate>)self]; } return YES; } // NOTE: 9.0 Use New Later API Interface - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options { if ([url.host isEqualToString:@"safepay"]) { // Payment Skip Alipay Wallet for Payment, Processing Payment Result [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) { NSLog(@"result = %@",resultDic); }]; // Authorize Skip Alipay Wallet to make payments and process payment results [[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) { NSLog(@"result = %@",resultDic); // analysis auth code NSString *result = resultDic[@"result"]; NSString *authCode = nil; if (result.length>0) { NSArray *resultArr = [result componentsSeparatedByString:@"&"]; for (NSString *subResult in resultArr) { if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) { authCode = [subResult substringFromIndex:10]; break; } } } NSLog(@"Authorization Results authCode = %@", authCode?:@""); }]; } //Here is WeChat payment if ([url.scheme isEqualToString:@"wxf6e443649d826e8e"]) { return [WXApi handleOpenURL:url delegate:(id<WXApiDelegate>)self]; } return YES; }
Add WeChat Payment Callback Agent Method
//WeChat Callback,This method is called back when there is a payment result - (void)onResp:(BaseResp *)resp { // Payment Result Callback if([resp isKindOfClass:[PayResp class]]){ switch (resp.errCode) { case WXSuccess:{ //Payment returns results, actual payment results need to go to their own server-side query NSNotification *notification = [NSNotification notificationWithName:@"ORDER_PAY_NOTIFICATION" object:@"success"]; [[NSNotificationCenter defaultCenter] postNotification:notification]; break; } default:{ NSNotification *notification = [NSNotification notificationWithName:@"ORDER_PAY_NOTIFICATION"object:@"fail"]; [[NSNotificationCenter defaultCenter] postNotification:notification]; break; } } } }
3. Add URL Scheme Configuration
Find the last URL Scheme under Targets -> Info,
Click the Info tab, in the URL Types option, click'+'to fill in the APPId you requested.
Ditto
4. Add the method of invoking WeChat in the place of payment
Introduce header file
#import <WXApi.h>
Payment Place Add Call WeChat Code
1 if ([WXApi isWXAppInstalled]) { 2 NSLog(@"WeChat is already installed..."); 3 4 //This calls the back-end interface to get the details of the order, and then calls the WeChat payment method 5 }else{ 6 7 } 8 9 #pragma mark WeChat Payment Method 10 11 - (void)WXPayWithAppid:(NSString *)appid partnerid:(NSString *)partnerid prepayid:(NSString *)prepayid package:(NSString *)package noncestr:(NSString *)noncestr timestamp:(NSString *)timestamp sign:(NSString *)sign{ 12 13 //This payment object needs to be created 14 PayReq *req = [[PayReq alloc] init]; 15 //By user microsignals and AppID Unique identification composed to verify micro credit users 16 req.openID = appid; 17 // business id,Given at the time of registration 18 req.partnerId = partnerid; 19 // Reservation Order This is the one that the WeChat server sends to your server after the background interaction with the WeChat server, and your server sends it to you again 20 req.prepayId = prepayid; 21 // Data and Signature Filled in accordance with Payment Document 22 req.package = package; 23 // Random encoding, generated in the background to prevent duplication 24 req.nonceStr = noncestr; 25 // This is a timestamp and is also generated in the background to verify the payment 26 NSString * stamp = timestamp; 27 req.timeStamp = stamp.intValue; 28 // This signature is also made in the background 29 req.sign = sign; 30 if ([WXApi sendReq:req]) { //Send request to WeChat and wait for WeChat to return onResp 31 NSLog(@"Suspend WeChat Successfully..."); 32 }else{ 33 NSLog(@"Failed to suspend WeChat..."); 34 } 35 }
3. UnionPayment Integration
UnionPay for Mobile Control https://link.jianshu.com/?t=https://open.unionpay.com/ajweb/index
UnionPay.com https://www.aliyun.com/jiaocheng/349377.html
Drag the required library files into your project. The SDK file is located in the directory upmp_iphone/paymentcontrol, which contains two files, UPPaymentControl.h and libPaymentControl.a (the old version is three, which is different).
The method requires several parameter documents are written, tn is the transaction pipeline number, your server passed to you, our client can only use this parameter to invoke the payment control to pay.
So far: Third-party payment integration is generally integrated, look forward to the next article encapsulating code for three types of integration calls