使用的是螺丝帽的sms功能,网址为https://sms-my.luosimao.com/signature/index
使用前提是:注册登录之后,需要进行签名管理,签名管理的前提是进行个人的身份证验证
具体的示例ruby代码如下所示
module SendSMS
class << self
MESSAGE_SUFFIX = "【简历网】"
SMS_API_KEY = Rails.application.credentials.dig(:sms_api_key)
SMS_SEND_URL = "https://sms-api.luosimao.com/v1/send.json"
SMS_STATUS_URL = "https://sms-api.luosimao.com/v1/status.json"
#
# SendSMS.send "13718781273", "hello"
# SendSMS.status
#
def send mobile, message
options = {
mobile: mobile,
message: "#{message}#{MESSAGE_SUFFIX}"
}
begin
response = RestClient.post SMS_SEND_URL, options, headers
response = JSON.parse(response)
Rails.logger.info "SMS: mobile #{mobile}, options: #{options}, response: #{response}"
rescue => e
response = e.message
end
unless response.try(:fetch, "error") == 0
Rails.logger.info "SMS failed: mobile #{mobile}, options: #{options}, response: #{response}"
end
response
end
def status
begin
response = RestClient.get SMS_STATUS_URL, headers
response = JSON.parse(response)
Rails.logger.info "SMS: status #{response}"
rescue => e
response = e.message
end
response
end
private
def headers
{ Authorization: "Basic " + Base64.encode64("api:key-#{SMS_API_KEY}").chomp }
end
end
end