日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

最新《ApplePay支付》接入

發布時間:2023/12/14 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 最新《ApplePay支付》接入 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? ? ?前言: ? ? ? ? ? ? ?2016是個真正開始走向解放錢包的時代了,從各種卡片開始流行起,不管你用的是磁條卡還是芯片卡,肯定是慢慢的塞滿了你的錢包,但隨著2月18日Apple Pay在中國上線,越來越多的人開始使用。Apple Pay 是行業稱呼,也有叫蘋果支付,其實它叫連連付。下面,我們就進入接入前的準備環節。 ? ? ?準備: ? ? ? ? ? ?? Apple Pay的接入相對支付寶簡單,對于微信更是簡單。但是,Apple Pay的接入流程可以說是和微信支付是半親。為什么說是半親?因為Apple Pay的重點接入和微信的第二詞簽名是80%一樣的。對于準備也是所有支付里面最難的一種。困難的種類: ? ? ? ?1、Apple Pay 的正式支付網站還不可以登錄。同時他們也給出了,跨域登錄和動態登錄。
? ? ? ?2、這里我們要登錄(正式登錄)為了簽名秘鑰獲取及IP域名配置。后續再說(不能正式登錄就不能獲得秘鑰)。 ? ? ? ?3、現在有一個測試登錄入口。 ? ? ? ? ? ? ?4、登錄后,你的工作就來了。請看下圖(3相里面的內容沒有點開,怕嚇著人了)。
? ? ? 5、下面進行的也是重要的也是很麻煩的。我就用語言描述了,就不上圖了(圖,后續完善)。首先,你要登錄蘋果開發者賬號。進入證書模塊。如果是第一次的話。你的MerchantID 這個模塊是沒有東西的。我們要進行添加。添加的時候會讓你寫兩個東西。分別是:MerchantID ?和 ? BundleID。然后,你進行在連連付的賬戶里創建應用,如下圖:
其中BundelID 和你開發者賬號里面生成MerchantID 的時候要一樣。第二步是提交,你開發者中心里面你填寫的MerchantID 。第三步,你下載一個CRS 的文件。保存到重要的位置。然后。我們現在要切換到,蘋果開發者中心證書生生模塊。在這個模塊里面,進行證書的創建。在第三步的時候,會讓你提交一個CRS文件。這個文件就是,你剛才下在的文件。(后續完善)。 ? ? ? 6、我們進行工程的配置。 ? ? ? ? ? ? 1.我們要導入必要的支持庫(保證,支付的安全,定位)。要導入的庫如下: ? ? ? ? ? ? ? ?
? ? ? ? ? ? 2.我們要進行開發SDK 的導入。(這里我將其融合) ? ? ? ? ? ? ? ?
? ? ? ? ? ? 3.我們要挑選開發者。 ? ? ? ? ? ? 4.進入項目Build Seting 里面的OtherLinkerFlags 設置為 _all_load. ? ? ? ? ? ? 5.進入項目 CApAbilities 模塊,打開Apple Pay模塊。并點擊更新按鈕。成功后會有三個對號。同時項目里面會出現一個證書。如下圖: ? ? ? ? ? ? ?? 第一:我們進行效果展示。 ? ? ? ? ? ? ? 第二:功能介紹 ? ? ? ? 1、動態的邊框。 2、TableView的獨立創建,界面。 3、Pay支付和Auth的預授權。 第二:代碼的編寫。
? ? ? ?1.進行訂單的簽名,和部分算法代碼。 ? ? ? ?簽名代碼: ? ? ? ? ?

