使用OTP调用API进行验证后,我需要从响应主体中获取用户ID值。
我已经解决了Promise后尝试调用.then()的问题,但是当从getid()函数之外的其他地方将其写入控制台时,uid是不确定的。
`
async function getid(){
var rp = require('request-promise-native');
const options = {
method: 'POST',
url: <API>,
json: true,
resolveWithFullResponse: true};
options.body = {otp = 1234};
const uid = await rp(options)
.then(function (response) {
return response.body.data.user._id;
}
);
return uid;
}
`
我希望我应该能够提取uid或任何其他响应主体参数的值,并在程序中的任何位置使用它。