Giter Site home page Giter Site logo

Comments (3)

fengmk2 avatar fengmk2 commented on July 28, 2024

我们只支持 nodejs 的官方 api,类似 bun 这种兼容 nodejs api 的运行时应该是可以运行的。

from alipay-sdk-nodejs-all.

superAlibi avatar superAlibi commented on July 28, 2024

实际上并不能,在使用sdk发送curl请求时,会将密钥对内容进行签名,但实际上密钥是base64的,在签名时使用node:crypto模块对密钥显式解码时,爆出私钥的base64无法解码
以下是逻辑代码和测试文件内容
`deno.json
{
...
"imports": {
"alipaysdk": "npm:alipay-sdk@latest"
}
...
}

javascript
// projectroot/tools/sdk/alipay.ts
import { AlipaySdk } from "alipaysdk";

const urlObj = new URL(import.meta.url);
const query = Object.fromEntries(urlObj.searchParams.entries());

/**

  • 如果当前是测试模式,需要自动加载环境变量
    */
    if ("test" in query) {
    await import("$std/dotenv/load.ts");
    }
    let alipaySdk: AlipaySdk;
    export function getAlipaySDKInstane() {
    if (alipaySdk) {
    return alipaySdk;
    }
    return alipaySdk = new AlipaySdk({
    appId: Deno.env.get("ALIPAY_APPID") as string,
    privateKey: Deno.env.get("APP_PRIVATE_KEY") as string,
    alipayPublicKey: Deno.env.get("ALIPAY_PUBLIC_KEY"),
    gateway: "https://openapi.alipay.com/gateway.do",
    // keyType: "PKCS8",
    });
    }

javascript
// projectroot/test/alipay.test.ts
import { getAlipaySDKInstane } from "../tools/sdk/alipay.ts?test";

Deno.test("test alipay sdk", async (t) => {
const alipay = getAlipaySDKInstane();
await t.step("test query", async (t) => {
const result = await alipay.curl("POST", "alipay.trade.page.pay", {
body: {
bizContent: {
outTradeNo: "123456",
productCode: "FAST_INSTANT_TRADE_PAY",
totalAmount: "0.01",
},
},
});
console.log(result);
});
});

`

from alipay-sdk-nodejs-all.

fengmk2 avatar fengmk2 commented on July 28, 2024

deno 不支持 nodejs api,是不支持的。

from alipay-sdk-nodejs-all.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.