-(NSString*)GetString:(NSDictionary*)anyobjiect_dict{

? ? // 創建一個局部數組,防止OrderInfoAllKeysArray 為空

? ? NSArray * AllKeys =@[@"busi_partner",@"dt_order",@"info_order",

? ? ? ? ? ? ? ? ? ? ? ? ? @"money_order",@"name_goods",@"no_order",

? ? ? ? ? ? ? ? ? ? ? ? ? @"notify_url",@"oid_partner",@"risk_item",@"sign_type",

? ? ? ? ? ? ? ? ? ? ? ? ? @"valid_order"];

? ? if (self.OrderInfoAllKeysArray !=nil) {

? ? ? ? // 如果OrderInfoAllKeysArray 存在將 Allkeys 替代

? ? ? ? AllKeys = self.OrderInfoAllKeysArray;

? ? }

? ? if (ErrorMessageDictInfo) {

? ? ? ? [ErrorMessageDictInfosetObject:@"OrderInfoAllKeysArray沒有傳入"forKey:@"AllKeys"];

? ? }

? ? // 將一個不可變的數組,可變化。進行數組對象字母排序

? ? NSMutableArray * LetterKeysArray = [NSMutableArrayarrayWithArray:AllKeys];

? ? [LetterKeysArray sortedArrayUsingComparator:^NSComparisonResult(id?_Nonnull obj1, id?_Nonnull obj2) {

? ? ? ? return [obj1 compare:obj2];

? ? }];

? ? // 聲明一個可變的字符串,將字典轉化為字符串

? ? NSMutableString * PiecedMutableString = [[NSMutableStringalloc]initWithCapacity:0];

? ? for (NSString * tempstrin LetterKeysArray) {

? ? ? ? if ([anyobjiect_dict[tempstr] length] != 0) {

? ? ? ? ? ? [PiecedMutableString appendFormat:@"&%@=%@",tempstr,anyobjiect_dict[tempstr]];

? ? ? ? }

? ? }

? ? // 進行可變的字符串進行處理

? ? if (PiecedMutableString.length !=0) {

? ? ? ? // 刪除字符串的第一個字符:@“&”

?? ? ? ? [PiecedMutableString deleteCharactersInRange:NSMakeRange(0,1)];

? ? }else{

? ? ? ? if(ErrorMessageDictInfo){

? ? ? ? ? ? [ErrorMessageDictInfosetObject:@"65可變字符串不存在"forKey:@"PiecedMutableString"];

? ? ? ? }

? ? }

? ? if ([anyobjiect_dict[@"sign_type"]isEqualToString:@"MD5"]) {

? ? ? ? // 拼接上簽名的Key-Value

? ? ? ? [PiecedMutableString appendFormat:@"&key=%@",self.SingKey];

? ? }

? ? // 聲明要輸出的字符串對象

? ? NSString * Return_SignString = nil;

? ? if([anyobjiect_dict[@"sign_type"]isEqualToString:@"MD5"]){

? ? ? Return_SignString = [ApplePayAlgorithm GetMd5String:PiecedMutableString];

? ? }else{

? ? ? // 哈希加密

? ? ? Return_SignString = [ApplePayAlgorithm signHmacString:PiecedMutableString withKey:self.SingKey];

? ? }

#ifdef kLLPayUtilNeedRSASign

? ? id<LLPDataSigner> signer = LLPCreateRSADataSigner(self.signKey);

? ? signString = [signer signString:paramString];

#endif

? ? // 輸出加密后的字符串

? ? NSLog(@"簽名字符串:%@",Return_SignString);

? ? return Return_SignString;

}


2.加密算法代碼 MD5

+(NSString*)GetMd5String:(NSString*)anyobject_string{

? ? // 進行編碼轉換成字符

? ? const char *original_str = [anyobject_stringUTF8String];

? ? unsigned char result[32];

? ? CC_MD5(original_str, (CC_LONG)strlen(original_str), result);//調用md5

? ? NSMutableString * MD5_String = [NSMutableStringstring];

? ? for (int i =0; i < 16; i++){

? ? ? ? [ MD5_String appendFormat:@"%02x", result[i]];

? ? }

? ? return MD5_String;

}


哈希

