你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發基礎 >> 10分鐘搞定支付寶和微信支付的各種填坑

10分鐘搞定支付寶和微信支付的各種填坑

編輯:IOS開發基礎

Crater_0012.jpg

本文授權轉載,作者:Migi000(簡書)

填坑

支付寶填坑是每個接入支付寶必經之路,下面是我接入支付寶遇到的問題匯總,希望大家在接入的路上少一點彎路。

問題1. Util/base64.h:63:21: Cannot find interface declaration for ‘NSObject’, superclass of ‘Base64’

解決辦法:

這是base64.h中沒有加入#import 系統庫文件導致,這個錯誤報錯方法直接想噴它一臉。報錯方式太惡心。

問題2.截圖告知你什麼問題

616981-d6540c725f3801a4.jpg

解決辦法:

這個問題可以同上的,心情好,截圖再次說明下,在 openssl_wrapper.h中#import 庫即可

問題3.Util/openssl_wrapper.m:11:9: ‘rsa.h’ file not found

解決辦法:

(1)萬年老坑,只要你接入支付寶百分百要遇到的問題,所以習以為常吧

(2)在Build setting中搜索search,找到Header Search Paths,添加$(PROJECT_DIR)/openssl和$(PROJECT_DIR) 如下圖:

(3)重要問題說三遍,這是網絡找到的到答案後繼續有同樣的坑,自己的解決方案,

Header Search Paths $(PROJECT_DIR)/ali中輸入這個

Framework Search Paths 和 Library Search Paths 繼續是$(inherited) 和 $(PROJECT_DIR)/ali

‘rsa.h’ file not found的解決方案

(4)由於後期多項目的接入,讓我知道一個算是萬能方法吧,就是始終保持Header Search Paths 和 Library Search Paths 都能找到你導入的openssl的正確路徑即可,已嘗試多遍,是能解決以上問題(求黑)

616981-b71f879b0c85fb6a.jpg

616981-e833ce4b6bd3cb57.jpg

問題4. 這類錯很多,大概有這些:這些可能是庫文件沒有導入,導致的

“_CNCopyCurrentNetworkInfo”, referenced from:

Undefined symbols for architecture x86_64:

"CNCopyCurrentNetworkInfo", referenced from:

-[APayReachability wifiInterface] in AlipaySDK

+[internal_DeviceInfo getSSIDInfo] in AlipaySDK

+[internal_DeviceInfo getNetworkInfo] in AlipaySDK

"_CNCopySupportedInterfaces", referenced from:

-[APayReachability wifiInterface] in AlipaySDK

+[internal_DeviceInfo getSSIDInfo] in AlipaySDK

+[internal_DeviceInfo getNetworkInfo] in AlipaySDK

"_CTRadioAccessTechnologyCDMA1x", referenced from:

-[AliSecXReachability networkStatusForFlags:] in AlipaySDK

"_CTRadioAccessTechnologyEdge", referenced from:

-[AliSecXReachability networkStatusForFlags:] in AlipaySDK

"_CTRadioAccessTechnologyGPRS", referenced from:

-[AliSecXReachability networkStatusForFlags:] in AlipaySDK

"_CTRadioAccessTechnologyLTE", referenced from:

-[AliSecXReachability networkStatusForFlags:] in AlipaySDK

"_OBJC_CLASS$_CMMotionManager", referenced from:

objc-class-ref in AlipaySDK

"OBJC_CLASS$_CTTelephonyNetworkInfo", referenced from:

objc-class-ref in AlipaySDK

"SCNetworkReachabilityCreateWithAddress", referenced from:

+[APayReachability reachabilityWithAddress:] in AlipaySDK

+[AliSecXReachability reachabilityWithAddress:] in AlipaySDK

"_SCNetworkReachabilityCreateWithName", referenced from:

+[APayReachability reachabilityWithHostname:] in AlipaySDK

+[AliSecXReachability reachabilityWithHostName:] in AlipaySDK

"_SCNetworkReachabilityGetFlags", referenced from:

-[APayReachability isReachable] in AlipaySDK

-[APayReachability isReachableViaWWAN] in AlipaySDK

-[APayReachability isReachableViaWiFi] in AlipaySDK

-[APayReachability connectionRequired] in AlipaySDK

-[APayReachability isConnectionOnDemand] in AlipaySDK

-[APayReachability isInterventionRequired] in AlipaySDK

-[APayReachability reachabilityFlags] in AlipaySDK

...

"_SCNetworkReachabilityScheduleWithRunLoop", referenced from:

-[AliSecXReachability startNotifier] in AlipaySDK

"_SCNetworkReachabilitySetCallback", referenced from:

-[APayReachability startNotifier] in AlipaySDK

-[APayReachability stopNotifier] in AlipaySDK

