对于如下的参数数组:
string[] parameters={ "service=\"mobile.securitypay.pay\"", "partner=\"2088101568338364\"", "_input_charset=\"utf-8\"", "notify_url=\"http://notify.msp.hk/notify.htm\"", "out_trade_no=\"0819145412-6177\"", "subject=\"《暗黑破坏神3:凯恩之书》\"", "payment_type=\"1\"", "seller_id=\"alipay-test01@alipay.com\"", "total_fee=\"0.01\"" };
把所有数组值以key= “value”进行组合,之后用“&”字符连接起来,支持无序,如:
service="mobile.securitypay.pay"&partner="2088101568338364"&_input_charset="utf-8"¬ify_url="http://notify.msp.hk/notify.htm"&out_trade_no="0819145412-6177"&subject="测试"&payment_type="1"&seller_id="xxx@alipay.com"&total_fee="0.01"
这串字符串便是待签名字符串。
对于同步通知的内容:
resultStatus={9000};memo={};result={partner="2088101568358171"&seller_id="xxx@alipay.com"&out_trade_no="0819145412-6177"&subject="测试"&body="测试测试"&total_fee="0.01"¬ify_url="http://notify.msp.hk/notify.htm"&service="mobile.securitypay.pay"&payment_type="1"&_input_charset="utf-8"&it_b_pay="30m"&success="true"&sign_type="RSA"&sign="hkFZr+zE9499nuqDNLZEF7W75RFFPsly876QuRSeN8WMaUgcdR00IKy5ZyBJ4eldhoJ/2zghqrD4E2G2mNjs3aE+HCLiBXrPDNdLKCZgSOIqmv46TfPTEqopYfhs+o5fZzXxt34fwdrzN4mX6S13cr3UwmEV4L3Ffir/02RBVtU="}
取出result中的部分,去掉sign和sign_type两个参数:
partner="2088101568358171"&seller_id="xxx@alipay.com"&out_trade_no="0819145412-6177"&subject="测试"&body="测试测试"&total_fee="0.01"¬ify_url="http://notify.msp.hk/notify.htm"&service="mobile.securitypay.pay"&payment_type="1"&_input_charset="utf-8"&it_b_pay="30m"&success="true"
即为待签名字符串。
对于异步通知的内容:
http://notify.java.jpxx.org/index.jsp?discount=0.00&payment_type=8&subject=测试&trade_no=2013082244524842&buyer_email=dlw***@gmail.com&gmt_create=2013-08-22 14:45:23¬ify_type=trade_status_sync&quantity=1&out_trade_no=082215222612710&seller_id=2088501624816263¬ify_time=2013-08-22 14:45:24&body=测试测试&trade_status=TRADE_SUCCESS&is_total_fee_adjust=N&total_fee=1.00&gmt_payment=2013-08-22 14:45:24&seller_email=xxx@alipay.com&price=1.00&buyer_id=2088602315385429¬ify_id=64ce1b6ab92d00ede0ee56ade98fdf2f4c&use_coupon=N&sign_type=RSA&sign=1glihU9DPWee+UJ82u3+mw3Bdnr9u01at0M/xJnPsGuHh+JA5bk3zbWaoWhU6GmLab3dIM4JNdktTcEUI9/FBGhgfLO39BKX/eBCFQ3bXAmIZn4l26fiwoO613BptT44GTEtnPiQ6+tnLsGlVSrFZaLB9FVhrGfipH2SWJcnwYs=
去掉sign和sign_type两个参数,将其他参数按照字母顺序升序排列,再把所有数组值以“&”字符连接起来:
body=测试测试 &buyer_email=dlw***@gmail.com&buyer_id=2088602315385429&discount=0.00&gmt_create=2013-08-22 14:45:23&gmt_payment=2013-08-22 14:45:24&is_total_fee_adjust=N¬ify_time=2013-08-22 14:45:24¬ify_type=trade_status_sync&out_trade_no=082215222612710&payment_type=8&price=1.00&quantity=1&seller_email=alipayrisk18@alipay.com&seller_id=2088501624816263&subject测试&total_fee=1.00&trade_no=2013082244524842&trade_status=TRADE_SUCCESS&use_coupon=N
即为待签名字符串。
注意:
- 没有值的参数无需传递,也无需包含到待签名数据中;
- 签名时将字符转化成字节流时指定的字符集与_input_charset保持一致;
- 如果传递了_input_charset参数,这个参数也应该包含在待签名数据中。
得到的签名结果是也是一串字符串,这串字符串便是sign参数的值,把这串字符串赋值于sign参数。