create account

支付宝扫码支付(当面付)开发之 RSAWithSHA1 / How to integrate scanning user Alipay paycode to get payment about RSAWithSHA1? by wjm

View this thread on: hive.blogpeakd.comecency.com
· @wjm ·
$14.46
支付宝扫码支付(当面付)开发之 RSAWithSHA1 / How to integrate scanning user Alipay paycode to get payment about RSAWithSHA1?
<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&amp;articleId=105351&amp;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(&amp;sha_ctx);</p>
<p>//if (1 != rc) { status = EXIT_FAILURE; goto end; }</p>
<p><br /></p>
<p>    rc = SHA1_Update(&amp;sha_ctx, buf, buf_len);</p>
<p>//if (1 != rc) { status = EXIT_FAILURE; goto end; }</p>
<p><br /></p>
<p>    rc = SHA1_Final(digest, &amp;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, &amp;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>
👍  , , , , , ,
properties (23)
authorwjm
permlinkrsawithsha1-how-to-integrate-scanning-user-alipay-paycode-to-get-payment-about-rsawithsha1
categorycn
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"]}
created2016-08-04 05:50:27
last_update2016-08-04 05:50:27
depth0
children1
last_payout2016-09-03 21:13:57
cashout_time1969-12-31 23:59:59
total_payout_value10.846 HBD
curator_payout_value3.612 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,607
author_reputation505,468,893,752
root_title"支付宝扫码支付(当面付)开发之 RSAWithSHA1 / How to integrate scanning user Alipay paycode to get payment about RSAWithSHA1?"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id595,881
net_rshares5,570,316,923,373
author_curate_reward""
vote details (7)
@eternalabove ·
properties (23)
authoreternalabove
permlinkrsawithsha1-how-to-integrate-scanning-user-alipay-paycode-to-get-payment-about-rsawithsha1
categorycn
json_metadata""
created2016-08-04 05:51:06
last_update2016-08-04 05:51:06
depth1
children0
last_payout2016-09-03 21:13:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7
author_reputation-922,435,559,398
root_title"支付宝扫码支付(当面付)开发之 RSAWithSHA1 / How to integrate scanning user Alipay paycode to get payment about RSAWithSHA1?"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id595,891
net_rshares-100,860,684
author_curate_reward""
vote details (52)