文档中心 > 移动支付

签名机制

更新时间:2017/07/11 访问次数:194149

需要参与签名的参数

  • 在请求参数列表中,除去sign、sign_type两个参数外,其他需要使用到的参数皆是要签名的参数。
  • 在同步通知、服务器异步通知参数列表中,除去sign、sign_type两个参数外,凡是通知返回回来的参数皆是要验签的参数。
  • sign值要做utf-8 URLencode。

生成待签名字符串

1、支付接口待签名字符串生成

对于如下的参数数组:

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"&notify_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"

这串字符串便是待签名字符串。

2、同步通知待签名字符串生成

对于同步通知的内容:

resultStatus={9000};memo={};result={partner="2088101568358171"&seller_id="xxx@alipay.com"&out_trade_no="0819145412-6177"&subject="测试"&body="测试测试"&total_fee="0.01"&notify_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"&notify_url="http://notify.msp.hk/notify.htm"&service="mobile.securitypay.pay"&payment_type="1"&_input_charset="utf-8"&it_b_pay="30m"&success="true"

即为待签名字符串。

3、异步通知待签名字符串生成

对于异步通知的内容:

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&notify_type=trade_status_sync&quantity=1&out_trade_no=082215222612710&seller_id=2088501624816263&notify_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&notify_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&notify_time=2013-08-22 14:45:24&notify_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参数,这个参数也应该包含在待签名数据中。

调用签名函数

  1. 密钥生成:
    请查看:RSA私钥及公钥生成
  2. 密钥用法:
    准备好支付宝公钥、商户自己生成的私钥、待签名字符串。
  3. 签名函数
    调用RSA加密函数,分别把商户自己生成的私钥、待签名字符串置入函数中得到签名结果。

签名结果的用途

得到的签名结果是也是一串字符串,这串字符串便是sign参数的值,把这串字符串赋值于sign参数。

FAQ

关于此文档暂时还没有FAQ
返回
顶部