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

如何在自定义策略中将“发送验证码”与“验证验证码”拆分为独立编排步骤?

如何在自定义策略中将“发送验证码”与“验证验证码”拆分为独立编排步骤?

没问题,我之前也碰到过一模一样的需求,把发送验证码和验证拆成两个独立的页面步骤完全是可行的,下面我给你捋清楚具体怎么实现:

首先得明确核心思路:把原本合并在一个步骤里的“发码+验码”逻辑,拆成两个独立的自断言编排步骤,分别对应“发送验证码页面”和“验证码验证页面”,让用户先完成发码操作,再进入验码环节。

具体实现步骤:

  1. 定义两个独立的自断言技术配置(Technical Profile)

    • 第一个技术配置专门负责「发送验证码」:只保留生成并发送验证码的逻辑,不需要用户输入任何内容,页面上只放一个“发送验证码”按钮就行。
    • 第二个技术配置专门负责「验证验证码」:只提供验证码输入框和“验证”按钮,逻辑上只校验用户输入的验证码是否有效。
  2. 修改用户旅程(User Journey),添加两个编排步骤
    在你的用户旅程里,按顺序加入这两个步骤,确保用户必须先完成发码步骤,才能进入验码步骤。举个简单的配置片段:

    <UserJourney Id="SplitVerificationFlow">
      <OrchestrationSteps>
        <!-- 这里可以保留你原有的前置步骤,比如用户识别、获取邮箱等 -->
        <OrchestrationStep Order="1" Type="ClaimsExchange">
          <ClaimsExchanges>
            <ClaimsExchange Id="SendVerificationCodeStep" TechnicalProfileReferenceId="SendVerificationCodeTechProfile"/>
          </ClaimsExchanges>
        </OrchestrationStep>
        <OrchestrationStep Order="2" Type="ClaimsExchange">
          <ClaimsExchanges>
            <ClaimsExchange Id="VerifyCodeStep" TechnicalProfileReferenceId="VerifyCodeTechProfile"/>
          </ClaimsExchanges>
        </OrchestrationStep>
        <!-- 后续的流程步骤,比如创建用户、颁发令牌等 -->
      </OrchestrationSteps>
    </UserJourney>
    
  3. 编写两个技术配置的具体内容

    • 发送验证码的技术配置示例:
      <TechnicalProfile Id="SendVerificationCodeTechProfile">
        <DisplayName>发送验证码</DisplayName>
        <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.SelfAssertedAttributeProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
        <Metadata>
          <Item Key="ContentDefinitionReferenceId">api.selfasserted.sendcode</Item>
          <Item Key="IncludeClaimResolvingInClaimsHandling">true</Item>
        </Metadata>
        <InputClaims>
          <!-- 传入用户的邮箱,用来发送验证码 -->
          <InputClaim ClaimTypeReferenceId="email" />
        </InputClaims>
        <ValidationTechnicalProfiles>
          <!-- 调用内置的发送验证码逻辑,比如AAD的Sspr发送接口 -->
          <ValidationTechnicalProfile ReferenceId="AadSspr-SendCode"/>
        </ValidationTechnicalProfiles>
      </TechnicalProfile>
      
    • 验证验证码的技术配置示例:
      <TechnicalProfile Id="VerifyCodeTechProfile">
        <DisplayName>验证验证码</DisplayName>
        <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.SelfAssertedAttributeProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
        <Metadata>
          <Item Key="ContentDefinitionReferenceId">api.selfasserted.verifycode</Item>
          <Item Key="IncludeClaimResolvingInClaimsHandling">true</Item>
        </Metadata>
        <InputClaims>
          <InputClaim ClaimTypeReferenceId="email" />
          <!-- 让用户输入验证码 -->
          <InputClaim ClaimTypeReferenceId="verificationCode" Required="true"/>
        </InputClaims>
        <ValidationTechnicalProfiles>
          <!-- 调用内置的验证码验证逻辑 -->
          <ValidationTechnicalProfile ReferenceId="AadSspr-VerifyCode"/>
        </ValidationTechnicalProfiles>
      </TechnicalProfile>
      
  4. 自定义页面UI(可选但推荐)
    你可以自定义自断言页面的HTML模板,让发送页面只显示“发送验证码”按钮和提示信息,验证页面只显示输入框和验证按钮,提升用户体验。

几个需要注意的点:

  • 确保用户的邮箱(或其他接收验证码的标识)在两个步骤之间能正确传递,一般通过声明(Claim)存在会话里就行。
  • 处理验证码过期的情况:如果用户输入过期的验证码,要引导他们回到发送页面重新获取。
  • 测试时要注意流程的连贯性,确保用户在发送验证码后能顺利跳转到验证页面,没有卡顿或错误。

备注:内容来源于stack exchange,提问作者Zesa Rex

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.23 09:22:36