-[AliSecXReachability startNotifier] in AlipaySDK

"_SCNetworkReachabilitySetDispatchQueue", referenced from:

-[APayReachability startNotifier] in AlipaySDK

-[APayReachability stopNotifier] in AlipaySDK

"_SCNetworkReachabilityUnscheduleFromRunLoop", referenced from:

-[AliSecXReachability stopNotifier] in AlipaySDK

"std::1::basic_string, std::1::allocator >::init(char const, unsigned long)", referenced from:

CAliSecXURL::encodeURIComponent(CAliSecXBuffer&) in AlipaySDK

"std::1::basic_string, std::1::allocator >::reserve(unsigned long)", referenced from:

CAliSecXURL::encodeURIComponent(CAliSecXBuffer&) in AlipaySDK

"std::1::basic_string, std::__1::allocator >::~basic_string()", referenced from:

CAliSecXURL::encodeURIComponent(CAliSecXBuffer&) in AlipaySDK

"std::nothrow", referenced from:

CAliSecXBuffer::CAliSecXBuffer(unsigned long) in AlipaySDK

CAliSecXBuffer::_copy(unsigned char const, unsigned long) in AlipaySDK

CAliSecXBuffer::resize(unsigned long) in AlipaySDK

"std::terminate()", referenced from:

clang_call_terminate in AlipaySDK

"operator delete", referenced from:

CAliSecXBuffer::~CAliSecXBuffer() in AlipaySDK

CAliSecXBuffer::release() in AlipaySDK

CAliSecXBuffer::~CAliSecXBuffer() in AlipaySDK

CAliSecXBuffer::operator=(CAliSecXBuffer const&) in AlipaySDK

CAliSecXBuffer::resize(unsigned long) in AlipaySDK

alisec_crypto_Hex2Bin(CAliSecXBuffer const&) in AlipaySDK

alisec_crypto_Bin2Hex(CAliSecXBuffer const&) in AlipaySDK

...

"operator new", referenced from:

CAliSecXBuffer::CAliSecXBuffer(unsigned long) in AlipaySDK

CAliSecXBuffer::_copy(unsigned char const*, unsigned long) in AlipaySDK

CAliSecXBuffer::resize(unsigned long) in AlipaySDK

"cxa_begin_catch", referenced from:

clang_call_terminate in AlipaySDK

"gxx_personality_v0", referenced from:

+[ASSStorageAccesser saveStorageModel:] in AlipaySDK

+[ASSStorageAccesser loadStorageModelFromKeychain] in AlipaySDK

+[ASSStorageAccesser loadPreviousApdid] in AlipaySDK

+[ASSStorageAccesser getRandomizedID] in AlipaySDK

+[ASSStorageAccesser getNewRadomizedID] in AlipaySDK

+[ASSStorageAccesser loadLastLoginTime] in AlipaySDK

+[ASSStorageAccesser saveCurrentLoginTime:] in AlipaySDK

...

"_deflate", referenced from:

+[ASSCommonUtils gzipData:] in AlipaySDK

+[DTGZipUtil compressGZip:] in AlipaySDK

"_deflateEnd", referenced from:

+[ASSCommonUtils gzipData:] in AlipaySDK

+[DTGZipUtil compressGZip:] in AlipaySDK

"_deflateInit2", referenced from:

+[ASSCommonUtils gzipData:] in AlipaySDK

+[DTGZipUtil compressGZip:] in AlipaySDK

"_kCNNetworkInfoKeyBSSID", referenced from:

+[UIDevice(APEX) networkDic] in AlipaySDK

"_kCNNetworkInfoKeySSID", referenced from:

+[UIDevice(APEX) networkDic] in AlipaySDK

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

解決辦法:

這種問題通過在General->Link Framework and Libraiies中添加以下framework解決:

- libz.tbd

- libc++.tbd

- Security.framework

- CoreMotion.Framework

- CFNetwork.framework

- CoreTelephony.framework

- SystemConfiguration.framework

截圖如下,由於公司同時接入支付寶和微信支付,所以導入的庫就多了點咯:

616981-2e9fde123b91a6d5.jpg

問題5. Redefinition of 'RSA' as different kind of symbol 多為sdk集成時產生的坑,因為我們公司在集成支付寶之前,有用過RSA加密,導致重名問題

解決辦法:

(1)這個問題不是每個公司都可能遇到的,但遇到也心煩

(2)由於支付寶中的openssl中的rsa.h文件與RSA加密有重名沖突。改掉公司自己之前導入RSA的命名,如果你牛逼也可以去改rsa.h中的

問題6. 系統庫導入問題

+++++++++++++

symbol(s) not found for architecture arm64

1464167743266924.png

解決辦法:

就是導入系統庫了

