iOS-支付寶&微信支付

支付寶、微信支付??https://github.com/SMARTSMALL/MobilePayDemo?

URL Schemes 配置如下



info.plist 白名單配置及網(wǎng)絡(luò)配置


ps. 支付集成及注意事項(xiàng) 均在LZMobilePayManager.h中 有提到


/************支付寶支付****************/

/*

1.導(dǎo)入(AlipaySDK.bundle AlipaySDK.framework)到項(xiàng)目文件庫下

2.在Build Phases選項(xiàng)卡的Link Binary With Libraries中,增加以下依賴:libc++.tbd、libz.tbd、SystemConfiguration.framework、CoreTelephony.framework、QuartzCore.framework、CoreText.framework、CoreGraphics.framework、UIKit.framework、Foundation.framework、CFNetwork.framework、CoreMotion.framework、AlipaySDK.framework

3.導(dǎo)入#import

- (BOOL)application:(UIApplication *)application

openURL:(NSURL *)url

sourceApplication:(NSString *)sourceApplication

annotation:(id)annotation {

if ([url.host isEqualToString:@"safepay"]) {

//支付跳轉(zhuǎn)支付寶錢包進(jìn)行支付,處理支付結(jié)果

[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {

NSLog(@"result = %@",resultDic);

if (resultDic) {

[[NSNotificationCenter defaultCenter]postNotificationName:@"AlipayNotification" object:selfuserInfo:resultDic];

}

}];

//授權(quán)跳轉(zhuǎn)支付寶錢包進(jìn)行支付,處理支付結(jié)果

[[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) {

NSLog(@"defaultService result = %@",resultDic);

//解析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(@"授權(quán)結(jié)果authCode = %@", authCode?:@"");

}];

}

}

return YES;

}

// NOTE: 9.0以后使用新API接口

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options

{

//支付跳轉(zhuǎn)支付寶錢包進(jìn)行支付,處理支付結(jié)果

[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {

if (resultDic) {

[[NSNotificationCenter defaultCenter]postNotificationName:@"AlipayNotification" object:selfuserInfo:resultDic];

}

NSLog(@"result = %@",resultDic);

}];

//授權(quán)跳轉(zhuǎn)支付寶錢包進(jìn)行支付,處理支付結(jié)果

[[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) {

NSLog(@"defaultService==result = %@",resultDic);

//解析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(@"授權(quán)結(jié)果authCode = %@", authCode?:@"");

}];

}

return YES;

}

4.、點(diǎn)擊項(xiàng)目名稱,點(diǎn)擊“Info”選項(xiàng)卡,在“URL Types”選項(xiàng)中,點(diǎn)擊“+”,在“URL Schemes”中輸入“alisdkdemo”。“alisdkdemo”來自于文件“APViewController.m”的NSString *appScheme = @“alisdkdemo”;。

注意:這里的URL Schemes中輸入的alisdkdemo,為測試demo,實(shí)際商戶的app中要填寫?yīng)毩⒌膕cheme,建議跟商戶的app有一定的標(biāo)示度,要做到和其他的商戶app不重復(fù),否則可能會導(dǎo)致支付寶返回的結(jié)果無法正確跳回商戶app。

5.注意'openssl/asn1.h' file not found在Build Setting下Header search paths添加"$(SRCROOT)/工程名/文件夾"

6.注意如果出現(xiàn)【rsa_private read error : private key is NULL】

1.修改RSADataSigner中方法formatPrivateKey中

[result appendString:@"-----BEGIN PRIVATE KEY-----\n"];

[result appendString:@"\n-----END PRIVATE KEY-----"];

[result appendString:@"-----BEGIN RSA PRIVATE KEY-----\n"];

[result appendString:@"\n-----END RSA PRIVATE KEY-----"];

2.

檢查提供是私鑰是否正確*/

如何使用 LZMobilePayManager?

ps. 后面有時(shí)間集成銀聯(lián)支付功能

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

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

  • MY BLOG---> Demo Demo下載地址demo使用時(shí),請?jiān)赪TPayKeys.h里面將各個(gè)參數(shù)配置好!...
    多面獸閱讀 4,000評論 4 26
  • 最近實(shí)現(xiàn)了支付寶sdk導(dǎo)入的視線功能,那么現(xiàn)在就講一下實(shí)現(xiàn)的整個(gè)流程。(其實(shí)并沒有想象中那么難) 一:第一步 需要...
    辛小二閱讀 1,507評論 0 1
  • 文章主要講到以下五部分: 一、支付寶開放平臺創(chuàng)建應(yīng)用 二、簽約移動(dòng)支付功能 三、接入支付前的準(zhǔn)備工作附準(zhǔn)備工作中遇...
    sillen閱讀 18,040評論 1 10
  • 按理說呢,我不應(yīng)該踩這么個(gè)坑了,但是 我粗心大意忘了,雖然之前寫了很多種支付了,但是最近在開發(fā)中又被支付坑了一次,...
    一個(gè)蘿卜X個(gè)坑閱讀 1,230評論 0 1
  • 帕斯卡爾在《沉思錄》里寫道,“人類不快樂的唯一原因是不知道如何安靜地呆在他的房間里?!边@句話產(chǎn)生于17世紀(jì),將這...
    廚房小賊閱讀 502評論 1 5

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