Last active
February 26, 2019 12:29
-
-
Save imyelo/05dcde922e9698a348a5bdc7c32b0a34 to your computer and use it in GitHub Desktop.
comparing signstr encoding of `alipay.user.agreement.page.sign`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// comparing signstr encoding of `alipay.user.agreement.page.sign` | |
const querystring = require('querystring') | |
function step1 (params) { | |
return querystring.stringify(params) | |
} | |
function step2 (qs) { | |
return encodeURIComponent(qs) | |
} | |
function assert (title, actual, expected) { | |
let isEqual | |
actual = actual.toLowerCase() | |
expected = expected.toLowerCase() | |
isEqual = actual === expected | |
console.log(title, isEqual) | |
if (!isEqual) { | |
console.log('actual:', actual) | |
console.log('expected:', expected) | |
} | |
} | |
const biz = { | |
"access_params": { | |
"channel": "ALIPAYAPP" | |
}, | |
"external_agreement_no": "beijignditie_1", | |
"identity_params": { | |
"cert_no": "610402196908019453", | |
"user_name": "jbuflp" | |
}, | |
"personal_product_code": "GENERAL_WITHHOLDING_P", | |
"sign_scene": "INDUSTRY|METRO", | |
"zm_auth_params": { | |
"buckle_app_id": "1001164", | |
"buckle_merchant_id": "268820000000414397785" | |
} | |
} | |
const params = { | |
"biz_content": JSON.stringify(biz), | |
"sign": "CxxysLRx0P/dEuSTw/xsH+utBXMDto5ez2fvtg5NmtxAhbp45BIUJfjM+KRsqNMTSPqtTXuOWxieUvFxTHA9aodPpc7Wbjx/1RUI0sT/YJI34PH2Xv0qtCMBT4wunP3J2ZKYByVNRKRGZ0etb0LuhuxPikSyQy8qKn/GsXQJ04c=", | |
"timestamp": "2017-06-29 21:06:02", | |
"sign_type": "RSA", | |
"charset": "UTF-8", | |
"app_id": "2017060101317939", | |
"method": "alipay.user.agreement.page.sign", | |
"version": "1.0" | |
} | |
/** | |
* document: https://docs.alipay.com/pre-open/20170601105911096277/cmgtz2#a-nameftodioa%E7%A4%BA%E4%BE%8B | |
*/ | |
const result_1_from_document = 'biz_content={"access_params"%3A{"channel"%3A"ALIPAYAPP"}%2C"external_agreement_no"%3A"beijignditie_1"%2C"identity_params"%3A{"cert_no"%3A"610402196908019453"%2C"user_name"%3A"jbuflp"}%2C"personal_product_code"%3A"GENERAL_WITHHOLDING_P"%2C"sign_scene"%3A"INDUSTRY|METRO"%2C"zm_auth_params"%3A{"buckle_app_id"%3A"1001164"%2C"buckle_merchant_id"%3A"268820000000414397785"}}&sign=CxxysLRx0P%2FdEuSTw%2FxsH%2ButBXMDto5ez2fvtg5NmtxAhbp45BIUJfjM%2BKRsqNMTSPqtTXuOWxieUvFxTHA9aodPpc7Wbjx%2F1RUI0sT%2FYJI34PH2Xv0qtCMBT4wunP3J2ZKYByVNRKRGZ0etb0LuhuxPikSyQy8qKn%2FGsXQJ04c%3D×tamp=2017-06-29+21%3A06%3A02&sign_type=RSA&charset=UTF-8&app_id=2017060101317939&method=alipay.user.agreement.page.sign&version=1.0' | |
const result_2_from_document = 'biz_content%3d%257B%2522access_params%2522%253A%257B%2522channel%2522%253A%2522ALIPAYAPP%2522%257D%252C%2522external_agreement_no%2522%253A%2522beijignditie_1%2522%252C%2522identity_params%2522%253A%257B%2522cert_no%2522%253A%2522610402196908019453%2522%252C%2522user_name%2522%253A%2522jbuflp%2522%257D%252C%2522personal_product_code%2522%253A%2522GENERAL_WITHHOLDING_P%2522%252C%2522sign_scene%2522%253A%2522INDUSTRY%257CMETRO%2522%252C%2522zm_auth_params%2522%253A%257B%2522buckle_app_id%2522%253A%25221001164%2522%252C%2522buckle_merchant_id%2522%253A%2522268820000000414397785%2522%257D%257D%26sign%3dCxxysLRx0P%252FdEuSTw%252FxsH%252ButBXMDto5ez2fvtg5NmtxAhbp45BIUJfjM%252BKRsqNMTSPqtTXuOWxieUvFxTHA9aodPpc7Wbjx%252F1RUI0sT%252FYJI34PH2Xv0qtCMBT4wunP3J2ZKYByVNRKRGZ0etb0LuhuxPikSyQy8qKn%252FGsXQJ04c%253D%26timestamp%3d2017-06-29%2b21%253A06%253A02%26sign_type%3dRSA%26charset%3dUTF-8%26app_id%3d2017060101317939%26method%3dalipay.user.agreement.page.sign%26version%3d1.0' | |
let result_1 = step1(params) | |
assert('result of step 1:', result_1, result_1_from_document) | |
let result_2 = step2(result_1) | |
assert('reuslt of step 2:', result_2, result_2_from_document) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment