alidayu_api 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +120 -0
- data/Rakefile +2 -0
- data/alidayu_api.gemspec +24 -0
- data/lib/alidayu.rb +27 -0
- data/lib/alidayu/configuration.rb +40 -0
- data/lib/alidayu/helper.rb +46 -0
- data/lib/alidayu/sms.rb +39 -0
- data/lib/alidayu/tts.rb +20 -0
- data/lib/alidayu/version.rb +3 -0
- data/lib/alidayu/voice.rb +30 -0
- data/spec/sms_spec.rb +28 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/tts_spec.rb +20 -0
- data/spec/voice_spec.rb +0 -0
- metadata +108 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: cab21f1519c50334d49a4995425f90cc127cfc48
         | 
| 4 | 
            +
              data.tar.gz: d37fb855fd7ff8317679c407620c285ce0489a70
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 1c34f525fe9966fce35b2ceb7047bc69619ef017c862ad1ab3bde7271fb2215fddd209cafd81d7ca5cbf291d95f0a000665c3ce5ec55ecdb575ea45dbfdbc102
         | 
| 7 | 
            +
              data.tar.gz: 27b4aad7118c9ccfb846d9c5b9e6ccf040775ea64f9f30bf1c86698fd54377f03c26e02e568dcf3f3bf306b4e79a526beaf7c02336c32a31b8f7b027f4a24e2f
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            Copyright (c) 2016 402399938
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            MIT License
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 6 | 
            +
            a copy of this software and associated documentation files (the
         | 
| 7 | 
            +
            "Software"), to deal in the Software without restriction, including
         | 
| 8 | 
            +
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 9 | 
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 10 | 
            +
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 11 | 
            +
            the following conditions:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            The above copyright notice and this permission notice shall be
         | 
| 14 | 
            +
            included in all copies or substantial portions of the Software.
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         | 
| 17 | 
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 18 | 
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         | 
| 19 | 
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         | 
| 20 | 
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         | 
| 21 | 
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         | 
| 22 | 
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,120 @@ | |
| 1 | 
            +
            # AlidayuApi
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            alidayu api for ruby
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            阿里大鱼相关API调用,可调用
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            1. 短信发送 `alibaba.aliqin.fc.sms.num.send`  
         | 
| 8 | 
            +
            2. 短信发送记录查询 `alibaba.aliqin.fc.sms.num.query`
         | 
| 9 | 
            +
            3. 文本转语音通知 `alibaba.aliqin.fc.tts.num.singlecall`
         | 
| 10 | 
            +
            4. 语音通知 `alibaba.aliqin.fc.voice.num.singlecall`
         | 
| 11 | 
            +
            5. 语音双呼 `alibaba.aliqin.fc.voice.num.doublecall`
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ## 安装
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            添加下面的代码到Gemfile中:
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            ```ruby
         | 
| 18 | 
            +
            gem 'alidayu_api'
         | 
| 19 | 
            +
            ```
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            然后执行:
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                $ bundle install
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            或者执行下面的代码:
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                $ gem install alidayu_api
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            ## 使用
         | 
| 30 | 
            +
            ### 配置
         | 
| 31 | 
            +
            创建脚本`config/initializers/alidayu.rb`填入以下代码
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            ```ruby
         | 
| 34 | 
            +
            Alidayu.setup do |config|
         | 
| 35 | 
            +
              config.server     = 'http://gw.api.taobao.com/router/rest'
         | 
| 36 | 
            +
              config.app_key    = ''
         | 
| 37 | 
            +
              config.app_secret = ''
         | 
| 38 | 
            +
              config.sign_name  = '注册验证'
         | 
| 39 | 
            +
            end
         | 
| 40 | 
            +
            ```
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            短信发送模板请自行根据需求定义
         | 
| 43 | 
            +
            	
         | 
| 44 | 
            +
            ### 短信发送
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            ```ruby
         | 
| 47 | 
            +
            options = {
         | 
| 48 | 
            +
              mobiles: '13681695220',
         | 
| 49 | 
            +
              template_code: 'SMS_5410467',
         | 
| 50 | 
            +
              params: {
         | 
| 51 | 
            +
               code: '45678',
         | 
| 52 | 
            +
               product: '就诊通'
         | 
| 53 | 
            +
              }
         | 
| 54 | 
            +
            }
         | 
| 55 | 
            +
            # params为模板内容的变量集合,根据模板中定义变量的不同而不同,若模板中未定义变量可不传
         | 
| 56 | 
            +
             | 
| 57 | 
            +
            Alidayu::Sms.send(options)
         | 
| 58 | 
            +
            ```
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            ### 短信发送记录查询
         | 