+ (NSString *)signHmacString:(NSString*)text withKey:(NSString*)key{

? ? constchar *cKey? = [keycStringUsingEncoding:NSUTF8StringEncoding];

? ? constchar *cData = [textcStringUsingEncoding:NSUTF8StringEncoding];

? ? uint8_t cHMAC[CC_SHA256_DIGEST_LENGTH];

? ? CCHmac(kCCHmacAlgSHA256, cKey,strlen(cKey), cData, strlen(cData), cHMAC);

? ? NSString *hash= nil;

? ? NSMutableString* output = [NSMutableStringstringWithCapacity:CC_SHA256_DIGEST_LENGTH *2];

? ? for(int i =0; i < CC_SHA256_DIGEST_LENGTH; i++){

? ? ? ? [output appendFormat:@"%02x", cHMAC[i]];

? ? }

? ? hash = output;

? ? return hash;

}

? ? ?3. 配置文件。其中商戶秘鑰是不正確的。

//? ApplePayCommont.h

//? Apple_Pay

//

//? Created by 周雙建 on 16/2/25.

//? Copyright ? 2016周雙建. All rights reserved.

//

#ifndef ApplePayCommont_h

#define ApplePayCommont_h

商戶號

static NSString *kLLOidPartner =@"201602190000022156";

// 商戶秘鑰

static NSString *kLLPartnerKey =@"201601250000011007";//這個不匹配,切記

NSString *kAPMerchantID =@"merchant.com.zsj.ApplePay";

#endif /* ApplePayCommont_h */

? ? ? 4.訂單的創建。

#pragma mark 創建訂單

