支付宝集成纪录
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了支付宝集成纪录相关的知识,希望对你有一定的参考价值。
最近在研究支付宝的继承,所以做一下笔记
继承支付宝第一步
第一步:创建应用并获取APPID
创建应用和申请支付宝支付那些就不说了,因为这些一般是不是我们做的事,我从配置密钥那一步说起:
第二步:配置密钥(这步很关键,决定你的成败)
开发者登录开放平台后,找到并进入应用
1、先下载密钥生成器,有mac版hewindow版本的
生成方式一(推荐):使用支付宝提供的一键生成工具(内附使用说明)
mac版本的工具下载后是这个东西, 下面介绍mac版本的操作步骤
生成
rsa_private_key_pkcs8
rsa_private_key
rsa_public_key
三个文件
支付宝平台的解析:
经过以上步骤,开发者可以在当前文件夹中(OpenSSL运行文件夹),看到app_private_key.pem(开发者RSA私钥)、app_private_key_pkcs8.pem(pkcs8格式开发者RSA私钥)和app_public_key.pem(开发者RSA公钥)3个文件。开发者将私钥保留,将公钥提交给支付宝配置到开发平台,用于验证签名
注意:对于使用Java的开发者,将pkcs8在console中输出的私钥去除头尾、换行和空格,作为开发者私钥,对于.NET和php的开发者来说,无需进行pkcs8命令行操作。
我解析一下上面的文字:
其实 app_public_key.pem 是要上传给支付宝平台的,app_private_key.pem的内容(java是使用app_private_key_pkcs8.pem)是ios程序里面下单的时候填写的 privateKey 参数,要去除头尾(-----BEGIN PRIVATE KEY----- xxx -----END PRIVATE KEY----- )
例如
-----BEGIN PRIVATE KEY-----
MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAMvITQCO+82VXnee
3UiODyFaqrMm9XHenUKAvEmnOYTHRTecPhhRFTyownCKdx+F9YgquEVeKO3f8xTC
sHnyeuB1P6CV2HxHeMAam86t14hhk36djj59JHCjgb0QcxllaO9p/wTOXTdy2Miy
EcB/+Bf7UY7nyIPhi/bUzztAiHd9AgMBAAECgYAAvwsJJXzmk9V0urA0w9BqXtqh
LVNYx2fsBmyqGGKtic1HFttjW2iogDW2E8u74dG0XfOu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BDygXkIlTJOIorgudFlrKP/HwJDoY4uQNl8gQJb/1LdrKwIe7FAkBl0TNtfodGrDXBHwBgtN/t3pyi+sz7OpJdUklKE7zMSBuLd1E3O4JMzvWP9wEE7JDb+brjgK4/cxxUHUTkk592 -----END RSA PRIVATE KEY----- |
PKCS8处理后的私钥文件示例(Java使用)
1 2 3 | -----BEGIN PRIVATE KEY----- MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAN0yqPkLXlnhM+2H/57aHsYHaHXazr9pFQun907TMvmbR04wHChVsKVgGUF1hC0FN9hfeYT5v2SXg1WJSg2tSgk7F29SpsF0I36oSLCIszxdu7ClO7c22mxEVuCjmYpJdqb6XweAZzv4Is661jXP4PdrCTHRdVTU5zR9xUByiLSVAgMBAAECgYEAhznORRonHylm9oKaygEsqQGkYdBXbnsOS6busLi6xA+iovEUdbAVIrTCG9t854z2HAgaISoRUKyztJoOtJfI1wJaQU+XL+U3JIh4jmNx/k5UzJijfvfpT7Cv3ueMtqyAGBJrkLvXjiS7O5ylaCGuB0Qz711bWGkRrVoosPM3N6ECQQD8hVQUgnHEVHZYtvFqfcoq2g/onPbSqyjdrRu35a7PvgDAZx69Mr/XggGNTgT3jJn7+2XmiGkHM1fd1Ob/3uAdAkEA4D7aE3ZgXG/PQqlm3VbE/+4MvNl8xhjqOkByBOY2ZFfWKhlRziLEPSSAh16xEJ79WgY9iti+guLRAMravGrs2QJBAOmKWYeaWKNNxiIoF7/4VDgrcpkcSf3uRB44UjFSn8kLnWBUPo6WV+x1FQBdjqRviZ4NFGIP+KqrJnFHzNgJhVUCQFzCAukMDV4PLfeQJSmna8PFz2UKva8fvTutTryyEYu+PauaX5laDjyQbc4RIEMU0Q29CRX3BA8WDYg7YPGRdTkCQQCG+pjU2FB17ZLuKRlKEdtXNV6zQFTmFc1TKhlsDTtCkWs/xwkoCfZKstuV3Uc5J4BNJDkQOGm38pDRPcUDUh2/ -----END PRIVATE KEY----- |
公钥文件示例
1 2 3 | -----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQWiDVZ7XYxa4CQsZoB3n7bfxLDkeGKjyQPt2FUtm4TWX9OYrd523iw6UUqnQ+Evfw88JgRnhyXadp+vnPKP7unormYQAfsM/CxzrfMoVdtwSiGtIJB4pfyRXjA+KL8nIa2hdQy5nLfgPVGZN4WidfUY/QpkddCVXnZ4bAUaQjXQIDAQAB -----END PUBLIC KEY----- |
2、点击“RSA(SHA1)密钥”处的“设置开发者公钥”(如已设置则显示“查看开发者公钥”,可修改),将公钥文件去除头尾、换行和空格,仅需填入字符串。
如下图:
到这里,密钥配置完成了
3、iOSdemo里面的集成
4、测试下单
主要是参数要选对
NSString *pid = @"合作伙伴身份(PID)";
NSString *appID = @"APPID(支付宝平台上面有)";
NSString *privateKey = @"MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAMvITQCO+82VXnee3UiODyFaqrMm9XHenUKAvEmnOYTHRTecPhhRFTyownCKdx+F9YgquEVeKO3f8xTCsHnyeuB1P6CV2HxHeMAam86t14hhk36djj59JHCjgb0QcxllaO9p/wTOXTdy2MiyEcB/+Bf7UY7nyIPhi/bUzztAiHd9AgMBAAECgYAAvwsJJXzmk9V0urA0w9BqXtqhLVNYx2fsBmyqGGKtic1HFttjW2iogDW2E8u74dG0XfOuzVl5BYjuWogq6ihpCFienFt7ATlEOEoHzfn2fn2/aNbuMey+72k8NAjP5PswDpPV6RaN+I78oytJIftypNTorvz3V1hWJJph8Xy6AQJBAOYPlNdwhIMc/YeQ0gugdgj3Ub8uGC5CxfFvlBV2AGNF3OZ4rJV7xLFGtzgME7XWvm+tpkeg2zWHOtZ3EsWz14UCQQDiwjmik1Cdq0lyxp7CdpHcnmob4S3t4L/cjk4GtKPlP9TlxdL4YnOzv7nX+I2SC1k/UTnNVBuKOp0f6sZ8P9WZAkBeZs5giN8XHfI6ioZmFvXYQAPfOv7ZHLU0mOBe3gjSs3wtZh8LR7oyNB5CdVIxL2j9UngEtFC+6jqOflXJoj4xAkBu5naxoEKpGgCN9b3ndX3Y3FEg2XxQ/r5W6/IVLXuKvzEsPxfzCpNzsaz+hz0V1B8N7HfMh/oAHLKDzZrNYZrhAkBoPWGhr8aSnGC+cJYmkmMLbVXsSft988tS6GM/809xngDx62bY2BOQQtdkibpBm1utdq3fo8fxeQXxQSSKTDaW";
privateKey 就是rsa_private_key_pkcs8.pem 中间的内容(去除头尾)
例如:
-----BEGIN PRIVATE KEY-----
MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAN0yqPkLXlnhM+2H/57aHsYHaHXazr9pFQun907TMvmbR04wHChVsKVgGUF1hC0FN9hfeYT5v2SXg1WJSg2tSgk7F29SpsF0I36oSLCIszxdu7ClO7c22mxEVuCjmYpJdqb6XweAZzv4Is661jXP4PdrCTHRdVTU5zR9xUByiLSVAgMBAAECgYEAhznORRonHylm9oKaygEsqQGkYdBXbnsOS6busLi6xA+iovEUdbAVIrTCG9t854z2HAgaISoRUKyztJoOtJfI1wJaQU+XL+U3JIh4jmNx/k5UzJijfvfpT7Cv3ueMtqyAGBJrkLvXjiS7O5ylaCGuB0Qz711bWGkRrVoosPM3N6ECQQD8hVQUgnHEVHZYtvFqfcoq2g/onPbSqyjdrRu35a7PvgDAZx69Mr/XggGNTgT3jJn7+2XmiGkHM1fd1Ob/3uAdAkEA4D7aE3ZgXG/PQqlm3VbE/+4MvNl8xhjqOkByBOY2ZFfWKhlRziLEPSSAh16xEJ79WgY9iti+guLRAMravGrs2QJBAOmKWYeaWKNNxiIoF7/4VDgrcpkcSf3uRB44UjFSn8kLnWBUPo6WV+x1FQBdjqRviZ4NFGIP+KqrJnFHzNgJhVUCQFzCAukMDV4PLfeQJSmna8PFz2UKva8fvTutTryyEYu+PauaX5laDjyQbc4RIEMU0Q29CRX3BA8WDYg7YPGRdTkCQQCG+pjU2FB17ZLuKRlKEdtXNV6zQFTmFc1TKhlsDTtCkWs/xwkoCfZKstuV3Uc5J4BNJDkQOGm38pDRPcUDUh2/
-----END PRIVATE KEY-----
去除-----BEGIN PRIVATE KEY----- 和 -----END PRIVATE KEY-----
那PRIVATE KEY 就是
MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAN0yqPkLXlnhM+2H/57aHsYHaHXazr9pFQun907TMvmbR04wHChVsKVgGUF1hC0FN9hfeYT5v2SXg1WJSg2tSgk7F29SpsF0I36oSLCIszxdu7ClO7c22mxEVuCjmYpJdqb6XweAZzv4Is661jXP4PdrCTHRdVTU5zR9xUByiLSVAgMBAAECgYEAhznORRonHylm9oKaygEsqQGkYdBXbnsOS6busLi6xA+iovEUdbAVIrTCG9t854z2HAgaISoRUKyztJoOtJfI1wJaQU+XL+U3JIh4jmNx/k5UzJijfvfpT7Cv3ueMtqyAGBJrkLvXjiS7O5ylaCGuB0Qz711bWGkRrVoosPM3N6ECQQD8hVQUgnHEVHZYtvFqfcoq2g/onPbSqyjdrRu35a7PvgDAZx69Mr/XggGNTgT3jJn7+2XmiGkHM1fd1Ob/3uAdAkEA4D7aE3ZgXG/PQqlm3VbE/+4MvNl8xhjqOkByBOY2ZFfWKhlRziLEPSSAh16xEJ79WgY9iti+guLRAMravGrs2QJBAOmKWYeaWKNNxiIoF7/4VDgrcpkcSf3uRB44UjFSn8kLnWBUPo6WV+x1FQBdjqRviZ4NFGIP+KqrJnFHzNgJhVUCQFzCAukMDV4PLfeQJSmna8PFz2UKva8fvTutTryyEYu+PauaX5laDjyQbc4RIEMU0Q29CRX3BA8WDYg7YPGRdTkCQQCG+pjU2FB17ZLuKRlKEdtXNV6zQFTmFc1TKhlsDTtCkWs/xwkoCfZKstuV3Uc5J4BNJDkQOGm38pDRPcUDUh2/
本文出自 “java” 博客,请务必保留此出处http://5378610.blog.51cto.com/5368610/1874338
以上是关于支付宝集成纪录的主要内容,如果未能解决你的问题,请参考以下文章