AliyunSms

Build Status Hex.pm

Aliyun SMS API(阿里云短信服务 API)

Installation

If available in Hex, the package can be installed by adding aliyun_sms to your list of dependencies in mix.exs:

def deps do
  [
    {:aliyun_sms, "~> 0.2.7"}
  ]
end

Configuration

config :aliyun_sms,
  access_key_id: "ALIYUN_ACCESS_KEY_ID",
  access_key_secret: "ALIYUN_ACCESS_KEY_SECRET"

Or if you want to config them via run-time system environment variables:

config :aliyun_oss,
  access_key_id: {:system, "ALIYUN_ACCESS_KEY_ID"},
  access_key_secret: {:system, "ALIYUN_ACCESS_KEY_SECRET"}

Quickstart

Aliyun.Sms.send_sms("1500000000", "阿里云短信测试专用", "SMS_0000", %{code: "222333"})
# {:ok, %{"Code" => "OK", "Message" => "OK", "BizId" => "700000000000000000^0", "RequestId" => "A0000000-3CC1-4000-8000-E00000000000"}}

Aliyun.Sms.send_sms("1500000000", "invalid_sig", "SMS_0000", %{code: "222333"})
# {:error, "isv.SMS_SIGNATURE_ILLEGAL", %{"Code" => "isv.SMS_SIGNATURE_ILLEGAL", "Message" => "短信签名不合法"}}

Aliyun.Sms.send_sms("1500000000", "阿里云短信测试专用", "SMS_0000", %{code: "222333"})
# {:error, :http_error, "REASON"}

Aliyun.Sms.send_sms("1500000000", "阿里云短信测试专用", "SMS_0000", %{code: "222333"})
# {:error, :json_decode_error, "BODY"}

Documentation

AliyunDescriptionThis package
SendSMS发送短信。Aliyun.Sms.send_sms/6
SendBatchSms批量发送短信。[TODO]
QuerySendDetails查询短信发送的状态。[TODO]