-(void)CreateOrderInfo{

? ? // 獲取當前時間

? ? NSDateFormatter * DateFormatter = [[NSDateFormatteralloc]init];

? ? [DateFormatter setDateFormat:@"yyyyMMddHHmmss"];

? ? // 將時間轉化成字符串

? ? NSString * PresentTimeString = [DateFormatterstringFromDate:[NSDatedate]];

? ? // 訂單前的標志

? ? NSString * OrderPresentSign = @"LL";

? ? // 加密的形式 MD5 ? RSA ? 哈希

? ? NSString * SignType = @"MD5";

? ? // 聲明一個可變的參數字典

? ? self.OrderInfoMutableDict = [NSMutableDictionarydictionaryWithCapacity:0];

? ? NSMutableDictionary * PrameMutableDict? = [NSMutableDictionarydictionary];

? ? [PrameMutableDict setDictionary:@{

? ? ? ? ? ? ? ? ? ? ? ? ? //簽名方式String RSA? 或者 MD5

?? ? ? ? ? ? ? ? ? ? ? ? ? @"sign_type":SignType,

?? ? ? ? ? ? ? ? ? ? ? ? ? //商戶業務類型是String(6)虛擬商品銷售:101001

?? ? ? ? ? ? ? ? ? ? ? ? ? @"busi_partner":@"101001",

?? ? ? ? ? ? ? ? ? ? ? ? ? //商戶訂單時間dt_orderString(14)格式:YYYYMMDDH24MISS? 14位數字,精確到秒

?? ? ? ? ? ? ? ? ? ? ? ? ? @"dt_order":PresentTimeString,

?? ? ? ? ? ? ? ? ? ? ? ? ? //交易金額money_order Number(8,2) 該筆訂單的資金總額,單位為RMB-元。大于0的數字,精確到小數點后兩位。如:49.65

?? ? ? ? ? ? ? ? ? ? ? ? ? @"money_order":@"0.10",

?? ? ? ? ? ? ? ? ? ? ? ? ? //服務器異步通知地址notify_url String(64) 連連錢包支付平臺在用戶支付成功后通知商戶服務端的地址。

?? ? ? ? ? ? ? ? ? ? ? ? ? @"notify_url":@"http://test.yintong.com.cn:80/apidemo/API_DEMO/notifyUrl.htm",

?? ? ? ? ? ? ? ? ? ? ? ? ? //商戶唯一訂單號no_order String(32) 商戶系統唯一訂單號

?? ? ? ? ? ? ? ? ? ? ? ? ? @"no_order":[NSStringstringWithFormat:@"%@%@",OrderPresentSign,PresentTimeString],

?? ? ? ? ? ? ? ? ? ? ? ? ? //商品名稱name_goods String(40)

?? ? ? ? ? ? ? ? ? ? ? ? ? @"name_goods":@"琴女的皮膚",

?? ? ? ? ? ? ? ? ? ? ? ? ? //訂單附加信息info_order String(255) 商戶訂單的備注信息,還可以詳細描述。

?? ? ? ? ? ? ? ? ? ? ? ? ? @"info_order":PresentTimeString,

?? ? ? ? ? ? ? ? ? ? ? ? ?//分鐘為單位,默認為10080分鐘(7天),從創建時間開始,過了此訂單有效時間此筆訂單就會被設置為失敗狀態不能再重新進行支付。

?? ? ? ? ? ? ? ? ? ? ? ? ? @"valid_order":@"10080",

?? ? ? ? ? ? ? ? ? ? ? ? ? //@"shareing_data":@"201412030000035903^101001^10^分賬說明1|201310102000003524^101001^11^分賬說明2|201307232000003510^109001^12^分賬說明3"

?? ? ? ? ? ? ? ? ? ? ? ? ? // 分賬信息數據 shareing_data? (1024)

?? ? ? ? ? ? ? ? ? ? ? ? ? //@"risk_item":@"{\"user_info_bind_phone\":\"13958069593\",\"user_info_dt_register\":\"20131030122130\"}",

?? ? ? ? ? ? ? ? ? ? ? ? ?//風險控制參數 此字段填寫風控參數,采用json串的模式傳入,字段名和字段內容彼此對應好

?? ? ? ? ? ? ? ? ? ? ? ? ?//商戶用戶唯一編號 該用戶在商戶系統中的唯一編號,要求是該編號在商戶系統中唯一標識該用戶

?? ? ? ? ? ? ? ? ? ? ? ? ? // user_id,一個user_id標示一個用戶

?? ? ? ? ? ? ? ? ? ? ? ? ? // user_id為必傳項,需要關聯商戶里的用戶編號,一個user_id下的所有支付銀行卡,身份證必須相同

?? ? ? ? ? ? ? ? ? ? ? ? ? // demo中需要開發測試自己填入user_id,可以先用自己的手機號作為標示,正式上線請使用商戶內的用戶編號

?? ? ? ? ? ? ? ? ? ? ? ? ? @"risk_item" : [ApplePayAlgorithmGetString:@{@"user_info_dt_register":@"20131030122130",@"cinema_name":@"大電影院",@"book_phone":@"18811520397"}],@"user_id":@"xu20160215",

?? ? ? ? ? ? ? ? ? ? ? ? ? @"oid_partner":kLLOidPartner

? ? ? ? ? ? ? ? ? ? ? ? ? ? }];

? ? self.OrderInfoMutableDict = PrameMutableDict;

? ? // matech ID ? 預支付AP ID

? ? self.OrderInfoMutableDict[@"ap_merchant_id"] =kAPMerchantID;

? ? if (kLLOidPartner.length >0) {

? ? ? ? // 商戶秘鑰

? ? ? ? self.OrderInfoMutableDict[@"oid_partner"] =kLLOidPartner;

? ? ? ? return;

? ? }

}


? 5.Pay支付代碼。

// 進行支付

- (void)payWithSignedOrder:(NSDictionary*)signedOrder

{

? ? [LLAPPaySDK sharedSdk].sdkDelegate =self;

? ? [[LLAPPaySDKsharedSdk] payWithTraderInfo:signedOrder

?? ? ? ? ? ? ? ? ? ? ? ? ? ? inViewController:self];

}

? 6.Auth 授權。

#pragma mark? 預授權

- (void)authWithSignedOrder:(NSDictionary*)signedOrder{

? ? [LLAPPaySDK sharedSdk].sdkDelegate =self;

? ? [[LLAPPaySDKsharedSdk] preauthWithTraderInfo:signedOrder

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? inViewController:self];

}


