Loading
識別使用者與管理存取
目錄
選取篩選

          沒有結果
          沒有結果
          以下是搜尋小祕訣

          檢查關鍵字的拼字。
          使用較常見的搜尋字詞。
          選取較少篩選條件以擴大您的搜尋。

          搜尋所有 Salesforce 說明
          範例:自訂一次性密碼傳送處理常式

          範例:自訂一次性密碼傳送處理常式

          在此範例中,自訂一次性密碼 (OTP) 傳送處理常式呼叫 Telesign 將自訂訊息傳送給外部 Salesforce 使用者。

          必要版本

          提供版本:Salesforce Classic (並非所有組織皆適用) 和 Lightning Experience
          提供版本:ProfessionalEnterpriseUnlimitedDeveloper Edition

          此程式碼範例僅供示範之用。在生產環境中實作之前,請務必先評估和測試任何程式碼。

          處理常式中的 sendOneTimePassword 方法會將 HTTP POST 要求傳送至 Telesign 的傳訊 API,https://rest-ww.telesign.com/v1/messaging。要求可包含這些支援的 Telesign 標題。

          Telesign 標題 描述
          Accept 指定 Salesforce 預期的回應格式。
          Content-Type 指定要求的格式。
          Authorization 透過包含 Telesign 客戶識別碼和 API 金鑰來驗證要求。客戶識別碼與 API 金鑰會以 customer ID:API key 格式彼此附加。產生的值為 Base64 編碼。

          要求內文包含這些支援的 Telesign 參數。請參閱 Telesign 文件網站上的 傳送 SMS 訊息

          Telesign 參數 描述
          is_primary 表示 Telesign 是主要提供者。
          phone_number 外部使用者的電話號碼。雖然電話號碼可能與使用者的帳戶相關聯,但不一定會驗證。
          message 要傳送給外部使用者的訊息內容。在此範例中,訊息包含一些文字,以介紹自訂 OTP、OTP 本身,以及 Salesforce SMS 提供者的預設文字。
          message_type 指定訊息包含 OTP。

          若成功,Telesign 會將 Salesforce OTP 傳送給外部使用者。處理常式會處理回應,並傳回表示要求是否成功的 Auth.CustomOneTimePasswordDeliveryResult

          global class TelesignMessaging implements Auth.CustomOneTimePasswordDeliveryHandler{
          
          global Auth.CustomOneTimePasswordDeliveryResult sendOneTimePassword(Id userId, String
          phoneNumber, String oneTimePassword, String defaultText, Id networkId, String experienceId)
          { //Send the message from Telesign
              HttpRequest request = new HttpRequest();
              //The commented-out code on the next line isn't necessary if you use named credentials
              //request.setEndpoint('https://rest-ww.telesign.com/v1/messaging');
              request.setEndpoint('callout:Telesign_SMS_Named');
              request.setMethod('POST');
              String requestBody = 'is_primary=true&phone_number=' + phoneNumber +
              '&message='+'Custom OTP%20'+ oneTimePassword+'; '+defaultText+'&message_type=OTP';
           
              request.setHeader('accept', 'application/json');
              request.setHeader('content-type', 'application/x-www-form-urlencoded');
              //The commented-out code on the next line isn't necessary if you use named credentials
              //request.setHeader('authorization', 'Basic <Base64-encoded Telesign customer ID:API key>');
              request.setBody(requestBody);
           
              HttpResponse response = new Http().send(request);
              // Handle the response as needed
              return Auth.CustomOneTimePasswordDeliveryResult.SUCCESS;
              }
          }
           
          正在載入
          Salesforce Help | Article