iOS支付寶 app支付流程

https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.8bz1nF&treeId=193&articleId=105295&docType=1
1.在Build Phases選項(xiàng)卡的Link Binary With Libraries中,增加以下依賴:

1.png

2.拷貝文件到項(xiàng)目文件夾下,如
2.png

3.頭文件

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AlipaySDK/AlipaySDK.h>
#import "Order.h"
#import "APAuthV2Info.h"
#import "DataSigner.h"

4.組裝請求信息。

//將商品信息賦予AlixPayOrder的成員變量
Order* order = [Order new];
 
// NOTE: app_id設(shè)置
order.app_id = appID;
 
// NOTE: 支付接口名稱
order.method = @"alipay.trade.app.pay";
 
// NOTE: 參數(shù)編碼格式
order.charset = @"utf-8";
 
// NOTE: 當(dāng)前時間點(diǎn)
NSDateFormatter* formatter = [NSDateFormatter new];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
order.timestamp = [formatter stringFromDate:[NSDate date]];
 
// NOTE: 支付版本
order.version = @"1.0";
 
// NOTE: sign_type設(shè)置
order.sign_type = @"RSA";
 
// NOTE: 商品數(shù)據(jù)
order.biz_content = [BizContent new];
order.biz_content.body = @"我是測試數(shù)據(jù)";
order.biz_content.subject = @"1";
order.biz_content.out_trade_no = [self generateTradeNO]; //訂單ID(由商家自行制定)
order.biz_content.timeout_express = @"30m"; //超時時間設(shè)置
order.biz_content.total_amount = [NSString stringWithFormat:@"%.2f", 0.01]; //商品價格
 
//將商品信息拼接成字符串
NSString *orderInfo = [order orderInfoEncoded:NO];
NSString *orderInfoEncoded = [order orderInfoEncoded:YES];
NSLog(@"orderSpec = %@",orderInfo);
 
// NOTE: 獲取私鑰并將商戶信息簽名,外部商戶的加簽過程請務(wù)必放在服務(wù)端,防止公私鑰數(shù)據(jù)泄露;
//       需要遵循RSA簽名規(guī)范,并將簽名字符串base64編碼和UrlEncode
id<DataSigner> signer = CreateRSADataSigner(privateKey);
NSString *signedString = [signer signString:orderInfo];
 
// NOTE: 如果加簽成功,則繼續(xù)執(zhí)行支付
if (signedString != nil) {
    //應(yīng)用注冊scheme,在AliSDKDemo-Info.plist定義URL types
    NSString *appScheme = @"alisdkdemo";
     
    // NOTE: 將簽名成功字符串格式化為訂單字符串,請嚴(yán)格按照該格式
    NSString *orderString = [NSString stringWithFormat:@"%@&sign=%@",
                             orderInfoEncoded, signedString];
     
    // NOTE: 調(diào)用支付結(jié)果開始支付
    [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
        NSLog(@"reslut = %@",resultDic);
    }];
}

5.運(yùn)行出現(xiàn)錯誤,出現(xiàn)rsa.h file not found ,在header search path路徑解決后, 然后出現(xiàn)openssl/asn1.h file not found, 解決

$(SRCROOT)/項(xiàng)目名
$(PROJECT_DIR)/項(xiàng)目名/Utils/Alipay    //openssl文件路徑
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1看了支付寶文檔,寫的很詳細(xì)本以為會比微信更容易些,沒想到這一入坑,半天沒爬起來。支付寶SDK下載地址:https...
    青鳥evergreen閱讀 294評論 0 4
  • 支付寶開放平臺地址https://doc.open.alipay.com/doc2/detail.htm?spm=...
    X勒個F閱讀 313評論 2 0
  • 近日,有不少的媒體報道了有關(guān)京城81號完成翻修,并對外招租其價格千萬令人咋舌。而有關(guān)的消息已將得到了有關(guān)媒體...
    順意明目護(hù)眼液閱讀 783評論 0 0
  • 記得剛剛和她戀愛時,她說要永遠(yuǎn)和我在一起,可后來我工作忙加上我偷偷的買房子,那時她剛剛實(shí)習(xí),我也剛剛畢業(yè)沒多久,我...
    你的愛Imnot閱讀 288評論 0 0
  • 你相信愛情嗎?如果,有一天遇到了心愛的他(她),你會怎么做?你憧憬你們的未來嗎?你覺得你們之間的緣分是天賜良緣還是...
    夏目心葉閱讀 374評論 5 10

友情鏈接更多精彩內(nèi)容