Skip to content

Commit

Permalink
aliyun ocr
Browse files Browse the repository at this point in the history
  • Loading branch information
qinmingyuan committed Jul 22, 2024
1 parent 0f9e942 commit a70293d
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/work-design/rails_com.git
revision: 7aec32afcd9dbe9347f221c73e467a92165bd680
revision: 9ccbdae61a3d196e64d7a9b3c500f1bd0423c86d
specs:
rails_com (1.3.0)
acme-client
Expand All @@ -20,7 +20,7 @@ GIT

GIT
remote: https://github.com/work-design/rails_design.git
revision: 8bbfb8000b400f5de3eef01d8261b7459104753c
revision: 044eef4bac1818a5104df5f916cfc8662a716c26
specs:
rails_design (0.0.1)
rails
Expand Down Expand Up @@ -111,7 +111,7 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
acts_as_list (1.2.1)
acts_as_list (1.2.2)
activerecord (>= 6.1)
activesupport (>= 6.1)
base64 (0.2.0)
Expand All @@ -131,18 +131,19 @@ GEM
activerecord (>= 4.0.0)
drb (2.2.1)
erubi (1.12.0)
faraday (2.9.2)
faraday (2.10.0)
faraday-net_http (>= 2.0, < 3.2)
logger
faraday-net_http (3.1.0)
net-http
faraday-retry (2.2.1)
faraday (~> 2.0)
globalid (1.2.1)
activesupport (>= 6.1)
http-2-next (1.0.3)
http-2 (1.0.0)
http-form_data (2.3.0)
httpx (1.2.6)
http-2-next (>= 1.0.3)
httpx (1.3.0)
http-2 (>= 1.0.0)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
io-console (0.7.2)
Expand All @@ -161,6 +162,7 @@ GEM
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
logger (1.6.0)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand Down
35 changes: 35 additions & 0 deletions app/apis/ali_ocr.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
begin
require 'aliyunsdkcore'
rescue LoadError
end

class AliOcr
attr_reader :client

def initialize(key, secret)
@client = RPCClient.new(
endpoint: 'https://documentautoml.cn-beijing.aliyuncs.com',
api_version: '2022-12-29',
access_key_id: key,
access_key_secret: secret
)
end

def records
body = {
action: 'DescribeDomainRecords'
}
body.merge! params: {
DomainName: root_domain
}
body.merge! opts: {
method: 'POST',
timeout: 15000
}

client.request(**body)
end



end
1 change: 1 addition & 0 deletions app/controllers/sync/admin/apps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def set_app

def app_params
params.fetch(:app, {}).permit(
:type,
:name,
:appid,
:secret,
Expand Down
5 changes: 5 additions & 0 deletions app/models/app/sync/aliyun_app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Sync
class AliyunApp < App
include Model::App::AliyunApp
end
end
11 changes: 11 additions & 0 deletions app/models/sync/model/app/aliyun_app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Sync
module Model::App::AliyunApp
extend ActiveSupport::Concern

def api
return @api if defined? @api
@api = AliOcr.new(appid, sceret)
end

end
end
1 change: 1 addition & 0 deletions app/views/sync/admin/apps/_base/_index_tbody.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<td><%= model.type_i18n %></td>
<td><%= model.name %></td>
<td><%= model.appid %></td>
<td><%= model.secret %></td>
Expand Down
1 change: 1 addition & 0 deletions app/views/sync/admin/apps/_base/_index_thead.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<th><%= Sync::App.human_attribute_name(:type) %></th>
<th><%= Sync::App.human_attribute_name(:name) %></th>
<th><%= Sync::App.human_attribute_name(:appid) %></th>
<th><%= Sync::App.human_attribute_name(:secret) %></th>
Expand Down
1 change: 1 addition & 0 deletions app/views/sync/admin/apps/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%= f.select :type, options_for_select(Sync::App.options_i18n(:type), f.object.type) %>
<%= f.text_field :name %>
<%= f.text_field :appid %>
<%= f.text_field :secret %>
Expand Down
4 changes: 4 additions & 0 deletions config/locales/zh.enum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ zh:
init: 默认
applied: 已修改
finished: 完成
sync/app:
type:
Sync::AliyunApp: 阿里云
Sync::XfyunApp: 讯飞

0 comments on commit a70293d

Please sign in to comment.