![](/img/trans.png)
[英]How can I send verification code in email instead of sms using authy?
[英]How do I send a user token via SMS with Authy and PHP?
我正在尝试在PHP中为Authy运行一个演示。 我已经在Composer中安装了Authy库,因此现在我可以使用这样的硬编码值注册用户:
$authy_api = new Authy\AuthyApi('<TESTING API KEY>', 'http://sandbox-api.authy.com'); // actual key omitted -- using the key generated for testing, not the one for production
$user = $authy_api->registerUser('something@something.com', '999-999-9999', 30); // actual credentials omitted
if($user->ok()){
echo "Success!";
$id = $user->id();
echo($id);
}
当上面的脚本运行时,确实生成了一个5位数的用户ID,因此一切似乎都进行得很好,但是SMS从未发送到我的手机。
一个可能的问题是我的电话号码已经被注册为该应用程序电话(与管理员帐户相关联),因此由于(按文档)每个电话号码都必须唯一地标识一个用户,因此我的电话可能已经为此应用程序注册了,因此无需发送新令牌。 在这种情况下,用户对象的ID可以是先前注册的ID。
但是,其他电话号码仍然存在问题。 所以现在我迷路了。
事实证明,代码本身没有错。
只是Sandbox API实际上并没有通过发送SMS来完成。 它仅模拟用于测试目的的过程,因此身份验证流程与生产API相同。
当我切换到生产API URL和密钥时,可以在手机上接收SMS。
的Guybrush
两件事导致您缺少短信。
https://docs.authy.com/totp.html#requesting-sms-codes
但是,可以忽略此行为。
这样您的最终代码将是:
$authy_api = new Authy\AuthyApi('<TESTING API KEY>', 'http://sandbox-api.authy.com'); // actual key omitted -- using the key generated for testing, not the one for production
$user = $authy_api->registerUser('something@something.com', '999-999-9999', 30); // actual credentials omitted
if($user->ok()){
echo "Success!";
$id = $user->id();
echo($id);
// Now send SMS, force sending a message even if the user has the Authy mobile app installed
$sms = $authy_api->requestSms('authy-id', array("force" => "true")); }
西蒙
$authy_api = new AuthyApi(AUTHY_API_KEY, "https://api.authy.com");
$user = $authy_api->registerUser($email, $phone_number, $country_code); //// Register User
if($user->ok()) {
$sms = $authy_api->requestSms($user->id()); //// Send SMS
return $sms->ok();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.