メインコンテンツにスキップ

独自 HTTP API 経由での SMS 送信

このガイドでは、組み込みタイプのない SMS ゲートウェイを介して Casdoor の認証コードを送信する方法について説明します。Casdoor はあなたが記述した HTTP エンドポイントを呼び出すため、通常の HTTP リクエストを受け入れる任意の SMS API が機能します。


学習目標​

  • SMS ゲートウェイの HTTP リクエストを Casdoor で記述する。
  • Casdoor がリクエストを構築する方法を理解する。

必要なもの​

  • HTTP API を持つ SMS ゲートウェイ
  • Casdoor 管理コンソールへの管理者アクセス権

Casdoorにプロバイダーを追加する​

  1. Casdoor管理コンソールで、Identity > Providers に移動し、プロバイダーを追加します。

  2. Category を SMS に、Type を Custom HTTP SMS に設定します。

  3. フィールドに入力します:

    Casdoor fieldMeaning必須
    テンプレートコードMessage template. The verification code replaces the %s placeholder (e.g. Your code is %s). If left empty, the raw code is sent.いいえ
    エンドポイントThe SMS API URL. Supports the {mobile} and {code} placeholders, which are replaced with the phone number and code.はい
    メソッドHTTP method: GET, POST, PUT, or DELETE.はい
    コンテンツタイプRequest body encoding for non-GET methods: application/x-www-form-urlencoded (default) or application/json.いいえ
    HTTPヘッダーExtra request headers (e.g. an Authorization header for your API key).いいえ
    HTTPボディマッピングField names used in the request for phoneNumber and content (non-GET methods).いいえ
    パラメータThe field name that carries the message content. Takes precedence over the content value in HTTP body mapping.いいえ
    プロキシを有効にするSend the request through the SOCKS5 proxy configured in Casdoor. See overview.いいえ
  4. プロバイダーを保存します。

Casdoorがリクエストを構築する方法​

  • Content: メッセージは、Template code の %s が認証コードに置き換えられたものになります。Template code が空の場合、Casdoorは認証コードのみを送信します。
  • Field names: 電話番号は phoneNumber フィールドに入り、コンテンツは Parameter で指定されたフィールドに入ります。両方の名前は HTTP body mapping で変更できます。Parameter が設定されている場合、content のマッピングよりも優先されます。
  • POST, PUT, DELETE: Casdoorは、選択した Content type で、ボディ内に電話番号とコンテンツを送信します。
  • GET: Casdoorは、クエリパラメータとして電話番号とコンテンツを追加します。Endpoint にプレースホルダー {mobile} または {code} が含まれている場合、Casdoorはプレースホルダーに値を設定し、クエリパラメータを追加しません。

例​

to と text フィールドを含む POST フォームを受け入れるゲートウェイ:

FieldValue
Endpointhttps://sms.example.com/api/send
MethodPOST
Content typeapplication/x-www-form-urlencoded
HTTP headerAuthorization: Bearer <your-token>
HTTP body mappingphoneNumber to to
Parametertext
Template codeYour verification code is %s

GET でURL内のすべての情報を使用するゲートウェイ:

FieldValue
Endpointhttps://sms.example.com/send?mobile={mobile}&code={code}
MethodGET

結果を検証する​

SMS Test に電話番号を入力し、テストメッセージを送信します。

関連項目​