| 61 | 
            +
             | 
| 62 | 
            +
            ```ruby
         | 
| 63 | 
            +
            options = {
         | 
| 64 | 
            +
              mobile: '13681695220',
         | 
| 65 | 
            +
              query_date: 'yyyyMMdd',
         | 
| 66 | 
            +
              current_page: 1, # 页码
         | 
| 67 | 
            +
              page_size: 10 # 每页数量,最大50
         | 
| 68 | 
            +
            }
         | 
| 69 | 
            +
             | 
| 70 | 
            +
            Alidayu::Sms.query(options)
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            ```
         | 
| 73 | 
            +
             | 
| 74 | 
            +
            ### 文本转语音通知
         | 
| 75 | 
            +
             | 
| 76 | 
            +
            ```ruby
         | 
| 77 | 
            +
            options = {
         | 
| 78 | 
            +
              called_num: '',
         | 
| 79 | 
            +
              called_show_num: '',
         | 
| 80 | 
            +
              template_code: '', # 文本转语音(TTS)模板ID
         | 
| 81 | 
            +
              params: {  } # TTS模板变量,同短信发送的params
         | 
| 82 | 
            +
            }
         | 
| 83 | 
            +
             | 
| 84 | 
            +
            Alidayu::Tts.single_call(options)
         | 
| 85 | 
            +
            ```
         | 
| 86 | 
            +
             | 
| 87 | 
            +
            ### 语音通知
         | 
| 88 | 
            +
             | 
| 89 | 
            +
            ```ruby
         | 
| 90 | 
            +
            options = {
         | 
| 91 | 
            +
              called_num: '',
         | 
| 92 | 
            +
              called_show_num: '',
         | 
| 93 | 
            +
              voice_code: '' # 语音文件ID
         | 
| 94 | 
            +
            }
         | 
| 95 | 
            +
             | 
| 96 | 
            +
            Alidayu::Voice.single_call(options)
         | 
| 97 | 
            +
            ```
         | 
| 98 | 
            +
             | 
| 99 | 
            +
            ### 语音双呼
         | 
| 100 | 
            +
             | 
| 101 | 
            +
            ```ruby
         | 
| 102 | 
            +
            options = {
         | 
| 103 | 
            +
              caller_num: '',
         | 
| 104 | 
            +
              caller_show_num: '',
         | 
| 105 | 
            +
              called_num: '',
         | 
| 106 | 
            +
              called_show_num: '',
         | 
| 107 | 
            +
              time_out: '' # 通话超时时长,如接通后到达120秒时,通话会因为超时自动挂断。若无需设置超时时长,可不传
         | 
| 108 | 
            +
            }
         | 
| 109 | 
            +
             | 
| 110 | 
            +
            Alidayu::Voice.double_call(options)
         | 
| 111 | 
            +
            ```
         | 
| 112 | 
            +
             | 
| 113 | 
            +
             | 
| 114 | 
            +
            ## Contributing
         | 
| 115 | 
            +
             | 
