填坑
支付宝填坑是每个接入支付宝必经之路,下面是我接入支付宝遇到的问题汇总,希望大家在接入的路上少一点弯路
问题1. Util/base64.h:63:21: Cannot find interface declaration for ‘NSObject’, superclass of ‘Base64’
解决办法:
这是base64.h中没有加入#import <Foundation/Foundation.h> 系统库文件导致,这个错误报错方法直接想喷它一脸。报错方式太恶心。
问题2.截图告知你什么问题
解决办法:
这个问题可以同上的,心情好,截图再次说明下,在 openssl_wrapper.h中#import <Foundation/Foundation.h> 库即可
问题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的正确路径即可,已尝试多遍,是能解决以上问题(求黑)
问题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<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const, unsigned long)", referenced from:
CAliSecXURL::encodeURIComponent(CAliSecXBuffer&) in AlipaySDK
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::reserve(unsigned long)", referenced from:
CAliSecXURL::encodeURIComponent(CAliSecXBuffer&) in AlipaySDK
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~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[](unsigned long, std::nothrow_t const&)", 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
截图如下,由于公司同时接入支付宝和微信支付,所以导入的库就多了点咯:
问题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
解决办法
就是导入系统库了
问题7:终于到微信了,接入微信,你就开心了
因为问题太少了,只能感谢下这两个帖子的楼主了
解决办法:
使用微信支付SDK1.5版本的支付demo
微信支付如果遇到跳转只有一个确定请看这里
为了一些懒人懒的去看帖子,简单说,就是微信支付注册放在友盟分享之后就ok了!
代码示例:
// 友盟分享
[self configUmengShare];
//向微信注册
[WXApi registerApp:@"wxb4ba3c02aa476ea1" withDescription:@"demo 2.0"];
问题8:
拉起微信支付后,在微信支付注册在友盟之后仍然跳转到微信还是一个确定按钮,点击确定按钮回到自己的应用
解决办法:
这个是后端返回的参数有问题,一般是sign签名有问题,
************注意:
1.签名 后端签名是要用到下面6个参数进行签名,appId,partnerId,noncestr,timestamp,package prepaid,签名过程中,6个参数都是小写,签名后字符转为大写,sign字符全是大写
2.随机串 请求预交易订单返回的
3.时间戳 订单结束时间
举例:如下是请求后端返回的数据
["appid"]=>
string(18) "wx5e71abd366954a75"
["noncestr"]=>
string(16) "Ws5NaX2MqdGejNvW"
["package"]=>
string(10) "Sign=WXPay"
["partnerid"]=>
string(10) "1341184101"
["prepayid"]=>
string(36) "wx20160530173622a5292225780182728337"
["sign"]=>
string(32) "322B952AC0678F21DD1F7C5B1F444886"
["timestamp"]=>
int(1464601340)
}
把后端返回的sign和自己签名的sign做个比较,native已经认证过,没有错误
-(NSString *)createMD5SingForPayWithAppID:(NSString *)appid_key partnerid:(NSString *)partnerid_key prepayid:(NSString *)prepayid_key package:(NSString *)package_key noncestr:(NSString *)noncestr_key timestamp:(UInt32)timestamp_key{
NSMutableDictionary *signParams = [NSMutableDictionary dictionary];
//签名的6个键值对中的key都必须小写
[signParams setObject:appid_key forKey:@"appid"];//微信appid 例如wxfb132134e5342
[signParams setObject:noncestr_key forKey:@"noncestr"];//随机字符串
[signParams setObject:package_key forKey:@"package"];//扩展字段 参数为 Sign=WXPay
[signParams setObject:partnerid_key forKey:@"partnerid"];//商户账号
[signParams setObject:prepayid_key forKey:@"prepayid"];//此处为统一下单接口返回的预支付订单号
[signParams setObject:[NSString stringWithFormat:@"%u",timestamp_key] forKey:@"timestamp"];//时间戳
NSMutableString *contentString =[NSMutableString string];
NSArray *keys = [signParams allKeys];
//按字母顺序排序
NSArray *sortedArray = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [obj1 compare:obj2 options:NSNumericSearch];
}];
//拼接字符串
for (NSString *categoryId in sortedArray) {
if ( ![[signParams objectForKey:categoryId] isEqualToString:@""]
&& ![[signParams objectForKey:categoryId] isEqualToString:@"sign"]
&& ![[signParams objectForKey:categoryId] isEqualToString:@"key"]
)
{
[contentString appendFormat:@"%@=%@&", categoryId, [signParams objectForKey:categoryId]];
}
}
//添加商户密钥key字段 API 密钥 这里的key需要换成自己公司商户密钥
[contentString appendFormat:@"key=%@", @"9db35c68b8de2d15d1d493d16fb67875"];
NSString *result = [self md5StringWithString:contentString];//md5加密
return result;
}
/**
* MD5 加密
*
* @return 加密后字符串
*/
- (NSString *)md5StringWithString:(NSString *)str
{
if(str == nil || [str length] == 0) return nil;
unsigned char digest[CC_MD5_DIGEST_LENGTH], i;
CC_MD5([str UTF8String], (int)[str lengthOfBytesUsingEncoding:NSUTF8StringEncoding], digest);
NSMutableString *ms = [NSMutableString string];
for(i=0;i<CC_MD5_DIGEST_LENGTH;i++)
{
[ms appendFormat: @"%02x", (int)(digest[i])];
}
[ms uppercaseString];
//转为大写
NSString *big = [ms uppercaseString];
NSLog(@"sign %@",big);
return [big copy];
}
这里NSLog后的值为
2016-05-30 17:41:01.166 FPHClient[15313:6309040] sign 322B952AC0678F21DD1F7C5B1F444886
和后端返回的一样
4.partnerId
问题9:
拉起支付宝报错:
交易订单处理失败,请稍后再试(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>
生成的文件:
这里写图片描述
把公钥上传到支付宝,然后把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;// 刚第三端命令生成的去头去尾
如有问题,继续分享咯,总结才能让问题越来越少!
PS:来简书混,关注是必须的,点赞❤️ 是要给的!