Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

有支持denojs的计划吗/Is there a plan to support denojs? #143

Open
superAlibi opened this issue Jun 27, 2024 · 3 comments
Open

有支持denojs的计划吗/Is there a plan to support denojs? #143

superAlibi opened this issue Jun 27, 2024 · 3 comments

Comments

@superAlibi
Copy link

目前打算在denojs上做demo,看了下加密方式在denojs上不能原生支持.所以想问问未来有支持denojs的计划吗

@fengmk2
Copy link
Member

fengmk2 commented Jun 27, 2024

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

@superAlibi
Copy link
Author

实际上并不能,在使用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);
});
});

`

@fengmk2
Copy link
Member

fengmk2 commented Jun 27, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants