module EzaliyunAms

Attributes

configuration[W]

Public Class Methods

BindAlias(app_key, device_id, alias_name) click to toggle source

——别名相关接口 绑定别名

# File lib/ezaliyun-ams.rb, line 328
def BindAlias app_key, device_id, alias_name
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'DeviceId' => device_id,
      'AliasName' => alias_name
  }
  get_rs api_params
end
BindTag(app_key, client_key, key_type, tag_name) click to toggle source

——TAG相关接口 绑定TAG

# File lib/ezaliyun-ams.rb, line 273
def BindTag app_key, client_key, key_type, tag_name
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'ClientKey' => client_key,
      'KeyType' => key_type,
      'TagName' => tag_name
  }
  get_rs api_params
end
CancelPush(app_key, message_id) click to toggle source

取消定时推送任务

# File lib/ezaliyun-ams.rb, line 178
def CancelPush app_key, message_id
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'MessageId' => message_id
  }
  get_rs api_params
end
CheckDevices(app_key, device_ids) click to toggle source

批量检查设备有效性

# File lib/ezaliyun-ams.rb, line 262
def CheckDevices app_key, device_ids
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'DeviceIds' => device_ids
  }
  get_rs api_params
end
ListPushRecords(app_key, start_time, end_time, push_type=nil, page=nil, page_size=nil) click to toggle source

——查询相关接口 查询推送列表

# File lib/ezaliyun-ams.rb, line 189
def ListPushRecords app_key, start_time, end_time, push_type=nil, page=nil, page_size=nil
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'StartTime' => start_time,
      'EndTime' => end_time,
      'PushType' => push_type,
      'Page' => page,
      'PageSize' => page_size
  }
  if !push_type.nil? then api_params['PushType'] = push_type end
  if !page.nil? then api_params['Page'] = page end
  if !page_size.nil? then api_params['PageSize'] = page_size end
  get_rs api_params
end
ListSummaryApps() click to toggle source

——各种接口从这开始—— APP概览列表

# File lib/ezaliyun-ams.rb, line 103
def ListSummaryApps
  api_params = {
      'Action' => __method__.to_s
  }
  get_rs api_params
end
ListTags(app_key, client_key, key_type, tag_name) click to toggle source

TAG列表

# File lib/ezaliyun-ams.rb, line 308
def ListTags app_key, client_key, key_type, tag_name
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key
  }
  get_rs api_params
end
Push(app_key, other_hash) click to toggle source

推送高级接口 未完成

# File lib/ezaliyun-ams.rb, line 168
def Push app_key, other_hash
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key
  }
  api_params.merge! other_hash
  get_rs api_params
end
PushMessageToAndroid(app_key, target, target_value, title, body) click to toggle source

——推送相关接口 推消息给Android设备

# File lib/ezaliyun-ams.rb, line 112
def PushMessageToAndroid app_key, target, target_value, title, body
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'Target' => target,
      'TargetValue' => target_value,
      'Title' => title,
      'Body' => body
  }
  get_rs api_params
end
PushMessageToiOS(app_key, target, target_value, title, body) click to toggle source

推消息给IOS设备

# File lib/ezaliyun-ams.rb, line 125
def PushMessageToiOS app_key, target, target_value, title, body
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'Target' => target,
      'TargetValue' => target_value,
      'Title' => title,
      'Body' => body
  }
  get_rs api_params
end
PushNoticeToAndroid(app_key, target, target_value, title, body, ext_parameters = nil) click to toggle source

推通知给Android设备

# File lib/ezaliyun-ams.rb, line 138
def PushNoticeToAndroid app_key, target, target_value, title, body, ext_parameters = nil
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'Target' => target,
      'TargetValue' => target_value,
      'Title' => title,
      'Body' => body,
      'ExtParameters' => ext_parameters
  }
  if !ext_parameters.nil? then api_params['ExtParameters'] = ext_parameters end
  get_rs api_params
end
PushNoticeToiOS(app_key, target, target_value, apns_env, title, body, ext_parameters = nil) click to toggle source

推通知给IOS设备

# File lib/ezaliyun-ams.rb, line 153
def PushNoticeToiOS app_key, target, target_value, apns_env, title, body, ext_parameters = nil
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'Target' => target,
      'TargetValue' => target_value,
      'ApnsEnv' => apns_env,
      'Title' => title,
      'Body' => body
  }
  if !ext_parameters.nil? then api_params['ExtParameters'] = ext_parameters end
  get_rs api_params
end
QueryAliases(app_key, device_id) click to toggle source

查询别名

# File lib/ezaliyun-ams.rb, line 339
def QueryAliases app_key, device_id
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'DeviceId' => device_id
  }
  get_rs api_params
end
QueryDeviceInfo(app_key, device_id) click to toggle source

查询设备详情

# File lib/ezaliyun-ams.rb, line 252
def QueryDeviceInfo app_key, device_id
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'DeviceId' => device_id
  }
  get_rs api_params
end
QueryDeviceStat(app_key, start_time, end_time, device_type, query_type) click to toggle source

设备新增与留存

# File lib/ezaliyun-ams.rb, line 228
def QueryDeviceStat app_key, start_time, end_time, device_type, query_type
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'StartTime' => start_time,
      'EndTime' => end_time,
      'DeviceType' => device_type,
      'QueryType' => query_type
  }
  get_rs api_params
