16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/yunpian_sms/sender.rb', line 16
def self.template_batch_send template_id, mobile_nos, params
successful_count = 0
successful_people = []
failed_people = []
total_fee = 0.0
uri = URI("#{YunPianSMS.server}/v2/sms/tpl_batch_send.json")
details = mobile_nos.each_slice(MAX_RECIPIENT_NUMBER).map do |sliced_mobile_nos|
mobile = sliced_mobile_nos.join(',')
result = send_internal(uri, template_id, mobile, params)
successful_count += result.body['total_count']
total_fee += result.body['total_fee'].to_f
result.body['data'].each do |data|
mobile = data['mobile']
if data['code'] == 0
successful_people << mobile
else
failed_people << mobile
end
end
result
end
YunPianSMS::BatchResult.new(successful_count, successful_people, failed_people, total_fee, details)
end
|