<p>上一篇 <a href="https://steemit.com/cn/@wjm/how-to-integrate-scan-user-alipay-paycode-to-get-payment">支付宝扫码支付(当面付)开发流程 / How to integrate scanning user Alipay paycode to get payment?</a></p> <p>我描述一下流程,在实现过程中,发现一个问题,就是如果你用得不是阿里官方支持的开发语言(C#, Java, PHP),那么你需要自己使用处理 HTTP 请求,其中最麻烦的一步是 <a href="https://doc.open.alipay.com/doc2/detail.htm?treeId=200&articleId=105351&docType=1" rel="noopener">商户请求参数的签名串,详见签名</a> ,当前这里只支持 RSAWithSHA1,我这次用的是 Delphi,在网上找了一代码,比如 </p> <p><a href="http://bbs.csdn.net/topics/391854462" rel="noopener"> http://bbs.csdn.net/topics/391854462 </a></p> <p>这段代码很奇怪,有时候签出来的了符不对,所以我直接用 VC2010 写了一个 DLL 直接 link OpenSSL 的 libary (这个 library 在 secret_key_tools_RSA_win 自带</p> <p>int __stdcall sign_data(</p> <p> const void *buf, /* input data: byte array */</p> <p> size_t buf_len, </p> <p> void *pkey, /* input private key: byte array of the PEM representation */</p> <p> size_t pkey_len,</p> <p> void *out_sig, /* output signature block, allocated in the function */</p> <p> size_t out_sig_len) </p> <p>{</p> <p> int status = EXIT_SUCCESS;</p> <p> int rc = 1;</p> <p><br /></p> <p> SHA_CTX sha_ctx = { 0 };</p> <p> unsigned char digest[SHA_DIGEST_LENGTH];</p> <p><br /></p> <p> rc = SHA1_Init(&sha_ctx);</p> <p>//if (1 != rc) { status = EXIT_FAILURE; goto end; }</p> <p><br /></p> <p> rc = SHA1_Update(&sha_ctx, buf, buf_len);</p> <p>//if (1 != rc) { status = EXIT_FAILURE; goto end; }</p> <p><br /></p> <p> rc = SHA1_Final(digest, &sha_ctx);</p> <p>//if (1 != rc) { status = EXIT_FAILURE; goto end; }</p> <p><br /></p> <p>BIO *b = NULL;</p> <p> RSA *r = NULL;</p> <p><br /></p> <p> b = BIO_new_mem_buf(pkey, pkey_len);</p> <p> r = PEM_read_bio_RSAPrivateKey(b, NULL, NULL, NULL);</p> <p><br /></p> <p>unsigned char *sig = NULL;</p> <p> unsigned int sig_len = 0;</p> <p><br /></p> <p>int s = RSA_size(r);</p> <p><br /></p> <p>sig = (unsigned char *)malloc(s);</p> <p>//if (NULL == sig) {status = EXIT_FAILURE; goto end; }</p> <p><br /></p> <p>rc = RSA_sign(NID_sha1, digest, sizeof digest, sig, &sig_len, r);</p> <p>//if (1 != rc) {status = EXIT_FAILURE; goto end; }</p> <p><br /></p> <p>base64_encode((char *)sig, sig_len, (char *)out_sig, out_sig_len);</p> <p><br /></p> <p>return status;</p> <p>}</p> <p>Delphi 里</p> <p>声明:</p> <p>function sign_data(</p> <p> buf: PChar;</p> <p> buf_len: integer;</p> <p> pkey: PChar;</p> <p> pkey_len: integer;</p> <p> out_sig: PChar;</p> <p> out_sign_len: integer): integer;</p> <p> external 'RSAWithSHA1DLL.dll';</p> <p><br /></p>
author | wjm |
---|---|
permlink | rsawithsha1-how-to-integrate-scanning-user-alipay-paycode-to-get-payment-about-rsawithsha1 |
category | cn |
json_metadata | {"tags":["cn","alipay"],"links":["https://steemit.com/cn/@wjm/how-to-integrate-scan-user-alipay-paycode-to-get-payment","https://doc.open.alipay.com/doc2/detail.htm?treeId=200&articleId=105351&docType=1","http://bbs.csdn.net/topics/391854462"]} |
created | 2016-08-04 05:50:27 |
last_update | 2016-08-04 05:50:27 |
depth | 0 |
children | 1 |
last_payout | 2016-09-03 21:13:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 10.846 HBD |
curator_payout_value | 3.612 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 2,607 |
author_reputation | 505,468,893,752 |
root_title | "支付宝扫码支付(当面付)开发之 RSAWithSHA1 / How to integrate scanning user Alipay paycode to get payment about RSAWithSHA1?" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 595,881 |
net_rshares | 5,570,316,923,373 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
abit | 0 | 5,566,206,648,994 | 100% | ||
murh | 0 | 1,394,889,796 | 11.33% | ||
tokyodude | 0 | 140,146,792 | 100% | ||
lief | 0 | 2,242,524,075 | 100% | ||
wjm | 0 | 269,067,228 | 100% | ||
jackeyjiang | 0 | 62,412,415 | 100% | ||
eternalabove | 0 | 1,234,073 | 0.1% |
Upvoted
author | eternalabove |
---|---|
permlink | rsawithsha1-how-to-integrate-scanning-user-alipay-paycode-to-get-payment-about-rsawithsha1 |
category | cn |
json_metadata | "" |
created | 2016-08-04 05:51:06 |
last_update | 2016-08-04 05:51:06 |
depth | 1 |
children | 0 |
last_payout | 2016-09-03 21:13:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 7 |
author_reputation | -922,435,559,398 |
root_title | "支付宝扫码支付(当面付)开发之 RSAWithSHA1 / How to integrate scanning user Alipay paycode to get payment about RSAWithSHA1?" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 595,891 |
net_rshares | -100,860,684 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
soupernerd | 0 | 226,085,432 | 10% | ||
emilyelizabeth | 0 | 17,025,145 | 10% | ||
weenis | 0 | 221,886,817 | 10% | ||
steemitlove | 0 | 5,179,895 | 10% | ||
steemlove | 0 | 5,157,062 | 10% | ||
steemit.tips | 0 | 11,386,634 | 10% | ||
curls4life | 0 | 4,974,375 | 10% | ||
alniskobs | 0 | 5,070,951 | 10% | ||
amboyst | 0 | 4,974,431 | 10% | ||
cheremet | 0 | 4,998,424 | 10% | ||
anarchypory | 0 | 5,032,451 | 10% | ||
angevel | 0 | 5,006,315 | 10% | ||
backetri | 0 | 5,000,838 | 10% | ||
chonesta | 0 | 6,296,493 | 10% | ||
countrytalented | 0 | 5,126,390 | 10% | ||
cozyone123 | 0 | 4,968,646 | 10% | ||
crumaner | 0 | 5,030,723 | 10% | ||
daysaiyan | 0 | 4,995,608 | 10% | ||
daysmega | 0 | 4,995,315 | 10% | ||
daysmega1421 | 0 | 5,036,118 | 10% | ||
dotersvilic | 0 | 4,968,322 | 10% | ||
eternalabove | 0 | 4,936,293 | 10% | ||
sugarfromhell | 0 | 4,934,027 | 10% | ||
gaspot | 0 | 5,103,013 | 10% | ||
forgetthefallen | 0 | 5,012,120 | 10% | ||
eleiminer | 0 | 4,988,339 | 10% | ||
etccrap | 0 | 4,921,209 | 10% | ||
abctrade | 0 | 6,565,043 | 10% | ||
yandra86 | 0 | 5,094,736 | 10% | ||
hxclife | 0 | 5,128,138 | 10% | ||
rottennasty | 0 | 4,961,813 | 10% | ||
bignastywhale | 0 | 6,153,249 | 10% | ||
feeltheblade | 0 | 4,916,545 | 10% | ||
silvesterstay | 0 | 4,889,352 | 10% | ||
joujou666 | 0 | 4,909,566 | 10% | ||
praisenoone | 0 | 5,273,548 | 10% | ||
rickydevil | 0 | 5,267,870 | 10% | ||
softpunk | 0 | 5,005,347 | 10% | ||
redddet | 0 | 4,925,758 | 10% | ||
catirabella | 0 | 4,993,036 | 10% | ||
redredwinewine | 0 | 5,030,751 | 10% | ||
gunpower | 0 | 6,483,901 | 10% | ||
koolaidssss | 0 | 6,114,670 | 10% | ||
hasherfromhell | 0 | 6,213,972 | 10% | ||
cheetah80 | 0 | -95,811,888 | -100% | ||
cheetah81 | 0 | -95,808,741 | -100% | ||
cheetah76 | 0 | -115,515,365 | -100% | ||
cheetah82 | 0 | -95,768,864 | -100% | ||
cheetah77 | 0 | -95,753,916 | -100% | ||
cheetah78 | 0 | -95,744,893 | -100% | ||
cheetah79 | 0 | -95,738,729 | -100% | ||
cheetah83 | 0 | -95,736,969 | -100% |