【发布时间】:2022-01-26 13:21:04
【问题描述】:
我的网址是这样的:
http://localhost:3000/success?merchant=xxxxxx&order_id=xxxxx&payment_ref_id=xxxxxxx&status=Aborted&status_code=9999&message=Not%20a%20Nagad%20account
我需要从 getServerSideProps 中的 URL 获取 payment_ref_id。我怎样才能做到这一点?
我尝试了context.query.payment_ref_id 之类的方法,但没有奏效。
我的代码:
export const getServerSideProps: GetServerSideProps = async (context) => {
try {
const payment_reference_id = context.query.payment_ref_id;
const response = await axios.get(`${BASE_URL}/remote-payment-gateway-1.0/api/dfs/verify/payment/${payment_reference_id}`,
{
headers: {
"X-KM-IP-V4": IP_ADDRESS,
"X-KM-Client-Type": "PC_WEB",
"X-KM-Api-Version": "v-0.2.0",
"Content-Type": "application/json",
}
});
const payment_verify_res = await response.data;
const paymentStatus = await payment_verify_res.status;
return {
props: {
StatusProps: payment_verify_res || null,
PaymentStatus: paymentStatus || null,
},
}
} catch (error) {
console.log(error);
return { props: {} }
}
}
【问题讨论】:
-
如果你在访问你提供的URL时登录
context.query.payment_ref_id,你会在终端看到什么? -
@juliomalves 未定义
-
其他查询参数
undefined也是吗?context.query返回什么? -
const { payment_ref_id } = context.query;解构解决了我的问题