TypeError: Class constructor BaseContextClass cannot be invoked without 'new'
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; }
} }
相关环境信息
- windows:
- Node v12.18.3:
- Egg "2.0.0:
提供最小可复现仓库
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 天内没有进展会被自动关闭。
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.