7.支付的回調。

#pragma mark? 支付結果的返回

/* kLLPayResultSuccess = 0,? ? // 支付成功

kLLPayResultFail = 1, ? ? ? // 支付失敗

kLLPayResultCancel = 2, ? ? // 支付取消,用戶行為

kLLPayResultInitError,? ? ? // 支付初始化錯誤,訂單信息有誤,簽名失敗等

kLLPayResultInitParamError, // 支付訂單參數有誤,無法進行初始化,未傳必要信息等

kLLPayResultUnknow, ? ? ? ? // 其他

*/

- (void)paymentEnd:(LLPayResult)resultCode withResultDic:(NSDictionary*)dic{

? ? [selfalertView:[ApplePayAlgorithmGetString:dic]];

? ? switch (resultCode) {

? ? ? ? casekLLPayResultSuccess:{

? ? ? ? ? // 支付成功

? ? ? ? ? ? NSString* result_pay = dic[@"result_pay"];

? ? ? ? ? ? if ([result_pay isEqualToString:@"SUCCESS"])

? ? ? ? ? ? {

? ? ? ? ? ? ? ? [self alertView:@"SUCCESS"];


? ? ? ? ? ? }

? ? ? ? ? ? else if ([result_payisEqualToString:@"PROCESSING"])

? ? ? ? ? ? {

? ? ? ? ? ? ? ? //@"支付單處理中";

? ? ? ? ? ? ? ? [self alertView:@"支付單處理中"];


? ? ? ? ? ? }

? ? ? ? ? ? else if ([result_payisEqualToString:@"FAILURE"])

? ? ? ? ? ? {

? ? ? ? ? ? ? ? // @"支付單失敗";

? ? ? ? ? ? ? ? [self alertView:@"支付單失敗"];


? ? ? ? ? ? }

? ? ? ? ? ? else if ([result_payisEqualToString:@"REFUND"])

? ? ? ? ? ? {

? ? ? ? ? ? ? ? // @"支付單已退款";

? ? ? ? ? ? ? ? [self alertView:@"支付單已退款"];


? ? ? ? ? ? }


? ? ? ? }

? ? ? ? ? ? break;

? ? ? ? casekLLPayResultFail:{

? ? ? ? ? // 支付失敗

?? ? ? ? ? [self alertView:@"支付失敗"];

?? ? ? ? ? ?


? ? ? ? }

? ? ? ? ? ? break;

? ? ? ? casekLLPayResultCancel:{

?? ? ? ? ? // 用戶取消支付

? ? ? ? ? ? [self alertView:@"用戶取消支付"];


? ? ? ? }

? ? ? ? ? ? break;

? ? ? ? casekLLPayResultInitError:{

? ? ? ? ? ? [selfalertView:@"支付初始化錯誤,訂單信息有誤,簽名失敗等"];


?? ? ? ? ? //支付初始化錯誤,訂單信息有誤,簽名失敗等

? ? ? ? }

? ? ? ? ? ? break;

? ? ? ? casekLLPayResultInitParamError:{

? ? ? ? ? ? [selfalertView:@"支付訂單參數有誤,無法進行初始化,未傳必要信息等"];

? ? ? ? }

?? ? ? ? ? ?

? ? ? ? ? ? break;

? ? ? ? casekLLPayResultUnknow:{

? ? ? ? ? ? //其他

? ? ? ? ? ? [self alertView:@"其他"];

? ? ? ? }

?? ? ? ? ? ?

? ? ? ? ? ? break;

? ? ? ? default:

? ? ? ? ? ? break;

? ? }

?? ?

}

8.切記,不要忘記添加代理。

LLPaySdkDelegate


9.下載地址。 https://github.com/zhoushuangjian/Apple_Pay.git
? ? ? ?

? ? ? ? ? ?? ? ? ? ? ? ? ? ?
? ? ? ?

總結

以上是生活随笔為你收集整理的最新《ApplePay支付》接入的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。