![](/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.