egg icon indicating copy to clipboard operation
egg copied to clipboard

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

Open echoiitime opened this issue 6 years ago • 3 comments

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:

echoiitime avatar Sep 04 '20 12:09 echoiitime

提供最小可复现仓库

atian25 avatar Sep 04 '20 12:09 atian25

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 天内没有进展会被自动关闭。

egg-bot avatar Sep 07 '20 08:09 egg-bot

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.

atian25 avatar Sep 08 '20 00:09 atian25