| 116 | 
            +
            1. Fork it ( https://github.com/[my-github-username]/alidayu_api/fork )
         | 
| 117 | 
            +
            2. Create your feature branch (`git checkout -b my-new-feature`)
         | 
| 118 | 
            +
            3. Commit your changes (`git commit -am 'Add some feature'`)
         | 
| 119 | 
            +
            4. Push to the branch (`git push origin my-new-feature`)
         | 
| 120 | 
            +
            5. Create a new Pull Request
         | 
    
        data/Rakefile
    ADDED
    
    
    
        data/alidayu_api.gemspec
    ADDED
    
    | @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require 'alidayu/version'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "alidayu_api"
         | 
| 8 | 
            +
              spec.version       = Alidayu::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["wangrui"]
         | 
| 10 | 
            +
              spec.email         = ["to_wangrui@163.com"]
         | 
| 11 | 
            +
              spec.summary       = %q{阿里大鱼API}
         | 
| 12 | 
            +
              spec.description   = %q{阿里大鱼短信发送,语音双呼,文本转语音通知等API的调用}
         | 
| 13 | 
            +
              spec.homepage      = "https://github.com/wangrui438/alidayu_api"
         | 
| 14 | 
            +
              spec.license       = "MIT"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              spec.files         = `git ls-files -z`.split("\x0")
         | 
| 17 | 
            +
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         | 
| 18 | 
            +
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         | 
| 19 | 
            +
              spec.require_paths = ["lib"]
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              spec.add_development_dependency "bundler", "~> 1.7"
         | 
| 22 | 
            +
              spec.add_development_dependency "rake", "~> 10.0"
         | 
| 23 | 
            +
              spec.add_development_dependency 'rspec', "~> 3.4"
         | 
| 24 | 
            +
            end
         | 
    
        data/lib/alidayu.rb
    ADDED
    
    | @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            require "alidayu/version"
         | 
| 2 | 
            +
            require "alidayu/configuration"
         | 
| 3 | 
            +
            require 'net/http'
         | 
| 4 | 
            +
            require "json"
         | 
| 5 | 
            +
            require "alidayu/helper"
         | 
| 6 | 
            +
            require "alidayu/sms"
         | 
| 7 | 
            +
            require "alidayu/tts"
         | 
| 8 | 
            +
            require "alidayu/voice"
         | 
| 9 | 
            +
            require "logger"
         | 
| 10 | 
            +
             | 
| 11 | 
            +
             | 
| 12 | 
            +
            module Alidayu
         | 
| 13 | 
            +
              
         | 
| 14 | 
            +
              class << self
         | 
| 15 | 
            +
                def setup
         | 
| 16 | 
            +
                  yield config
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def config
         | 
| 20 | 
            +
                  @config ||= Configuration.new
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                def logger
         | 
| 24 | 
            +
                  @logger ||= Logger.new(STDOUT)
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1,40 @@ | |
| 1 | 
            +
            module Alidayu
         | 
| 2 | 
            +
              class Configuration
         | 
| 3 | 
            +
                # API请求地址分为正式(http/https)和沙箱(http/https)共四个地址
         | 
| 4 | 
            +
                # 正式-http: http://gw.api.taobao.com/router/rest  
         | 
| 5 | 
            +
                # 正式-https: https://eco.taobao.com/router/rest
         | 
| 6 | 
            +
                # 沙箱-http: http://gw.api.tbsandbox.com/router/rest
         | 
| 7 | 
            +
                # 沙箱-https: https://gw.api.tbsandbox.com/router/rest
         | 
| 8 | 
            +
                def server
         | 
| 9 | 
            +
                  @server ||= 'https://eco.taobao.com/router/rest'
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def server=(server)
         | 
| 13 | 
            +
                  @server = server
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                def app_key
         | 
| 17 | 
            +
                  @app_key ||= 'your_app_key'
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def app_key=(app_key)
         | 
| 21 | 
            +
                  @app_key = app_key
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def app_secret
         | 
| 25 | 
            +
                  @app_secret ||= 'your_app_secret'
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                def app_secret=(app_secret)
         | 
| 29 | 
            +
                  @app_secret = app_secret
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                def sign_name
         | 
| 33 | 
            +
                  @sign_name ||= 'sign_name'
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                def sign_name=(sign_name)
         | 
| 37 | 
            +
                  @sign_name = sign_name
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
            end
         | 
| @@ -0,0 +1,46 @@ | |
| 1 | 
            +
            module Alidayu
         | 
| 2 | 
            +
              module Helper
         | 
| 3 | 
            +
                # 获得响应结果
         | 
| 4 | 
            +
                def get_response(params)
         | 
| 5 | 
            +
                  uri = URI(Alidayu.config.server)
         | 
| 6 | 
            +
                  http = Net::HTTP.new(uri.host, uri.port)
         | 
| 7 | 
            +
                  if uri.scheme == "https"
         | 
| 8 | 
            +
                    http.use_ssl = true
         | 
| 9 | 
            +
                    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
                  request = Net::HTTP::Post.new(uri.path)
         | 
| 12 | 
            +
                  request_params = build_params(params)
         | 
| 13 | 
            +
                  request.add_field('Content-Type', 'application/json')
         | 
| 14 | 
            +
                  request.set_form_data(request_params)
         | 
| 15 | 
            +
                  response = http.request(request)
         | 
| 16 | 
            +
                  Alidayu.logger.info response.body
         | 
| 17 | 
            +
                  return JSON.parse(response.body)
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                private
         | 
| 21 | 
            +
                # 构建请求参数
         | 
| 22 | 
            +
                def build_params(params)
         | 
| 23 | 
            +
                  params[:app_key] = params[:app_key] || Alidayu.config.app_key
         | 
| 24 | 
            +
                  params[:timestamp] = Time.now.strftime("%Y-%m-%d %H:%M:%S")
         | 
| 25 | 
            +
                  params[:format] = 'json'
         | 
| 26 | 
            +
                  params[:v] = '2.0'
         | 
| 27 | 
            +
                  params[:sign_method] = 'hmac'
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  signature = generate_signature(params)
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  params[:sign] = signature
         | 
| 32 | 
            +
                  return params
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                # 生成签名 hmac
         | 
| 36 | 
            +
                def generate_signature(params)
         | 
| 37 | 
            +
                  params.delete(:sign)
         | 
| 38 | 
            +
                  data = params.sort.compact.join
         | 
| 39 | 
            +
                  digest = OpenSSL::Digest.new('md5')
         | 
| 40 | 
            +
                  secret = params[:app_secret] || Alidayu.config.app_secret
         | 
| 41 | 
            +
                  hmac_sign = OpenSSL::HMAC.hexdigest(digest, secret, data).upcase
         | 
| 42 | 
            +
                  return hmac_sign
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
              end
         | 
| 46 | 
            +
            end
         | 
    
        data/lib/alidayu/sms.rb
    ADDED
    
    | @@ -0,0 +1,39 @@ | |
| 1 | 
            +
            module Alidayu
         | 
| 2 | 
            +
              module Sms
         | 
| 3 | 
            +
                class << self
         | 
| 4 | 
            +
                  include Alidayu::Helper
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  METHOD_HASH = {
         | 
| 7 | 
            +
                    sms_send: "alibaba.aliqin.fc.sms.num.send",
         | 
| 8 | 
            +
                    sms_query: "alibaba.aliqin.fc.sms.num.query"
         | 
| 9 | 
            +
                  }
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  # 短信发送
         | 
| 12 | 
            +
                  # { mobiles: '', template_code: '', params: { code: '', product: '' } }
         | 
| 13 | 
            +
                  def send(params)
         | 
| 14 | 
            +
                    params[:method] = METHOD_HASH[:sms_send]
         | 
| 15 | 
            +
                    params[:sms_type] = 'normal'
         | 
| 16 | 
            +
                    params[:sms_free_sign_name] = params.delete(:sign_name) || Alidayu.config.sign_name
         | 
| 17 | 
            +
                    if params[:params].is_a? Hash
         | 
| 18 | 
            +
                      sms_param = params[:params].to_json
         | 
| 19 | 
            +
                      params.delete(:params)
         | 
| 20 | 
            +
                      params[:sms_param] = sms_param
         | 
| 21 | 
            +
                    end
         | 
| 22 | 
            +
                    params[:rec_num] = params.delete(:mobiles)
         | 
| 23 | 
            +
                    params[:sms_template_code] = params.delete(:template_code)
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    response = get_response(params)
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  # 短信发送记录查询
         | 
| 29 | 
            +
                  # {  mobile: '', query_date: 'yyyyMMdd', current_page: 1, page_size: 20 }
         | 
| 30 | 
            +
                  def query(params)
         | 
| 31 | 
            +
                    params[:method] = METHOD_HASH[:sms_query]
         | 
| 32 | 
            +
                    params[:rec_num] = params.delete(:mobile)
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                    response = get_response(params)
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
            end
         | 
    
        data/lib/alidayu/tts.rb
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            module Alidayu
         | 
| 2 | 
            +
              module Tts
         | 
| 3 | 
            +
                class << self
         | 
| 4 | 
            +
                  include Alidayu::Helper
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  # 文本转语音通知
         | 
| 7 | 
            +
                  # { called_num: '', called_show_num: '', template_code: '', params: {  } }
         | 
| 8 | 
            +
                  def single_call(params)
         | 
| 9 | 
            +
                    params[:method] = 'alibaba.aliqin.fc.tts.num.singlecall'
         | 
| 10 | 
            +
                    params[:tts_code] = params.delete(:template_code)
         | 
| 11 | 
            +
                    if params[:params].is_a? Hash
         | 
| 12 | 
            +
                      tts_param = params[:params].to_json
         | 
| 13 | 
            +
                      params.delete(:params)
         | 
| 14 | 
            +
                      params[:tts_param] = tts_param
         | 
| 15 | 
            +
                    end
         | 
| 16 | 
            +
                    response = get_response(params)
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
| @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            module Alidayu
         | 
| 2 | 
            +
              module Voice
         | 
| 3 | 
            +
                class << self
         | 
| 4 | 
            +
                  include Alidayu::Helper
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  METHOD_HASH = {
         | 
| 7 | 
            +
                    voice_double_call: "alibaba.aliqin.fc.voice.num.doublecall",
         | 
| 8 | 
            +
                    voice_single_call: "alibaba.aliqin.fc.voice.num.singlecall"
         | 
| 9 | 
            +
                  }
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  # 语音双呼
         | 
| 12 | 
            +
                  # { caller_num: '', caller_show_num: '', called_num: '', called_show_num: '' }
         | 
| 13 | 
            +
                  def double_call(params)
         | 
| 14 | 
            +
                    params[:method] = METHOD_HASH[:voice_double_call]
         | 
| 15 | 
            +
                    params[:session_time_out] = params.delete(:time_out)
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                    response = get_response(params)
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  # 语音通知
         | 
| 21 | 
            +
                  #  { called_num: '', called_show_num: '', voice_code: '' }
         | 
| 22 | 
            +
                  def single_call(params)
         | 
| 23 | 
            +
                    params[:method] = METHOD_HASH[:voice_single_call]
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    response = get_response(params)
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
            end
         | 
    
        data/spec/sms_spec.rb
    ADDED
    
    | @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe "test sms api" do
         | 
| 4 | 
            +
              it "should send message success" do
         | 
| 5 | 
            +
                options = { mobiles: '13681695220', template_code: 'SMS_5410467', params: { code: '1234567', product: '就诊通' } }
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                data = Alidayu::Sms.send(options)
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                expect(data["alibaba_aliqin_fc_sms_num_send_response"]["result"]["success"]).to eq(true)
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              it "should send message fail" do
         | 
| 13 | 
            +
                options = { mobiles: '13681695220', template_code: 'SMS_5410467', params: { code: '123567' } }
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                data = Alidayu::Sms.send(options)
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                expect(data["error_response"]).to be_an_instance_of(Hash)
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              it "should query message record" do
         | 
| 21 | 
            +
                options = { mobile: '13681695220', query_date: '20160304', current_page: 1, page_size: 10 }
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                data = Alidayu::Sms.query(options)
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                expect(data["alibaba_aliqin_fc_sms_num_query_response"]).to be_an_instance_of(Hash)
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
             end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | @@ -0,0 +1,12 @@ | |
| 1 | 
            +
            require 'bundler/setup'
         | 
| 2 | 
            +
            require 'alidayu'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            Bundler.setup
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Alidayu.setup do |config|
         | 
| 7 | 
            +
              # config.server     = 'http://gw.api.taobao.com/router/rest'
         | 
| 8 | 
            +
              config.server     = 'https://eco.taobao.com/router/rest'
         | 
| 9 | 
            +
              config.app_key    = '12345'
         | 
| 10 | 
            +
              config.app_secret = '6789012345'
         | 
| 11 | 
            +
              config.sign_name  = '注册验证'
         | 
| 12 | 
            +
            end
         | 
    
        data/spec/tts_spec.rb
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe "test tts api" do
         | 
| 4 | 
            +
              it "should send tts success" do
         | 
| 5 | 
            +
                options = { called_num: '13681695220', called_show_num: '10086', template_code: 'TTS_5410474', params: { product: '就诊通', code: '1234567' } }
         | 
| 6 | 
            +
                
         | 
| 7 | 
            +
                data = Alidayu::Tts.single_call(options)
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                expect(data["alibaba_aliqin_fc_sms_num_send_response"]["result"]["success"]).to eq(true)
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              it "should send tts fail" do
         | 
| 13 | 
            +
                options = { called_num: '13681695220', called_show_num: '10086', template_code: 'TTS_5410474', params: { product: '就诊通' } }
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                data = Alidayu::Tts.single_call(options)
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                expect(data["error_response"]).to be_an_instance_of(Hash)
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
             end
         | 
    
        data/spec/voice_spec.rb
    ADDED
    
    | 
            File without changes
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,108 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: alidayu_api
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - wangrui
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2016-03-06 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: bundler
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '1.7'
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '1.7'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: rake
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '10.0'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '10.0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: rspec
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - "~>"
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '3.4'
         | 
| 48 | 
            +
              type: :development
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - "~>"
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '3.4'
         | 
| 55 | 
            +
            description: "阿里大鱼短信发送,语音双呼,文本转语音通知等API的调用"
         | 
| 56 | 
            +
            email:
         | 
| 57 | 
            +
            - to_wangrui@163.com
         | 
| 58 | 
            +
            executables: []
         | 
| 59 | 
            +
            extensions: []
         | 
| 60 | 
            +
            extra_rdoc_files: []
         | 
| 61 | 
            +
            files:
         | 
| 62 | 
            +
            - ".gitignore"
         | 
| 63 | 
            +
            - Gemfile
         | 
| 64 | 
            +
            - LICENSE.txt
         | 
| 65 | 
            +
            - README.md
         | 
| 66 | 
            +
            - Rakefile
         | 
| 67 | 
            +
            - alidayu_api.gemspec
         | 
| 68 | 
            +
            - lib/alidayu.rb
         | 
| 69 | 
            +
            - lib/alidayu/configuration.rb
         | 
| 70 | 
            +
            - lib/alidayu/helper.rb
         | 
| 71 | 
            +
            - lib/alidayu/sms.rb
         | 
| 72 | 
            +
            - lib/alidayu/tts.rb
         | 
| 73 | 
            +
            - lib/alidayu/version.rb
         | 
| 74 | 
            +
            - lib/alidayu/voice.rb
         | 
| 75 | 
            +
            - spec/sms_spec.rb
         | 
| 76 | 
            +
            - spec/spec_helper.rb
         | 
| 77 | 
            +
            - spec/tts_spec.rb
         | 
| 78 | 
            +
            - spec/voice_spec.rb
         | 
| 79 | 
            +
            homepage: https://github.com/wangrui438/alidayu_api
         | 
| 80 | 
            +
            licenses:
         | 
| 81 | 
            +
            - MIT
         | 
| 82 | 
            +
            metadata: {}
         | 
| 83 | 
            +
            post_install_message: 
         | 
| 84 | 
            +
            rdoc_options: []
         | 
| 85 | 
            +
            require_paths:
         | 
| 86 | 
            +
            - lib
         | 
| 87 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 88 | 
            +
              requirements:
         | 
| 89 | 
            +
              - - ">="
         | 
| 90 | 
            +
                - !ruby/object:Gem::Version
         | 
| 91 | 
            +
                  version: '0'
         | 
| 92 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
              requirements:
         | 
| 94 | 
            +
              - - ">="
         | 
| 95 | 
            +
                - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                  version: '0'
         | 
| 97 | 
            +
            requirements: []
         | 
| 98 | 
            +
            rubyforge_project: 
         | 
| 99 | 
            +
            rubygems_version: 2.4.8
         | 
| 100 | 
            +
            signing_key: 
         | 
| 101 | 
            +
            specification_version: 4
         | 
| 102 | 
            +
            summary: "阿里大鱼API"
         | 
| 103 | 
            +
            test_files:
         | 
| 104 | 
            +
            - spec/sms_spec.rb
         | 
| 105 | 
            +
            - spec/spec_helper.rb
         | 
| 106 | 
            +
            - spec/tts_spec.rb
         | 
| 107 | 
            +
            - spec/voice_spec.rb
         | 
| 108 | 
            +
            has_rdoc: 
         |