Pythonを使用したOTP
PythonでOTPトークン(ワンタイムパスワード)を生成します
Python : APIドキュメント
Pythonを使用したOTP
import urllib2
afilnet_class="otp"
afilnet_method="generateotp"
afilnet_user="user"
afilnet_password="password"
afilnet_type="number"
afilnet_destination="34600000000"
afilnet_time="1"
afilnet_timetype="days"
afilnet_length="6"
afilnet_otpformat="all"
afilnet_output=""
# Create an URL request
sUrl = "https://www.afilnet.com/api/http/?class="+afilnet_class+"&method="+afilnet_method+"&user="+afilnet_user+"&password="+afilnet_password+"&type="+afilnet_type+"&destination="+afilnet_destination+"&time="+afilnet_time+"&timetype="+afilnet_timetype+"&length="+afilnet_length+"&otpformat="+afilnet_otpformat+"&output="+afilnet_output
result = urllib2.urlopen(sUrl).read()
from urllib.request import urlopen
from urllib.parse import urlencode
afilnet_class="otp"
afilnet_method="generateotp"
afilnet_user="user"
afilnet_password="password"
afilnet_type="number"
afilnet_destination="34600000000"
afilnet_time="1"
afilnet_timetype="days"
afilnet_length="6"
afilnet_otpformat="all"
afilnet_output=""
# Create an URL request
sUrl = "https://www.afilnet.com/api/http/"
data = urlencode({"class": afilnet_class,"method": afilnet_method,"user": afilnet_user,"password": afilnet_password,"type": afilnet_type,"destination": afilnet_destination,"time": afilnet_time,"timetype": afilnet_timetype,"length": afilnet_length,"otpformat": afilnet_otpformat,"output": afilnet_output}).encode("utf-8")
result = urlopen(sUrl, data).read()
print(result)
import requests
afilnet_class="otp"
afilnet_method="generateotp"
afilnet_user="user"
afilnet_password="password"
afilnet_type="number"
afilnet_destination="34600000000"
afilnet_time="1"
afilnet_timetype="days"
afilnet_length="6"
afilnet_otpformat="all"
afilnet_output=""
# Create an URL request
sUrl = "https://www.afilnet.com/api/basic/?class="+afilnet_class+"&method="+afilnet_method+"&type="+afilnet_type+"&destination="+afilnet_destination+"&time="+afilnet_time+"&timetype="+afilnet_timetype+"&length="+afilnet_length+"&otpformat="+afilnet_otpformat+"&output="+afilnet_output
result = requests.get(sUrl,auth=requests.auth.HTTPBasicAuth(afilnet_user,afilnet_password))
print(result.text)
パラメータ | 説明 | 必須/オプション |
---|---|---|
class=otp | 要求されたクラス:要求が行われるクラス | 強制的 |
method=generateotp | 要求されたクラスメソッド:要求が行われるクラスのメソッド | 強制的 |
user | Afilnetアカウントのユーザーと電子メール | 強制的 |
password | Afilnetアカウントのパスワード | 強制的 |
type | グループのタイプ(電子メールまたはモバイル) | 強制的 |
destination | 携帯電話番号または宛先メール | 強制的 |
time | 日数、週数、月数、または年数 | オプショナル |
timetype | 時間のタイプ(可能な値:日、週、月、または年) | オプショナル |
length | 生成するパスワードの長さ | オプショナル |
otpformat | 生成するパスワードの形式(すべての文字、数字のみ、または文字のみ(すべて、数字、文字)が含まれる場合) | オプショナル |
output | 結果の出力形式 | オプショナル |
リクエストを行うと、次のフィールドが表示されます。
- status
-
結果(ステータス=成功の場合)、ここで次の値を受け取ります。
- 追加の値は送信されません
- エラー(ステータス=エラーの場合)、ここでエラーコードを受け取ります
考えられるエラーコードは以下のとおりです。
コード | 説明 |
---|---|
MISSING_USER | ユーザーまたはメールは含まれていません |
MISSING_PASSWORD | パスワードは含まれていません |
MISSING_CLASS | 含まれていないクラス |
MISSING_METHOD | 含まれていないメソッド |
MISSING_COMPULSORY_PARAM | 必須パラメーターは含まれていません |
INCORRECT_USER_PASSWORD | 間違ったユーザーまたはパスワード |
INCORRECT_CLASS | 間違ったクラス |
INCORRECT_METHOD | 間違った方法 |
INCORRECT_TIME_TYPE | 誤ったタイプの時間(可能な値:日、週、月、または年) |
INCORRECT_TYPE | タイプが正しくありません。タイプはモバイルまたはメールである必要があります |
INCORRECT_FORMAT | ERROR_INCORRECT_FORMAT |
INCORRECT_OTP_FORMAT | ERROR_INCORRECT_OTP_FORMAT |
パラメーター:
- class : otp
- method : generateotp
- user : user
- password : password
- type : number
- destination : 34600000000
- time : 1
- timetype : days
- length : 6
- otpformat : all
- output :
要求:
https://www.afilnet.com/api/http/?class=otp&method=generateotp&user=user&password=password&type=number&destination=34600000000&time=1&timetype=days&length=6&otpformat=all&output=