独自 HTTP API 経由での SMS 送信
このガイドでは、組み込みタイプのない SMS ゲートウェイを介して Casdoor の認証コードを送信する方法について説明します。Casdoor はあなたが記述した HTTP エンドポイントを呼び出すため、通常の HTTP リクエストを受け入れる任意の SMS API が機能します。
学習目標
- SMS ゲートウェイの HTTP リクエストを Casdoor で記述する。
- Casdoor がリクエストを構築する方法を理解する。
必要なもの
- HTTP API を持つ SMS ゲートウェイ
- Casdoor 管理コンソールへの管理者アクセス権
Casdoorにプロバイダーを追加する
-
Casdoor管理コンソールで、Identity > Providers に移動し、プロバイダーを追加します。
-
Category を
SMSに、Type をCustom HTTP SMSに設定します。 -
フィールドに入力します:
Casdoor field Meaning 必須 テンプレートコード Message template. The verification code replaces the %splaceholder (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, orDELETE.はい コンテンツタイプ Request body encoding for non- GETmethods:application/x-www-form-urlencoded(default) orapplication/json.いいえ HTTPヘッダー Extra request headers (e.g. an Authorizationheader for your API key).いいえ HTTPボディマッピング Field names used in the request for phoneNumberandcontent(non-GETmethods).いいえ パラメータ The field name that carries the message content. Takes precedence over the contentvalue in HTTP body mapping.いいえ プロキシを有効にする Send the request through the SOCKS5 proxy configured in Casdoor. See overview. いいえ -
プロバイダーを保存します。
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 フォームを受け入れるゲートウェイ:
| Field | Value |
|---|---|
| Endpoint | https://sms.example.com/api/send |
| Method | POST |
| Content type | application/x-www-form-urlencoded |
| HTTP header | Authorization: Bearer <your-token> |
| HTTP body mapping | phoneNumber to to |
| Parameter | text |
| Template code | Your verification code is %s |
GET でURL内のすべての情報を使用するゲートウェイ:
| Field | Value |
|---|---|
| Endpoint | https://sms.example.com/send?mobile={mobile}&code={code} |
| Method | GET |
結果を検証する
SMS Test に電話番号を入力し、テストメッセージを送信します。