klover2 / wechatpay-node-v3-ts

微信支付v3
MIT License
560 stars 86 forks source link

Create T3 App项目中调用方法报错 #82

Open ss707494 opened 1 month ago

ss707494 commented 1 month ago
TypeError: hexoid is not a function
at eval (webpack-internal:///(rsc)/./node_modules/.pnpm/formidable@2.1.2/node_modules/formidable/src/Formidable.js:15:18)
at (rsc)/./node_modules/.pnpm/formidable@2.1.2/node_modules/formidable/src/Formidable.js (...\t3-next\.next\server\vendor-chunks\formidable@2.1.2.js:20:1)
at __webpack_require__ (...\t3-next\.next\server\webpack-runtime.js:33:43)
at eval (webpack-internal:///(rsc)/./node_modules/.pnpm/formidable@2.1.2/node_modules/formidable/src/index.js:5:20)
at (rsc)/./node_modules/.pnpm/formidable@2.1.2/node_modules/formidable/src/index.js (...\t3-next\.next\server\vendor-chunks\formidable@2.1.2.js:63:1)
at __webpack_require__ (...\t3-next\.next\server\webpack-runtime.js:33:43)
at eval (webpack-internal:///(rsc)/./node_modules/.pnpm/superagent@8.1.2/node_modules/superagent/lib/node/index.js:29:20)
at (rsc)/./node_modules/.pnpm/superagent@8.1.2/node_modules/superagent/lib/node/index.js (...\t3-next\.next\server\vendor-chunks\superagent@8.1.2.js:50:1)
at __webpack_require__ 

这个是我的调用方法


import fs from "node:fs";
import WxPay from "wechatpay-node-v3";

const pay = new WxPay({
  appid: "***",
  mchid: "***",
  publicKey: fs.readFileSync("./cert/apiclient_cert.pem"), // 公钥
  privateKey: fs.readFileSync("./cert/apiclient_key.pem"), // 秘钥
});

export const payNative = async () => {
  try {

    const params = {
      description: "测试",
      out_trade_no: "***",
      notify_url: "https://www.weixin.qq.com/wxpay/pay.php",
      amount: {
        total: 1,
      },
      scene_info: {
        payer_client_ip: "ip",
      },
    };

    const result = await pay.transactions_native(params);
    console.log(result);
  } catch (error) {
    console.error(error);
  }
  // # { status: 200, code_url: 'weixin://wxpay/bizpayurl?pr=9xFPmlUzz' }
};
klover2 commented 1 month ago
TypeError: hexoid is not a function
at eval (webpack-internal:///(rsc)/./node_modules/.pnpm/formidable@2.1.2/node_modules/formidable/src/Formidable.js:15:18)
at (rsc)/./node_modules/.pnpm/formidable@2.1.2/node_modules/formidable/src/Formidable.js (...\t3-next\.next\server\vendor-chunks\formidable@2.1.2.js:20:1)
at __webpack_require__ (...\t3-next\.next\server\webpack-runtime.js:33:43)
at eval (webpack-internal:///(rsc)/./node_modules/.pnpm/formidable@2.1.2/node_modules/formidable/src/index.js:5:20)
at (rsc)/./node_modules/.pnpm/formidable@2.1.2/node_modules/formidable/src/index.js (...\t3-next\.next\server\vendor-chunks\formidable@2.1.2.js:63:1)
at __webpack_require__ (...\t3-next\.next\server\webpack-runtime.js:33:43)
at eval (webpack-internal:///(rsc)/./node_modules/.pnpm/superagent@8.1.2/node_modules/superagent/lib/node/index.js:29:20)
at (rsc)/./node_modules/.pnpm/superagent@8.1.2/node_modules/superagent/lib/node/index.js (...\t3-next\.next\server\vendor-chunks\superagent@8.1.2.js:50:1)
at __webpack_require__ 

这个是我的调用方法


import fs from "node:fs";
import WxPay from "wechatpay-node-v3";

const pay = new WxPay({
  appid: "***",
  mchid: "***",
  publicKey: fs.readFileSync("./cert/apiclient_cert.pem"), // 公钥
  privateKey: fs.readFileSync("./cert/apiclient_key.pem"), // 秘钥
});

export const payNative = async () => {
  try {

    const params = {
      description: "测试",
      out_trade_no: "***",
      notify_url: "https://www.weixin.qq.com/wxpay/pay.php",
      amount: {
        total: 1,
      },
      scene_info: {
        payer_client_ip: "ip",
      },
    };

    const result = await pay.transactions_native(params);
    console.log(result);
  } catch (error) {
    console.error(error);
  }
  // # { status: 200, code_url: 'weixin://wxpay/bizpayurl?pr=9xFPmlUzz' }
};

你指定一下superagent的版本 npm install superagent@8.0.6 看下可以吗