eggjs / egg

🥚 Born to build better enterprise frameworks and apps with Node.js & Koa
https://eggjs.org
MIT License
18.87k stars 1.81k forks source link

TypeError: Class constructor BaseContextClass cannot be invoked without 'new' #4455

Closed echoiitime closed 4 years ago

echoiitime commented 4 years ago

What happens?

在 egg 后端项目中 使用 alipay-sdk 因为 alipay-sdk 是 TS项目 我们在目录文件 TS service

最小可复现仓库

请使用 npm init egg --type=simple bug 创建,并上传到你的 GitHub 仓库

复现步骤,错误日志以及相关配置

import AlipaySdk from 'alipay-sdk' ; // 初始化sms_client import { Service } from 'egg'; const fs = require('fs'); const path = require('path');

const appId = ""; // const privateKey = 'asdasda'; const alipaySdk = new AlipaySdk({ // 参考下方 SDK 配置 appId: '', privateKey // privateKey: fs.readFileSync('./private-key.pem', 'ascii'), // alipayRootCertPath: path.join(dirname,'../fixtures/alipayRootCert.crt'), // appCertPath: path.join(dirname,'../fixtures/appCertPublicKey.crt'), // alipayPublicCertPath: path.join(__dirname,'../fixtures/alipayCertPublicKey_RSA2.crt'), });

export default class PayService extends Service {

public async recognizeIdentityCard(option) { const { ctx, app } = this; const { logger } = app; const { code } = option; try { const data = await alipaySdk.exec('alipay.system.oauth.token', { grantType: 'authorization_code', code: code, refreshToken: 'token' }); if (data) { return true; } logger.info("\n OcrService recognizeIdentityCard res", JSON.stringify(data)); return false; } catch (err) { logger.info("\n OcrService recognizeIdentityCard err", JSON.stringify(err)); return false; }

} }

相关环境信息

atian25 commented 4 years ago

提供最小可复现仓库

egg-bot commented 4 years ago

Hello @echoiitime. Please provide a reproducible example following the instruction.

Issues labeled by Need Reproduce will be closed if no activities in 7 days.


@echoiitime,请根据这个说明提供最小可复现代码。

如果在 7 天内没有进展会被自动关闭。

atian25 commented 4 years ago

hey, we need more information to follow up this issue, recommend using npm init egg --type=simple to provide a mini project and upload to your GitHub.

for now, it will close due to lack of activity, feel free to reopen this issue if provided more information.