说明
小程序里报错ALI38173的问题,一般在my.tradePay、my.paySignCenter,这几个支付类接口里。错误原因和支持中心提供的一样
检查请求参数
1、对照我们的线上文档查看,比如:参数少了、多了、乱码、名称不对,还有必传参数是否都请求提交给支付宝了等等。
2、确认是否破坏了参数名=参数值&参数名=参数值的格式。
排查思路
本次,针对这个报错,我们提供一个详细的排查思路
先把orderStr这个参数里的赋值内容给打印出来,举例如下:
示例一:
alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2018030902340000&biz_content=%7B%22body%22%3A%22%25E9%25A2%2584%25E7%25BA%25A6%25E5%25AE%25A1%25E8%25BD%25A6%25E8%25B4%25B9%25E7%2594%25A8%22%2C%22out_trade_no%22%3A%22E201805251502141834984962%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22subject%22%3A%22%25E9%25A2%2584%25E7%25BA%25A6%25E5%25AE%25A1%25E8%25BD%25A6%25E8%25B4%25B9%25E7%2594%25A8%22%2C%22timeout_express%22%3A%2230m%22%2C%22total_amount%22%3A%220.01%22%7D&charset=GBK&format=json&method=alipay.trade.app.pay¬ify_url=http%3A%2F%2Fwww.alipay.com%2F&sign=aX2Cx1lA6uu5y4%2F%2FgA8nO6y0ADAp2D7yY4ZE9Hx3VfC8iWAHOvalrkLv3qknTkvoQo0fXt9whyvJbHIs8Pas%2FtVb1nSP9azfYG4T2gOi2EEa542JonkLg4fOnEdL8FMJhMYDXVrmP2gcjwUIhGd8J5E4gN2U9yocNuQ2FEeajmXlYfX7YdxbChqHmTq0JHJ9g%2FGUMKs39XX7Obp%2F4iDiVpO24s3AgdMrm0v0wW9DKgLGYAwq1U0qemyRZ%2B55UNyoZwmJBvqP3mBhtFN0%2BxEKvDv8PFT%2BiFZFtKCpIjGjnNcHLANenD1eGoQwq7nTyJrgSTlzX8v7TFb%2BnCmYoGGjnQ%3D%3D&sign_type=RSA2×tamp=2018-06-05+10%3A29%3A51&version=1.0
示例二:
alipay_sdk=alipay-sdk-php-20161101&app_id=2018012902100000&biz_content=%7B%22out_trade_no%22%3A%222018061112212055440%22%26%22total_amount%22%3A%22998.00%22%26%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%26%22subject%22%3A%22%E5%85%BB%E7%94%9F%E8%B5%84%E8%AE%AF%E6%94%AF%E4%BB%98%22%7D&charset=UTF-8&format=json&method=alipay.trade.app.pay¬ify_url=https%3A%2F%2Fwww.alipay.com%2Fxiao_notify_url&sign_type=RSA2×tamp=2018-06-11+12%3A21%3A21&version=1.0&sign=1JDo9XZAR%2FwQAEejazzfq7s1xWKf0nXLfxJIVHc4gPSxmQ7fyy%2F3VjWeOeb%2Ful%2B%2FyeAckCEql7B%2FneWVqbNAOFz1SZjsfQ9gqn64xXJgCi%2BjCIPS6%2F0GJCwbrRhNMuMcCHRAJUdOOFh3yTuGSFF3Q9BB%2FMx2KdaSJ%2FYyM8D1sidC6xeOpCF%2FC4Cw670TjdX2XpOAoxI4myEyWkLSSj6Ia2oS%2BKOaOjguUQUwzIVphlpO%2FEOoSUDJLw3B%2BjPSQYIbujqNO1ETdxhVoOPFk0fHi2LV2MI4zHz4HyuDC260IIcpE9XbncnUv5C65aIzGpiP1S%2FRAa%2BxF7%2FlP%2B3WLCnVug%3D%3D
以上两个示例是从开发者的后端返回给前端的数据。
用工具或自行urldecode下数据是长什么样呢?
与开放平台提供的签名逻辑进行比对、与接口文档的参数进行比对(app支付、当面付),有时候一次decode还不行,需要两次才能看到原始信息。
示例一
第一次decode:
alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2018030902340000&biz_content={"body":"%E9%A2%84%E7%BA%A6%E5%AE%A1%E8%BD%A6%E8%B4%B9%E7%94%A8","out_trade_no":"E201805251502141834984962","product_code":"QUICK_MSECURITY_PAY","subject":"%E9%A2%84%E7%BA%A6%E5%AE%A1%E8%BD%A6%E8%B4%B9%E7%94%A8","timeout_express":"30m","total_amount":"0.01"}&charset=GBK&format=json&method=alipay.trade.app.pay¬ify_url=http://www.alipay.com/&sign=aX2Cx1lA6uu5y4//gA8nO6y0ADAp2D7yY4ZE9Hx3VfC8iWAHOvalrkLv3qknTkvoQo0fXt9whyvJbHIs8Pas/tVb1nSP9azfYG4T2gOi2EEa542JonkLg4fOnEdL8FMJhMYDXVrmP2gcjwUIhGd8J5E4gN2U9yocNuQ2FEeajmXlYfX7YdxbChqHmTq0JHJ9g/GUMKs39XX7Obp/4iDiVpO24s3AgdMrm0v0wW9DKgLGYAwq1U0qemyRZ+55UNyoZwmJBvqP3mBhtFN0+xEKvDv8PFT+iFZFtKCpIjGjnNcHLANenD1eGoQwq7nTyJrgSTlzX8v7TFb+nCmYoGGjnQ==&sign_type=RSA2×tamp=2018-06-05 10:29:51&version=1.0
第二次decode:
alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2018030902340000&biz_content={"body":"预约审车费用","out_trade_no":"E201805251502141834984962","product_code":"QUICK_MSECURITY_PAY","subject":"预约审车费用","timeout_express":"30m","total_amount":"0.01"}&charset=GBK&format=json&method=alipay.trade.app.pay¬ify_url=http://www.alipay.com/&sign=aX2Cx1lA6uu5y4//gA8nO6y0ADAp2D7yY4ZE9Hx3VfC8iWAHOvalrkLv3qknTkvoQo0fXt9whyvJbHIs8Pas/tVb1nSP9azfYG4T2gOi2EEa542JonkLg4fOnEdL8FMJhMYDXVrmP2gcjwUIhGd8J5E4gN2U9yocNuQ2FEeajmXlYfX7YdxbChqHmTq0JHJ9g/GUMKs39XX7Obp/4iDiVpO24s3AgdMrm0v0wW9DKgLGYAwq1U0qemyRZ 55UNyoZwmJBvqP3mBhtFN0 xEKvDv8PFT iFZFtKCpIjGjnNcHLANenD1eGoQwq7nTyJrgSTlzX8v7TFb nCmYoGGjnQ==&sign_type=RSA2×tamp=2018-06-05 10:29:51&version=1.0
这个的问题在于biz_content被urlencode了一次,再做拼接后又urlencode了一次。
解决办法就是:biz_content不要urlencode。
示例二:
alipay_sdk=alipay-sdk-php-20161101&app_id=2018012902100000&biz_content={"out_trade_no":"2018061112212055440"&"total_amount":"998.00"&"product_code":"QUICK_MSECURITY_PAY"&"subject":"养生资讯支付"}&charset=UTF-8&format=json&method=alipay.trade.app.pay¬ify_url=https://www.alipay.com/xiao_notify_url&sign_type=RSA2×tamp=2018-06-11 12:21:21&version=1.0&sign=1JDo9XZAR/wQAEejazzfq7s1xWKf0nXLfxJIVHc4gPSxmQ7fyy/3VjWeOeb/ul+/yeAckCEql7B/neWVqbNAOFz1SZjsfQ9gqn64xXJgCi+jCIPS6/0GJCwbrRhNMuMcCHRAJUdOOFh3yTuGSFF3Q9BB/Mx2KdaSJ/YyM8D1sidC6xeOpCF/C4Cw670TjdX2XpOAoxI4myEyWkLSSj6Ia2oS+KOaOjguUQUwzIVphlpO/EOoSUDJLw3B+jPSQYIbujqNO1ETdxhVoOPFk0fHi2LV2MI4zHz4HyuDC260IIcpE9XbncnUv5C65aIzGpiP1S/RAa+xF7/lP+3WLCnVug==
可以看出biz_content里面不是JSON格式。
解决办法就是:把biz_content里的&字符改成半角的逗号【,】
简言之:
decode出来的信息,一个参数一个参数的检查,是否有缺少,是否拼接格式有异常即可。
使用开放平台SDK 正确的拼接结果长什么样子的呢,以下例子仅供参考:
alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2018041002532671&biz_content=%7B%22out_trade_no%22%3A%22cs20180419000002%22%2C%22total_amount%22%3A%220.01%22%2C%22subject%22%3A%22%E6%B5%8B%E8%AF%95%22%2C%22body%22%3A%22%E6%B5%8B%E8%AF%95%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%7D&charset=utf-8&format=json&method=alipay.trade.app.pay¬ify_url=http%3A%2F%2F%E5%B7%A5%E7%A8%8B%E5%85%AC%E7%BD%91%E8%AE%BF%E9%97%AE%E5%9C%B0%E5%9D%80%2Falipay.trade.page.pay-JAVA-UTF-8%2Fnotify_url.jsp&sign=NZjw96Y4ReP0Y%2Fcnb6SxfF%2B1bqvk%2BQquVKu56Y34X%2FO9nGvIQJKZmWCsZV7c%2BvAULJpdytxU0cOxPYMf9Drun%2BtDEW9qrOQD2eB8gDRoj09QRZFGupmtQjaUF1MKYCo3iiUiSwbIIzOk6oOecGMpGTohVmWH%2FKXrqbbYRQ18wfrJsMbWl6vZksgZ7wlUWd3B%2BxhI0oXaX5Qwi%2FgyYBETIrurgaLiY%2BRI7NZCW7KQlzS6LOVjnID%2FONgPD2PxB7d%2F2sq%2B0umBvWm8mEtcpmo7%2F2UhLDlD8UxAsal8i6agDlndpOOVRBMP2h%2FTCfJoGwcib7Y5iJ7QJpKPl56uYwF09g%3D%3D&sign_type=RSA2×tamp=2018-06-05+11%3A36%3A01&version=1.0
orderstr里的数据是怎么拼接起来的呢?
(以my.tradePay举例)
1. 先去找到APP支付的服务端SDK下载包
2. 再在下载的页面下方找到调用代码示例
3. 接着服务端调用接口getbody()拿到完整的数据拼接信息(注意是不带openapi.alipay.com网关的)
4. 然后通过前端的my.httpRequest回调给前端
5. 最后my.tradePay接口里的赋值给orderStr
在开发测试过程中,建议在服务端手工生成一个数据请求串,写死到前端代码里,以便定位是后端的请求串拼接问题还是前端解析问题。