end
QueryPushStatByApp(app_key, start_time, end_time, granularity) click to toggle source

APP维度推送统计

# File lib/ezaliyun-ams.rb, line 206
def QueryPushStatByApp app_key, start_time, end_time, granularity
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'StartTime' => start_time,
      'EndTime' => end_time,
      'Granularity' => granularity
  }
  get_rs api_params
end
QueryPushStatByMsg(app_key, message_id) click to toggle source

任务维度推送统计

# File lib/ezaliyun-ams.rb, line 218
def QueryPushStatByMsg app_key, message_id
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'MessageId' => message_id
  }
  get_rs api_params
end
QueryTags(app_key, client_key, key_type) click to toggle source

查询TAG

# File lib/ezaliyun-ams.rb, line 285
def QueryTags app_key, client_key, key_type
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'ClientKey' => client_key,
      'KeyType' => key_type
  }
  get_rs api_params
end
QueryUniqueDeviceStat(app_key, start_time, end_time) click to toggle source

去重设备统计

# File lib/ezaliyun-ams.rb, line 241
def QueryUniqueDeviceStat app_key, start_time, end_time
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'StartTime' => start_time,
      'EndTime' => end_time
  }
  get_rs api_params
end
RemoveTag(app_key, tag_name) click to toggle source

删除TAG

# File lib/ezaliyun-ams.rb, line 317
def RemoveTag app_key, tag_name
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'TagName' => tag_name
  }
  get_rs api_params
end
UnbindAlias(app_key, device_id, unbind_all = nil, alias_name = nil) click to toggle source

解绑别名

# File lib/ezaliyun-ams.rb, line 349
def UnbindAlias app_key, device_id, unbind_all = nil, alias_name = nil
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'DeviceId' => device_id
  }
  if !unbind_all.nil? then api_params['UnbindAll'] = unbind_all end
  if !alias_name.nil? then api_params['AliasName'] = alias_name end
  get_rs api_params
end
UnbindTag(app_key, client_key, key_type, tag_name) click to toggle source

解绑TAG

# File lib/ezaliyun-ams.rb, line 296
def UnbindTag app_key, client_key, key_type, tag_name
  api_params = {
      'Action' => __method__.to_s,
      'AppKey' => app_key,
      'ClientKey' => client_key,
      'KeyType' => key_type,
      'TagName' => tag_name
  }
  get_rs api_params
end
canonicalized_query_string(params) click to toggle source

原生参数经过2次编码拼接成标准字符串

# File lib/ezaliyun-ams.rb, line 53
def canonicalized_query_string(params)
  cqstring = ''

  # Canonicalized Query String/使用请求参数构造规范化的请求字符串
  # 按照参数名称的字典顺序对请求中所有的请求参数进行排序
  params = params.sort.to_h

  params.each do |key, value|
    if cqstring.empty?
      cqstring += url_encode"#{key}=#{url_encode(value)}"
    else
      cqstring += url_encode"&#{key}=#{url_encode(value)}"
    end
  end
  return  cqstring
end
configuration() click to toggle source
# File lib/ezaliyun-ams.rb, line 28
def configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source
# File lib/ezaliyun-ams.rb, line 32
def configure
  yield(configuration)
end
get_rs(api_params) click to toggle source
# File lib/ezaliyun-ams.rb, line 36
def get_rs api_params
  public_params ={
      'Format' => configuration.format,
      'RegionId' => configuration.region_id,
      'Version' => configuration.version,
      'AccessKeyId' => configuration.access_key_id,
      'SignatureMethod' => configuration.signature_method,
      'Timestamp' => seed_timestamp,
      'SignatureVersion' => configuration.signature_version,
      'SignatureNonce' => seed_signature_nonce
  }
  public_params = public_params.merge api_params
  public_params['Signature'] = sign configuration.access_key_secret, public_params
  post_param(public_params).body
end
post_param(params) click to toggle source
# File lib/ezaliyun-ams.rb, line 90
def post_param params
  uri = URI('https://' + configuration.domain)
  Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
    request = Net::HTTP::Post.new uri
    request.set_form_data params
    # request.body = params.to_json
    http.request request # Net::HTTPResponse object
  end
end
seed_signature_nonce() click to toggle source

生成短信唯一标识码,采用到微秒的时间戳

# File lib/ezaliyun-ams.rb, line 86
def seed_signature_nonce
  Time.now.utc.strftime("%Y%m%d%H%M%S%L")
end
seed_timestamp() click to toggle source

生成短信时间戳

# File lib/ezaliyun-ams.rb, line 81
def seed_timestamp
  Time.now.utc.strftime("%FT%TZ")
end
sign(key_secret, params) click to toggle source

生成数字签名

# File lib/ezaliyun-ams.rb, line 71
def sign(key_secret, params)
  key = key_secret + '&'
  signature = 'POST' + '&' + url_encode('/') + '&' + canonicalized_query_string(params)
  digest = OpenSSL::Digest.new('sha1')
  sign = Base64.encode64(OpenSSL::HMAC.digest(digest, key, signature))
  # url_encode(sign.chomp) # 通过chomp去掉最后的换行符 LF
  sign.chomp # 通过chomp去掉最后的换行符 LF
end