问题描述
console.log("Otp.js>13 mounted");
if ('OTPCredential' in window) {
try {
console.log("Otp.js>16 in otpcredential");
if (navigator.credentials) {
try {
console.log("Otp.js>19 credential");
let {type,code} = await navigator.credentials.get({ otp:{ transport: ['sms']}})
console.log("EsignSteps.js>78 aaaayo",type,code);
}
catch (e) {
console.log("EsignSteps.js>81",e);
}
}
}
catch (err) {
console.log("40",err);
}
}
即使我收到 OTP 几分钟后,上面的代码也会给出 DOMException
我也试过
const abort = new AbortController();
setTimeout(() => {
abort.abort();
},2 * 60 * 1000);
let {type,code} = await navigator.credentials.get({ signal: abort.signal,otp:{ transport: ['sms']}})
也试过了
navigator.credentials.get({ signal: abort.signal,otp:{ transport: ['sms']}})
.then((otp)=>{
console.log(otp);
})
.catch(err=>{
console.log(err);
})
我尝试了很多短信格式,例如:
格式 1:
Your OTP is : 123456
@https://example.com #123456
格式 2:
Your OTP is : 123456
@example.com #123456
格式 3:
Your OTP is : 123456
@www.example.com #123456
我已经了解了最小的细节 https://web.dev/web-otp/
我尝试了一些演示,例如 https://web-otp.glitch.me/、https://jyotishman.github.io/webOTPAPI/ 哪些不起作用
解决方法
我找到了解决方案。我正在从我朋友的手机号码发送短信,该手机号码保存在我的联系人列表中。 如果发送者的电话号码包含在接收者的联系人列表中,由于底层 SMS User Consent API! 的设计,不会触发此 API。