# # # # this is opening recently made a project, involving alipay and and unionpay to pay, pay treasure and unionpay is the industry’s big brother, documentation, the SDK is bad, dream, dream don’t understand, good have no friends (just teasing 😄), this paper will involve the latest available SDK, documentation, and I pay some pit tag.

https://doc.open.alipay.com/doc2/detail?treeId=54&articleId=103419&docType=1
Copy the code

data

Alipay // document IDK includes Android and iOS versions

Silver couplet

Unionpay official website information

Demo

Demo gave an order number for testing. If payment fails, it may have been paid by others, or the server order has expired

####1. Alipay #####1.1 Please read alipay documentation and Demo #####1.2 to import the corresponding library

Localhost: Alipay MAC $ls apAuthv2Info.h order.h libssl.a apAuthv2Info.m order.m openssl AlipaySDK.bundle Util AlipaySDK.framework libcrypto.aCopy the code

Importing system Libraries

SystemConfiguration.framework
Copy the code

Set up search Paths

Build Setting -> Search search path and you get the idea

And when you’re done, compile it, see if there’s any errors, and if there are, let’s go to the next step. #####1.3 Before connecting to Alipay, you still need to get a bunch of things from the server

3p parameter list is written in alipay interface document, --! So just to summarize what I'm using, or what I'm talking about in the Demo, but I'm beyond the scope of the partner ID alipayPartner = @"2088 a string of numbers."; Interface name alipaySeller = @"[email protected]"; Signature aliPayPrivateKey = @"Very, very long private key."; / / public key alipayRSA_PUBLIC = @"Average length"; The client does not need the server to give me --~! Server asynchronous notification page path alipayNotifServerURL = @"A web site"; // Alipay will notify the server of the payment resultCopy the code

Some other parameters (related to the purchase of products, design to the business, client/server who can provide) directly attached to the order code, see my specific Demo examples.

Order \*order = [[Order alloc] init]; order.partner = alipayPartner ; order.seller = alipaySeller; order.tradeNO = tn; Order. ProductName = [NSString stringWithFormat:@"Car Service Top-up -%@"The @"Pay"]; Order. productDescription = [NSString stringWithFormat:@"%@: Alipay mobile payment recharge"The @"xxxx"]; Order.amount = _txtcny. text; // Order. NotifyURL = alipayNotifServerURL; // Callback URL order.service = @"mobile.securitypay.pay";
                    order.paymentType = @"1";
                    order.inputCharset = @"utf-8";
                    order.itBPay = @"30m";
                    order.showUrl = @"m.alipay.com"; Alixpaydemo-info.plist URL types NSString *appScheme = URLScheme;Copy the code

Call Alipay

[[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
                            NSLog(@"reslut = %@",resultDic);
                            if ([resultDic[@"resultStatus"[intValue]==9000) {// Enter the recharge list page NSLog(@"Payment successful");
                            }
                            else{
                                NSString *resultMes = resultDic[@"memo"]; resultMes = (resultMes.length<=0? @"Payment failure":resultMes);
                                NSLog(@"% @",resultMes); }}];Copy the code

You may find that the callback will not work -> Set the callback shema

// Shema name NSString *appScheme = URLScheme; // Set the shema method here is no longer unnecessary, here needs to handle the shema callback from Alipay, APPDelegate - - (BOOL)application:(UIApplication *)application openURL:(NSURL *)urlsourceApplication:(NSString *)sourceApplication annotation:(id)annotation {// jump alipay wallet for payment, Handle payment results [[AlipaySDK defaultService] processOrderWithPaymentResult: url standbyCallback: ^ (NSDictionary * resultDic) { NSLog(@"result = %@",resultDic);
    }];
    
    return YES;
}

Copy the code

#### ii. Unionpay #####2.1 Please go to unionPay documentation and Demo #####2.2 to import the corresponding library

SDK description SDK is divided into the following two versions: â‘  Support pure card-free transaction static library, hereinafter referred to as UPPayPlugin, including files: A â‘¡ Support pure cardless transactions and VIPOS audio port payment static library, hereinafter referred to as UPPayPluginPro, including files: uppayplugin.h uppayplugin.h libuppayplugin.h  UPPayPluginPro.h UPPayPluginDelegate.h libUPPayPluginPro.aCopy the code

Probably these two libraries are just like the above, we just need to know about the business/latter background

② Need to change.m to.mm. 😄)Copy the code
Add SDK package a) According to the SDK version selected by the merchant, add three files of the corresponding version in SDK/Inc directory and SDK /libs directory to the UPPayDemo project; B) If you choose UPPayPlugin, add quartzCore. framework and security. framework to the project; C) If you choose the UPPayPluginPro version, Add QuartzCore.framework, AudioToolbox.framework, CoreAudio. Framework, MediaPlayer. Avfoundation. framework and security. framework into the project; 😄 d) add the -objc macro to Other Linker Flags in Build Settings of the project;Copy the code

Import to the project, let the server prepare the transaction serial number information (what they don’t understand, let them go to the document bank union), take a break, drink a cup of what?

#####2.3 Docking our server is also quite powerful, a cup of tea time, will be ready to trade serial number information, well, speed docking.

 + (BOOL)startPay:(NSString*)tn 
mode:(NSString*)mode 
viewController:(UIViewController*)viewController 
delegate:(id<UPPayPluginDelegate>)delegate;
Copy the code
-- -- -- -- -- -- -- -- -- -- -- -- -- parameter specification (mandatory) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- tn nsstrings * trading serial number information, unionpay background, through the merchant background returns to the client and the incoming payment controls; Mode NSString* Specifies the access mode. Two values are @"00": Indicates access to the production environment (required for the official version). @"01": represents access to the development test environment (required for the test version); ViewController UIViewController* Current UIViewController for merchant application to call UnionPay mobile payment; Delegate ID <UPPayPluginDelegate> UIViewController that implements the UPPayPluginDelegate method;Copy the code

Well, these are all in the documentation, please take a look at *[make sure to change the mode mode when online]*. Mode In the test environment, the test number tn=@”01″ given by UnionPay can be used

The test uses the card number and mobile phone number information (such information is only for the test, and no formal transaction will take place) Bank Card Number: 6216261000000000018 ID Number: 341126197709218366 Mobile Phone Number: 13552535506 Verification Code: 123456Copy the code

The viewcontroller needs to do that

* Import header file \#import "UPPayPluginPro.h"* Call interface [UPPayPluginPro startPay:tn mode:self.tnMode viewController:self delegate:self]; Implement the corresponding proxy method \#pragma mark UPPayPluginResult
		- (void)UPPayPluginResult:(NSString \*)result
		{
		    NSString\* msg = [NSString stringWithFormat:@"% @", result];
		    NSLog(@"msg%@",msg);
		    if ([result isEqualToString:@"msgcancel"]) {
		        NSLog(@"Cancel union Pay...");
		    }
		    else if([result containsString:@"success"]){
		        NSLog(@"Payment successful"); }}Copy the code

WeChat pay

Wechat Pay process before work

Wechat Payment documents wechat SDK

Generally speaking, wechat payment needs to be audited, and I did not get a number to test it personally. Generally speaking, there will be no problems if I follow the document demo.

#### note may encounter unionpay c++ compilation problems, switch the corresponding viewcontroller to.mm, compile and see. If you have CreateRSADataSigner arm64, please change the DataSigner from Alipay to.mm. For the rest, please refer to my demo

@ lp_ Ma Jiancheng