qcloud-sms 0.0.1 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a63a18a1bfe4f2663c7df71bc36862fae902d7d82ed35bf1ab6c63097f564c0
4
- data.tar.gz: 970b7f153d245e45ed5c7a499150f69750009e41683a20013f748acf00cbad77
3
+ metadata.gz: dde5ab811276e2d579ee24f10021a547103962d90058bfd0cf46c5d66e00ec45
4
+ data.tar.gz: 45ba212e83bfa4074028bec9344f54590b5f66f82daa90adcee61806c272afec
5
5
  SHA512:
6
- metadata.gz: 20d09cd7959f8b390fdfffd521f3bf20330d63ee21ad594f9324078ed6ad0dc6cc1b061690ea4b7dd3b6bcfa046f160f5fe8938cca033e9472a3e255aa156bd5
7
- data.tar.gz: 55b789aebbf6b57f0c3ec213ce746a5f1835c456754e285fbf50970119121594e93fb16536539bb2e1eb2eaa4d4007e26a8090af60a0da3a73f8d36799150b30
6
+ metadata.gz: 955f35dd2448f0e953fe6ebc6d2d3e9e1736ad3073a86586b6688edebf25434babfc214aebaf8e485c3037b050b6d3cc1ace3b91d60f5b01ec2e58b44c82bf40
7
+ data.tar.gz: 7fd900fae64574fe7b94114f90c2ab31fa7ae47bd68fca8b1952b646ed89bc94c0988796158307cb276ca6ae0e6152645ee35f6983d43774ff5a4695b7a42003
@@ -1,6 +1,8 @@
1
1
  require "qcloud/sms/version"
2
+ require 'securerandom'
2
3
  require 'digest'
3
- require 'typhoeus/adapters/faraday'
4
+ require 'typhoeus'
5
+ require 'json'
4
6
 
5
7
  module Qcloud
6
8
  module Sms
@@ -24,40 +26,45 @@ module Qcloud
24
26
  yield(configuration)
25
27
  end
26
28
 
27
- def sms_single_sender(mobile, templId, params)
29
+ def create_params(mobile, templId, params, random_number)
30
+ sms_params = {
31
+ "ext" => "",
32
+ "extend" => "",
33
+ "params" => params,
34
+ "sig" => sig(mobile, random_number),
35
+ "sign" => configuration.sign,
36
+ "tel" => {
37
+ "mobile" => mobile,
38
+ "nationcode" => "86"
39
+ },
40
+ "time" => timestamp,
41
+ "tpl_id" => templId
42
+ }
43
+ sms_params.to_json
44
+ end
45
+
46
+ def single_sender(mobile, templId, params)
28
47
  random_number = random
29
48
  Typhoeus.post("https://yun.tim.qq.com/v5/tlssmssvr/sendsms?sdkappid=" + configuration.app_id + "&random=" + random_number,
30
- headers: {"Content-Type"=> "application/json"},
31
- body: {
32
- params: params,
33
- sig: sig(mobile, random_number),
34
- sign: configuration.sign,
35
- tel: {
36
- mobile: mobile,
37
- nationcode: "86"
38
- },
39
- time: timestamp,
40
- tpl_id: templId,
41
- extend: "",
42
- ext: ""
43
- }
49
+ headers: { "Content-Type": "application/json" },
50
+ body: create_params(mobile, templId, params, random_number)
44
51
  )
45
52
  end
46
53
 
47
54
  # 生成数字签名
48
55
  def sig(mobile, random_number)
49
- signature = "appkey=" + configuration.app_key + "&random=" + random_number + "&time=" + timestamp + "&mobile=" + mobile
56
+ signature = "appkey=" + configuration.app_key + "&random=" + random_number + "&time=" + timestamp.to_s + "&mobile=" + mobile
50
57
  Digest::SHA256.hexdigest signature
51
58
  end
52
59
 
53
60
  # 生成随机数
54
61
  def random
55
- SecureRandom.random_number.to_s.slice(-6..-1)
62
+ SecureRandom.random_number.to_s.slice(-10..-1)
56
63
  end
57
64
 
58
65
  # 生成短信时间戳
59
66
  def timestamp
60
- Time.now.to_i.to_s
67
+ Time.now.to_i
61
68
  end
62
69
 
63
70
  end
@@ -1,5 +1,5 @@
1
1
  module Qcloud
2
2
  module Sms
3
- VERSION = "0.0.1"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
@@ -34,5 +34,4 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency "rake", "~> 10.0"
35
35
  spec.add_development_dependency "rspec", "~> 3.0"
36
36
  spec.add_dependency "typhoeus"
37
- spec.add_dependency "faraday"
38
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qcloud-sms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OHIMY中国
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-08 00:00:00.000000000 Z
11
+ date: 2018-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: faraday
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  description: A Ruby Gem for using qcloud sms service.
84
70
  email:
85
71
  - im@ohimy.com