Unimatrix Python SDK
インストール
Python向けUnimatrix SDKは PyPI から pip で導入する方法を推奨します。
pip install uni-sdk
利用方法
クライアントの初期化
from uni.client import UniClient
client = UniClient("your access key id", "your access key secret") # Simple Mode の場合は第1引数のみ
環境変数の利用も可能です。
export UNIMTX_ACCESS_KEY_ID=your_access_key_id
export UNIMTX_ACCESS_KEY_SECRET=your_access_key_secret
SMSの送信
from uni.client import UniClient
from uni.exception import UniException
client = UniClient()
try:
res = client.messages.send({
"to": "+1206880xxxx", # E.164形式
"text": "Your verification code is 2048."
})
print(res.data)
except UniException as e:
print(e)
テンプレートを使用する例:
client.messages.send({
"to": "+1650253xxxx",
"signature": "Unimatrix",
"templateId": "pub_verif_en_basic2",
"templateData": {
"code": "2048"
}
})
認証コード(OTP)の送信
from uni.client import UniClient
from uni.exception import UniException
client = UniClient()
res = client.otp.send({
"to": "+1206880xxxx"
})
print(res.data)
認証コード(OTP)の検証
from uni.client import UniClient
from uni.exception import UniException
client = UniClient()
res = client.otp.verify({
"to": "+1206880xxxx",
"code": "123456" # ユーザーが入力した認証コード
})
print(res.valid)