Alipay Payment Development IOS Graphics tutorial case _ios

Source: Internet
Author: User

Preface: Since the last "micro-letter payment to develop the iOS graphics tutorial case," has not been much time to update the summary of the detailed payment of such a lengthy, I am sorry. Today, a detailed flow of Alipay payment is introduced.

1, start downloading and viewing Alipay payment demo.

We go directly to Alipay's payment platform reference to make an integrated Alipay payment:

Https://doc.open.alipay.com/doc2/detail.htm? Spm=a219a.7629140.0.0.jiukaq&treeid=59&articleid=103675&doctype=1

The integration process is basically to follow the above four processes to complete the integrated iOS Alipay SDK.

Well, we actually step on the side of the process:

Click to download the SDK and demo

    

Then you'll go to the next page, the URL here by the way: https://doc.open.alipay.com/doc2/detail.htm?treeId=54&articleId=104509&docType=1

  

Extract after download:

And then after running the demo:

We'll find that whatever we click on that cell will pop up this message box. We need to find out where this information pops up in the source, and here's a quick way to find the target code.

You see the pop-up box prompts: "Missing partner or seller or private key", and that's it:

From the 148, 149, 150 lines of code above, we can see that we need the values of three parameters: partner, seller, Privatekey.

So these three parameters require a merchant app application:

2, our own to achieve Alipay payment function:

2-1, add SDK:

  

2-2, add the SDK-dependent class library:

2-3, we create an Order object: Alipayorder

  

2-4, then we will pay treasure demo in the order object parameters are copied into:

2-5, then we will deal with the payment code:

2-6, the next part of my copy of the code appropriate extraction and modification, and finally put in a Alipay method:

-(void) AliPay {//Alipay payment/* Before calling Alipay payment, we need to send the relevant order parameters to our backend server, signed by the backend server, and return all the relevant parameters to the client, the client directly use the parameters to pay Alipay.
 * * * * Merchant's only parnter and seller.
 * After signing, Alipay will assign a unique parnter and seller for each merchant. * */*============================================================================*//*======================= need to fill in the merchant AP P Application of ===================================*//*====================================================================
 ========*/nsstring *partner = @ "";
 NSString *seller = @ "";
 NSString *privatekey = @ ""; /*============================================================================*/
 /*============================= ===============================================*/
 /*============================================================
 ================*///partner and seller get failed, prompt if ([partner length] = = 0 | |
 [Seller Length] = = 0 | | [Privatekey length] = = 0) {Uialertview *alert = [[Uialertview alloc] initwithtitle:@ ' Prompt ' message:@ ' is missing partner or seller or Private. "Delegate:self Cancelbuttontitle: @ "determine" otherbuttontitles:nil];
 [Alert show];
 Return
 Order.partner = partner;
 Order.seller = seller; Order.tradeno = @ "1234567890"; Order ID (made by merchant) Order.productname = @ "Test item title"; Product title Order.productdescription = @ "Test Product description"; Product Description Order.amount = @ "0.01"; Commodity price Order.notifyurl = @ "http://www.xxx.com";
 Callback URL Order.service = @ "Mobile.securitypay.pay";
 Order.paymenttype = @ "1";
 Order.inputcharset = @ "Utf-8";
 Order.itbpay = @ "30m";
 
 Order.showurl = @ "m.alipay.com";
 
 Apply registration scheme, define URL in alixpaydemo-info.plist types nsstring *appscheme = @ "Alisdkdemo";
 Stitching the product information into a string nsstring *orderspec = [order description];
 
 NSLog (@ "Orderspec =%@", orderspec); Get the private key and sign the merchant information, the external merchant can hold the private key and signature according to the situation, only need to follow the RSA signature specification, and base64 the signature string to encode and UrlEncode//id<datasigner> signer =
 
 Creatersadatasigner (Privatekey);
 
 The signature value is processed by the server and returned to the client nsstring *signedstring = @ "Xxxxxxx_sign"; Format the signature success string as an order wordString, please strictly follow the format nsstring *orderstring = nil; if (signedstring!= nil) {orderstring = [nsstring stringwithformat:@ "%@&sign=\"%@\ "&sign_type=\"%@\ "", orderSp
 
 EC, Signedstring, @ "RSA"]; initiate payment [[Alipaysdk Defaultservice] payorder:orderstring fromscheme:appscheme callback:^ (nsdictionary *resultDic) {NSL
 OG (@ "pay the result Reslut =%@", resultdic);
 }];
 }

}

2-7, in addition we need to register Appscheme in the application, this scheme can be obtained from the above code:

  

2-8, add Appscheme

2-9. After the payment code is processed, we handle the callback result, we need to add the Alipay header file #import <AlipaySDK/AlipaySDK.h> and add the proxy method to process the return result in Appdelegate:

2-10, don't forget to add a button to listen and set the merchant ID parameters

Add: If we use Alipay to pay, if we have a mobile phone installed Alipay app, we will call Alipay to pay.

If we do not have a Alipay app installed on our phones, we will call the H5 interface for payment.

3. Get Merchant Payment ID

The above is the entire content of this article, I hope to help you learn.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.