<commit_before># SmsCtrl

发送短信，间隔限制，过期控制

## Installation

Add this line to your application's Gemfile:


	gem 'sms_ctrl'


And then execute:

    $ bundle

Or install it yourself as:

    $ gem install sms_ctrl

## Usage

```ruby
# confing/initializes/sms_ctrl.rb

# 设置debug模式，所有验证码都是123456，不会走sender
SmsCtrl.debug = true

# 设置cache，需要支持 read(key), write(key, expires_in: 10)
SmsCtrl.cache = Rails.cache

# 设置默认配置，可以在case配置中覆盖
SmsCtrl.default_options = {
  retry_limit: 55,
  expires_in: 30 * 60,
  mobile_regexp: /^1[3|4|5|7|8]\d{9}$/,
  sender: -> (mobile, code, params) { warn "No message sender set for case #{@name}" },
}

# 设置默认错误，可以在case配置中覆盖
SmsCtrl.default_errors = {
  illegal_mobile: '请输入正确的手机号码',
  retry_limit: '操作太频繁，请稍后再试'
}

# 注册控制模块
SmsCtrl.register( "register_user", {
  # retry_limit: 55,
  # expires: 30 * 60,
  sender: ->(mobile, code, params) {
    # 发送逻辑
  }
})

SmsCtrl.register( "user_reset_password", {
  # retry_limit: 55,
  # expires: 30 * 60,
  sender: ->(mobile, code, params) {
    # 发送逻辑
  }
})

# 发送验证码
SmsCtrl["register_user"].send_sms(mobile, code, params)
SmsCtrl["user_reset_password"].send_sms(mobile, code, params)

# 检查验证码是否匹配
SmsCtrl["register_user"].check_code "13000000000", '231232'
SmsCtrl["user_reset_password"].check_code "13000000000", '231232'

# 设置默认
SmsCtrl.set_default("register_user")
SmsCtrl.send_sms(mobile, code, params)
SmsCtrl.check_code "13000000000", '231232'
<commit_msg>fix readme bug<commit_after># SmsCtrl

发送短信，间隔限制，过期控制

## Installation

Add this line to your application's Gemfile:


	gem 'sms_ctrl'


And then execute:

    $ bundle

Or install it yourself as:

    $ gem install sms_ctrl

## Usage

```ruby
# confing/initializes/sms_ctrl.rb

# 设置debug模式，所有验证码都是123456，不会走sender
SmsCtrl.debug = true

# 设置cache，需要支持 read(key), write(key, expires_in: 10)
SmsCtrl.cache = Rails.cache

# 设置默认配置，可以在case配置中覆盖
SmsCtrl.default_options = {
  retry_limit: 55,
  expires_in: 30 * 60,
  mobile_regexp: /^1[3|4|5|7|8]\d{9}$/,
  sender: -> (mobile, code, params) { warn "No message sender set for case #{@name}" },
}

# 设置默认错误，可以在case配置中覆盖
SmsCtrl.default_errors = {
  illegal_mobile: '请输入正确的手机号码',
  retry_limit: '操作太频繁，请稍后再试'
}

# 注册控制模块
SmsCtrl.register( "register_user", {
  # retry_limit: 55,
  # expires_in: 30 * 60,
  sender: ->(mobile, code, params) {
    # 发送逻辑
  }
})

SmsCtrl.register( "user_reset_password", {
  # retry_limit: 55,
  # expires_in: 30 * 60,
  sender: ->(mobile, code, params) {
    # 发送逻辑
  }
})

# 发送验证码
SmsCtrl["register_user"].send_sms(mobile, code, params)
SmsCtrl["user_reset_password"].send_sms(mobile, code, params)

# 检查验证码是否匹配
SmsCtrl["register_user"].check_code "13000000000", '231232'
SmsCtrl["user_reset_password"].check_code "<PASSWORD>0000000", '<PASSWORD>'

# 设置默认
SmsCtrl.set_default("register_user")
SmsCtrl.send_sms(mobile, code, params)
SmsCtrl.check_code "13000000000", '231232'

{'fraction_non_alphanumeric': 0.1442941380506417, 'fraction_numerical': 0.054804023586541795, 'mean_word_length': 4.921971252566735, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2384175', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1371, 'n_words': 226}