616981-3a750ed6a81bdc43.jpg

問題7:終於到微信了,接入微信,你就開心了

因為問題太少了,只能感謝下這兩個帖子的樓主了

解決辦法:

使用微信支付SDK1.5版本的支付demo

微信支付如果遇到跳轉只有一個確定請看這裡

為了一些懶人懶的去看帖子,簡單說,就是微信支付注冊放在友盟分享之後就ok了!

代碼示例:

// 友盟分享
    [self configUmengShare];
//向微信注冊
    [WXApi registerApp:@"wxb4ba3c02aa476ea1" withDescription:@"demo 2.0"];

問題7:拉起支付寶報錯:交易訂單處理失敗,請稍後再試(ALI64)

解決辦法:

重新生成私鑰和公鑰,執行步驟如下個問題

問題8:支付寶要重新生成私鑰和公鑰,並上傳修改公鑰 -- 為你補充

解決辦法:

RSA密鑰生成命令步驟如下:

(1)先在終端鍵入 openssl

生成RSA私鑰

(2)openssl>genrsa -out rsa_private_key.pem 1024

生成RSA公鑰

(3)openssl>rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem

將RSA私鑰轉換成PKCS8格式

(4)openssl>pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt

注意:“>”符號後面的才是需要輸入的命令。

使用

WuTiandeiMac:FPHClientNew wutianshi$ openssl
OpenSSL>
OpenSSL>
OpenSSL>
OpenSSL>
OpenSSL> genrsa -out rsa_private_key.pem 1024
Generating RSA private key, 1024 bit long modulus
....................++++++
.........++++++
e is 65537 (0x10001)
OpenSSL> rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
writing RSA key
OpenSSL>
OpenSSL>
OpenSSL> pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt
-----BEGIN PRIVATE KEY-----
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBANOjnFDIjeQjyah1
1smthHNsiHyXE8EOWMyMZkLrIlbu6TCDVHk/hhJTpbDxVOz6f4cFdynP/wD9Tbnf
ZfJCKFDFJ9jPz3Euyb5/jLFbyAVblyLLPiv5bxRLaA9/w4Jtt+G7E/ti8HN6224x
4TT3owFuKqZTcAXeqXp7QMzZyEkZAgMBAAECgYBWYKRf5DrlLiYT92Rek89HPLjI
APEzDiP3+CWUkltFl+Tcw/0qL18NA87QVO8QeXyrIvPrwNSXFssuXZtCMPY6oqgh
21ixQ+w4Kk4Z8nkEbFNRjryrpOeGMQmZlkSqRiehnYPY6UT8ovKXj0D1HBoscfA7
z1Ioxpo3QEN3jsxkcQJBAPbgYhJYS7+/HB92eXaHckTpU0/ycosSj6ha02xs5+Sv
xJbkkDfrt/LVVgApBYlgJQG0WRcD/8+4cIyyAxGFp7MCQQDbdduyrvUTffsXeuad
XcHIAmX928y19YGvCU3+TJtGIfUMPoRsnidMnZh2s29G6bGy0fkrmMadogEkKqQX
AmYDAkBEmbdGx7hM0Oscpww7bonHMlrPNVy03nSC4LItR9nsRxdGor6ce2jDFpru
MnfyY4AFCDtVVOwpqWPFBNYrcUtXAkEAltAme2OKHawMmnUl9+zPV1B2oH6k7kJZ
rVy6kVA5wHdje9eWj0IcBaWjeacTiGreZ+Gt1sz1aKxFFoKLIxjN2wJADlpg/9iN
Bf+JylK9QEgOTw6PngSOiXeaVXdErOPbu4WkzvxhB0bm8HPEPiJpLg/3sNaaX3ou
TIEHO8o1EcEnrw==
-----END PRIVATE KEY-----
OpenSSL>

生成的文件:

616981-bf1bd390c88ef9da.png

把公鑰上傳到支付寶,然後把pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt 這條命令產生的私鑰用在下面設置中就好

然後設置

/*
*商戶的唯一的parnter和seller。
*簽約後,支付寶會為每個商戶分配一個唯一的 parnter 和 seller。
*/
/*============================================================================*/
/*=======================需要填寫商戶app申請的===================================*/
/*============================================================================*/
NSString *partner = PartnerID;//合作伙伴身份(PID):
NSString *seller = SellerID;//商戶支付寶賬戶
//獲取私鑰並將商戶信息簽名,外部商戶可以根據情況存放私鑰和簽名,只需要遵循RSA簽名規范,並將簽名字符串base64編碼和UrlEncode
NSString *privateKey = PartnerPrivKey;// 剛第三端命令生成的去頭去尾

如有問題,繼續分享咯,總結才能讓問題越來越少!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved