Module: Reapal::Api::CommunicateResultHelper

Defined in:
lib/reapal/api/api_helper.rb

Instance Method Summary collapse

Instance Method Details

#operate_post(request_type, service, params, post_path, fail_codes, success_codes, version = '3.0') ⇒ Hash

操作类的 api,统一返回处理

Parameters:

  • request_type (Symbole)

    操作类(:operate)/查询类(:query)

  • service (String)

    富民的服务

  • params (Hash)

    参数

  • post_path (String)

    post url

  • fail_codes (Array)

    错误返回码

  • success_codes (String)

    【业务】【明确的】正确返回码(而不是申请成功这类)

Returns:

  • (Hash)

    结果集(见通用返回)



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/reapal/api/api_helper.rb', line 17

def operate_post(request_type, service, params, post_path, fail_codes, success_codes, version='3.0')
  response = Http.post(service, params, @config, post_path, version)

  res = Reapal::Utils.api_result(params, response)

  if :operate == request_type
    # 向服务器发送操作,超时类的都应该当 pending 处理
    return res if response.http_pending?
  elsif :query == request_type
    # 查询类 api,http 没成功都返回 pending
    return res unless response.http_success?
  else
    raise "未知的请求类型,请选择设置:操作类(:operate)/查询类(:query)"
  end

  # 确定的错误
  if fail_codes.include?(response.data[:errorCode])
    res[:result] = "F"
    return res
  end

  # 其余 api 错误不知道
  return res unless response.data[:errorCode].nil?

  # 确定的成功返回码
  if success_codes.include?(response.data[:resultCode])
    res[:result] = "S"
  end

  res
end