Skip to content

Commit

Permalink
添加账号管理和运营管理的API接口
Browse files Browse the repository at this point in the history
  • Loading branch information
JiangYongKang committed Sep 14, 2020
1 parent 7fa7622 commit 226a4c2
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 1 deletion.
102 changes: 101 additions & 1 deletion lib/tim_sdk/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,108 @@ def self.connection
end
end

# 导入单个帐号
def self.invoke_account_import(identifier, nick = nil, face_url = nil)
response = connection.post('/v4/im_open_login_svc/account_import') do |request|
request_body = { :Identifier => identifier.to_s }
request_body.merge!(:Nick => nick) if nick
request_body.merge!(:FaceUrl => face_url) if face_url
request.body = request_body.to_json
end
raise TimServerError, "Response Status: #{response.status}" unless response.success?
JSON.parse(response.body, symbolize_names: true) if response.success?
end

# 导入多个账号
def self.invoke_multi_account_import(accounts)
response = connection.post('/v4/im_open_login_svc/multiaccount_import') do |request|
request.body = {
:Accounts => accounts.map(&:to_s)
}.to_json
end
raise TimServerError, "Response Status: #{response.status}" unless response.success?
JSON.parse(response.body, symbolize_names: true) if response.success?
end

# 删除账号
def self.invoke_account_delete(accounts)
response = connection.post('/v4/im_open_login_svc/account_delete') do |request|
request.body = {
:DeleteItem => accounts.map do |account|
{
:UserID => account.to_s
}
end
}.to_json
end
raise TimServerError, "Response Status: #{response.status}" unless response.success?
JSON.parse(response.body, symbolize_names: true) if response.success?
end

# 查询账号
def self.invoke_account_check(accounts)
response = connection.post('/v4/im_open_login_svc/account_check') do |request|
request.body = {
:CheckItem => accounts.map do |account|
{
:UserID => account.to_s
}
end
}.to_json
end
raise TimServerError, "Response Status: #{response.status}" unless response.success?
JSON.parse(response.body, symbolize_names: true) if response.success?
end

# 失效帐号登录态
def self.invoke_kick(identifier)
response = connection.post('/v4/im_open_login_svc/kick') do |request|
request.body = {
:Identifier => identifier.to_s
}.to_json
end
raise TimServerError, "Response Status: #{response.status}" unless response.success?
JSON.parse(response.body, symbolize_names: true) if response.success?
end

# 查询帐号在线状态
def self.invoke_query_state(accounts, is_need_detail = 0)
response = connection.post('/v4/openim/querystate') do |request|
request.body = {
:To_Account => accounts.map(&:to_s),
:IsNeedDetail => is_need_detail
}.to_json
end
raise TimServerError, "Response Status: #{response.status}" unless response.success?
JSON.parse(response.body, symbolize_names: true) if response.success?
end

# 拉取运营数据
def self.invoke_fetch_app_info(fields = [])
response = connection.post('/v4/openconfigsvr/getappinfo') do |request|
request.body = {
:RequestField => fields
}.to_json
end
raise TimServerError, "Response Status: #{response.status}" unless response.success?
JSON.parse(response.body, symbolize_names: true) if response.success?
end


# 下载消息记录
def self.invoke_fetch_history(chat_type, msg_time)
response = connection.post('/v4/open_msg_svc/get_history') do |request|
request.body = {
:ChatType => chat_type,
:MsgTime => msg_time,
}.to_json
end
raise TimServerError, "Response Status: #{response.status}" unless response.success?
JSON.parse(response.body, symbolize_names: true) if response.success?
end


# 获取服务器 IP 地址
# 基于安全等考虑,您可能需要获知服务器的 IP 地址列表,以便进行相关限制。App 管理员可以通过该接口获得 SDK、第三方回调所使用到的服务器 IP 地址列表或 IP 网段信息。
def self.invoke_fetch_ip_list
response = connection.post('/v4/ConfigSvc/GetIPList') do |request|
request.body = {}.to_json
Expand Down
53 changes: 53 additions & 0 deletions spec/tim_sdk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,59 @@
expect(signature.size).to be > 0
end

it 'should be imported successfully' do
response = TimSdk::Api.invoke_account_import('foo')
expect(response[:ActionStatus]).to eq('OK')
expect(response[:ErrorCode]).to eq(0)
end

it 'should be imported multi account successfully' do
response = TimSdk::Api.invoke_multi_account_import(%w[foo bar])
expect(response[:ActionStatus]).to eq('OK')
expect(response[:ErrorCode]).to eq(0)
end

it 'should be kick account successfully' do
response = TimSdk::Api.invoke_kick('foo')
expect(response[:ActionStatus]).to eq('OK')
expect(response[:ErrorCode]).to eq(0)
end

it 'should be check account successfully' do
response = TimSdk::Api.invoke_account_check(%w[foo bar])
expect(response[:ActionStatus]).to eq('OK')
expect(response[:ErrorCode]).to eq(0)
end

it 'should be query account state successfully' do
response = TimSdk::Api.invoke_query_state(%w[foo bar])
expect(response[:ActionStatus]).to eq('OK')
expect(response[:ErrorCode]).to eq(0)
response = TimSdk::Api.invoke_query_state(%w[foo bar], 1)
expect(response[:ActionStatus]).to eq('OK')
expect(response[:ErrorCode]).to eq(0)
end

it 'should be delete account successfully' do
response = TimSdk::Api.invoke_account_delete(%w[foo bar])
expect(response[:ActionStatus]).to eq('OK')
expect(response[:ErrorCode]).to eq(0)
end

it 'should return app info' do
response = TimSdk::Api.invoke_fetch_app_info
expect(response[:ErrorInfo]).to eq('OK')
expect(response[:ErrorCode]).to eq(0)
expect(response).to have_key(:Result)
end

it 'should return message histories' do
response = TimSdk::Api.invoke_fetch_history('C2C', '2020091116')
expect(response).to have_key(:ActionStatus)
expect(response).to have_key(:ErrorInfo)
expect(response).to have_key(:ErrorCode)
end

it 'should return a list of IP addresses' do
response = TimSdk::Api.invoke_fetch_ip_list
expect(response[:ActionStatus]).to eq('OK')
Expand Down

0 comments on commit 226a4c2

Please sign in to comment.