alipay / alipay-sdk-nodejs-all

支付宝开放平台 Alipay SDK for Node.js
https://docs.open.alipay.com/54/103419/
Other
410 stars 65 forks source link

请求内容驼峰会被意外的转换 #137

Closed StringKe closed 5 months ago

StringKe commented 5 months ago

@fengmk2

import { AlipaySdk } from 'alipay-sdk';

import appConfig from './global/config';

const sdk = new AlipaySdk({
    camelcase: false,
    appId: appConfig.MINI_PROGRAM_APP_ID,
    privateKey: appConfig.MINI_PROGRAM_PRIVATE_KEY,
    alipayPublicKey: appConfig.MINI_PROGRAM_ALI_PUBLIC_KEY,
    encryptKey: appConfig.MINI_PROGRAM_ENCRYPT_KEY,
    gateway: appConfig.ALIPAY_GATEWAY,
});

const order = {
    orderNo: '2021042400000000000098724400',
};

const address = {
    address: '北京市朝阳区望京SOHO',
    phone: '13100000000',
    name: '张三',
};

const freezeParams = {
    out_order_no: order.orderNo,
    out_request_no: order.orderNo,
    amount: 0.01,
    order_title: '预授权冻结',
    product_code: 'PRE_AUTH_ONLINE',
    timeout_express: '3d',
    deposit_product_mode: 'DEPOSIT_ONLY',
    extra_param: {
        category: 'RENT_PHONE',
        serviceId: '2024042400000000000098724400',
        outStoreCode: 'test_0001',
        outStoreAlias: '赁免押服务',
        creditExtInfo: {
            lastPreAuthNo: '',
            carrierDesc: '内存:128GB,颜色:白色钛金属',
            rentPeriod: '12',
            rentAmount: 0.01,
            deliveryAddress: address.address,
            deliveryMobile: address.phone,
            deliveryName: address.name,
        },
    },
};

console.log(
    sdk.sdkExec('alipay.fund.auth.order.app.freeze', {
        bizContent: freezeParams,
        notifyUrl: 'https://alipay.com/api/index/freezeNotify',
        format: 'JSON',
    }),
);

method=alipay.fund.auth.order.app.freeze&app_id=2021004141643129&charset=utf-8&version=1.0&sign_type=RSA2&timestamp=2024-06-13%2018%3A43%3A35&notify_url=https%3A%2F%2Falipay.com%2Fapi%2Findex%2FfreezeNotify&format=JSON&biz_content=%7B%22out_order_no%22%3A%222021042400000000000098724400%22%2C%22out_request_no%22%3A%222021042400000000000098724400%22%2C%22amount%22%3A0.01%2C%22order_title%22%3A%22%E9%A2%84%E6%8E%88%E6%9D%83%E5%86%BB%E7%BB%93%22%2C%22product_code%22%3A%22PRE_AUTH_ONLINE%22%2C%22timeout_express%22%3A%223d%22%2C%22deposit_product_mode%22%3A%22DEPOSIT_ONLY%22%2C%22extra_param%22%3A%7B%22category%22%3A%22RENT_PHONE%22%2C%22service_id%22%3A%222024042400000000000098724400%22%2C%22out_store_code%22%3A%22test_0001%22%2C%22out_store_alias%22%3A%22%E5%9C%9F%E8%B1%86%E5%BF%AB%E7%A7%9F%E7%A7%9F%E8%B5%81%E5%85%8D%E6%8A%BC%E6%9C%8D%E5%8A%A1%22%2C%22credit_ext_info%22%3A%7B%22last_pre_auth_no%22%3A%22%22%2C%22carrier_desc%22%3A%22%E5%86%85%E5%AD%98%3A128GB%2C%E9%A2%9C%E8%89%B2%3A%E7%99%BD%E8%89%B2%E9%92%9B%E9%87%91%E5%B1%9E%22%2C%22rent_period%22%3A%2212%22%2C%22rent_amount%22%3A0.01%2C%22delivery_address%22%3A%22%E5%8C%97%E4%BA%AC%E5%B8%82%E6%9C%9D%E9%98%B3%E5%8C%BA%E6%9C%9B%E4%BA%ACSOHO%22%2C%22delivery_mobile%22%3A%2213100000000%22%2C%22delivery_name%22%3A%22%E5%BC%A0%E4%B8%89%22%7D%7D%7D&sign=fnHv63bDcO6CUE%2FUN%2BkcM5PwXYqQHf9kFVccJX%2BU%2B5ekjRE3K1MImftqdvNFLQBPmAINXUwiyzT3nKBjsisPyUB8hjEryFAfH3supgAFZZ2eGa3pYkjBgxu7phoPRkg1EZrUZ6fXigq9389fv2vJ7etlgNMRXOVRR%2FagG6WloS5bF0QdOeIAxciZKHV0V%2B16WRg%2BoN%2BPVo32mTg33X15MQwZtC%2FmBWCCdS6YJ%2Bal0d1nMIoQ2Rs%2FinCF4tmLjpZZs6vZAG71putq9mn%2BYg8m1JPUORhK2547yggemkzlBHfNn4%2FYAAoF1OxAmQzHiMcjGpnxsGtvmZPl7v5hjXzARQ%3D%3D

内部参数被意外的转换成驼峰了,但支付宝后端并不支持。

fengmk2 commented 5 months ago

@StringKe 你的意思是不要对 extra_param 里面的字段做任何转换对么?

StringKe commented 5 months ago

是的,这样会导致支付宝后端业务不通过的,设置了 camelcase 为 false 应该禁止所有的 key 转换

fengmk2 commented 5 months ago

是的,这样会导致支付宝后端业务不通过的,设置了 camelcase 为 false 应该禁止所有的 key 转换

ok,我加一个 camelcase 参数

StringKe commented 5 months ago

我看当前有 camelcase 这个参数了,有些地方好像不遵守这个参数

fengmk2 commented 5 months ago

我看当前有 camelcase 这个参数了,有些地方好像不遵守这个参数

camelcase 是对响应不做转换,不是请求参数,而且它是 config 级别的,不太好用。我新增一个 options 参数

fengmk2 commented 5 months ago

@StringKe https://github.com/alipay/alipay-sdk-nodejs-all/pull/138 帮忙看看这样是否能解决你的问题?

StringKe commented 5 months ago

我拉源码到本地运行么? 这个好像没发 beta / alpha 版本

fengmk2 commented 5 months ago

@StringKe 如果参数命名理解没有问题,我就合并发一个版本。

StringKe commented 5 months ago

看着没问题,我看构造里有一个 camelcase 会有影响吗?

fengmk2 commented 5 months ago

我按你的 issue 提供的 freezeParams 数据造的单测,就是不对 freezeParams 做任何参数处理。

fengmk2 commented 5 months ago

@StringKe 用 alipay-sdk@4.8.0