You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在AWS Cognito中,更新邮箱后如何重新发送验证码?

解决方案:重发AWS Cognito邮箱更新后的验证验证码
  • 正确接口:使用GetUserAttributeVerificationCode接口,该接口专门用于重发用户属性更新后的验证验证码,完全匹配你的场景。
  • 无效原因说明:
    • ResendConfirmationCode仅服务于注册阶段的账号确认流程,和属性更新的验证流程属于独立的验证码体系,所以生成的验证码无法通过VerifyUserAttribute校验。
    • 重复调用updateUserAttributes设置相同邮箱时,Cognito会判定属性值无变更,不会触发新的验证邮件发送逻辑。
  • PHP代码示例(基于AWS SDK for PHP):
use Aws\CognitoIdentityProvider\CognitoIdentityProviderClient;

// 初始化Cognito客户端
$client = new CognitoIdentityProviderClient([
    'region' => '你的AWS区域',
    'version' => 'latest',
    'credentials' => [
        'key' => '你的AWS Access Key',
        'secret' => '你的AWS Secret Key',
    ],
]);

// 调用接口重发验证码
$result = $client->getUserAttributeVerificationCode([
    'Username' => '用户的用户名或ID',
    'UserPoolId' => '你的Cognito用户池ID',
    'AttributeName' => 'email', // 指定要重发验证的属性为邮箱
]);

// 可选:获取返回的会话值(用于后续关联操作)
$session = $result['Session'];

内容的提问来源于stack exchange,提问作者Emilien

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 01:24:50