Node.js在使用POST请求信息后重定向

时间:2018-04-10 10:35:50

标签: node.js post request graphql

目前我使用Express,Node.js,Graphql来构建后端服务器, 我想将数据发布到在线支付系统中,当我成功使用请求发布数据时,我发现它可以在我的终端中控制一个HTML主体,但我想要的是Graphql接口可以重定向到平台而不仅仅是输出HTML正文,我该怎么做才能解决这个问题?这是我的参考代码。

Mutation: {
    createPayment: async (parent, args, { models, user }) => {
      const MerchantID = Merchantvalue;
      const TotalAmt = await args.TotalAmt;
      const ItemName = await args.ItemName;
      const ChoosePayment = await args.ChoosePayment;
      const PaymentType = payment value;
      const TradeDesc = await args.TradeDesc;
      const ReturnURL = returnurl;
      const EncryptType = encry;
      const MerchantTradeNo = await CheckMacValue.random;
      const MerchantTradeDate = await CheckMacValue.datetime;
      const TheCheckMacValue = await CheckMacValue.PaymentOnceValue(
        MerchantID, PaymentType, TotalAmt, TradeDesc,
        ItemName, ReturnURL, ChoosePayment, EncryptType,
      );

      const formData = {
        MerchantID: MerchantID,
        MerchantTradeNo: MerchantTradeNo,
        MerchantTradeDate: MerchantTradeDate,
        TotalAmount: TotalAmt,
        ItemName: ItemName,
        ChoosePayment: ChoosePayment,
        PaymentType: PaymentType,
        TradeDesc: TradeDesc,
        ReturnURL: ReturnURL,
        EncryptType: EncryptType,
        CheckMacValue: TheCheckMacValue,
      };
//In here I can successfully post data, but I want to redirect rather than just console the body in terminal.

      request.post(
        { url: 'https://payment-stage.ecpay.com.tw/Cashier/AioCheckOut/V5', formData: formData },
        function optionalCallback (err, httpResponse, body) {
        if (err) {
          return console.error('upload failed:', err);
        }
        console.log(body);
 });
    },
  },

1 个答案:

答案 0 :(得分:0)

您需要做的是将正确的响应(代码,消息)传递给客户端并在客户端处理该重定向逻辑(Web,移动等)