Commit 7ee70070 authored by Andi Saurer's avatar Andi Saurer

use ssl by default

parent d60ffad2
2.1.1@short_message
2.1.3@short_message
......@@ -3,24 +3,28 @@ require "net/http"
module ShortMessage
class Message < ActiveRecord::Base
attr_accessible :message_key, :recipient, :sender, :status_code, :text
def status_text
I18n.t("short_message.status.code_#{self.status_code}")
end
def deliver
self.sender = ShortMessage.config.default_sms_sender if self.sender.blank?
unless self.recipient.blank? and self.text.blank?
http = Net::HTTP.new(ShortMessage.config.gateway_server, ShortMessage.config.gateway_port)
if ShortMessage.config.gateway_port == Net::HTTP.https_default_port()
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
response, data = http.post(ShortMessage.config.send_file_path, build_deliver_params_string)
if response.code == "200"
# returns something like 0:200: OK (<mobilenumber>:<msgid>)
result_set = response.body.gsub("(","").gsub(")","").split(":")
self.status_code = result_set[0].to_i
self.message_key = result_set[3] unless result_set[3].blank?
if self.status_code == 3 and ShortMessage.config.default_reload_amount > 0
if self.recharge
self.deliver
......@@ -29,7 +33,7 @@ module ShortMessage
return false
end
end
self.save
true
else
......@@ -37,16 +41,16 @@ module ShortMessage
end
end
end
def recharge amount = ShortMessage.config.default_reload_amount
unless ShortMessage.config.account_functions_path.blank?
http = Net::HTTP.new(ShortMessage.config.gateway_server)
response, body = http.post(ShortMessage.config.account_functions_path, build_recharge_params_string(amount))
if response.code == "200"
# returns something like 0:Successful
result_set = response.body.split(":")
if result_set[0].to_i == 0
logger.info "SMS account successfully charged with #{amount} sms."
Mailer.recharge_notification(amount).deliver unless ShortMessage.config.reload_notification_email.blank?
......@@ -62,7 +66,7 @@ module ShortMessage
end
end
end
private
def build_deliver_params_string
params = []
......@@ -75,7 +79,7 @@ module ShortMessage
params << "utf-8=1"
params.join("&")
end
def build_recharge_params_string amount
params = []
params << "UserIDFS=#{ShortMessage.config.user_id}"
......
ShortMessage.configure do |config|
config.gateway_server = "www1.q-x.ch"
config.gateway_port = 80
config.gateway_port = 443
config.send_file_path = "/app/sms/gw1/cust/send.php"
config.account_functions_path = "/app/sms/gw1/cust/accfunc.php"
config.account_functions_path = "/app/sms/gw1/cust/accfunc.php"
# enter your details received from provider here
config.user_id = ""
config.ccu_id = ""
config.id_string = ""
config.default_reload_amount = 1000
config.default_mail_sender = "webmaster@your-domain.com"
config.reload_notification_email = "webmaster@your-domain.com"
config.voucher_notification_email = "give-me-money@your-domain.com" # set nil to disable voucher mailing
# set a default sms sender (used if no sender is present)
# config.default_sms_sender = ""
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment