kuai_jie_qian 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 49596f7513bea4035b85d4798232ad99b9d3d459
4
+ data.tar.gz: beb2f496084cd6831da518309ac475b87212f59d
5
+ SHA512:
6
+ metadata.gz: ea07d9ab08cff3951e7bbdad2a722df3564ac5edff8aea4a3e84328e36c96e319608d82d21fab3d65f064ae1f67c8dc6ae9343bbfd516b9a0502d7b6c1fab6e0
7
+ data.tar.gz: 2b213375d22ae5fe298190c0fa541772f3fb206c0b1002ed831f5da743554d2bf4b61f5c6c4cd1f280209bee38c94ec4d6fb4b96505b9d030cca8dba67a7f317
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ .byebug_history
14
+ *.gem
15
+ Gemfile.lock
16
+
17
+ .DS_Store
18
+ */**/.DS_Store
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.5
5
+ before_install: gem install bundler -v 1.16.0
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tony@omniaccount.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in kuai_jie_qian.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 tony
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # KuaiJieQian
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kuai_jie_qian`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'kuai_jie_qian'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install kuai_jie_qian
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kuai_jie_qian. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the KuaiJieQian project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/kuai_jie_qian/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ task :push do
9
+ puts `gem push pkg/kuai_jie_qian-#{KuaiJieQian::VERSION}.gem`
10
+ end
11
+
12
+ task :publish => [:build, :push]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kuai_jie_qian"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "kuai_jie_qian/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "kuai_jie_qian"
9
+ spec.version = KuaiJieQian::VERSION
10
+ spec.authors = ["tony"]
11
+ spec.email = ["tony@omniaccount.com"]
12
+
13
+ spec.summary = %q{E签宝之快捷签}
14
+ spec.description = %q{签宝之快捷签接口}
15
+ spec.homepage = "https://github.com/omniaccountcorp/kuai_jie_qian"
16
+ spec.license = "MIT"
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against " \
24
+ "public gem pushes."
25
+ end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(test|spec|features)/})
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.16"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ spec.add_development_dependency 'byebug', '~> 9.1'
38
+ spec.add_development_dependency 'faker', '~> 1.8', '>= 1.8.4'
39
+ spec.add_development_dependency 'rest-client', '~> 2.0', '>= 2.0.2'
40
+ spec.add_development_dependency 'pdfkit', '~> 0.8.2'
41
+ spec.add_development_dependency 'wkhtmltopdf-binary', '~> 0.12.3.1'
42
+ spec.add_development_dependency 'grim'
43
+ spec.add_development_dependency 'rmagick', '~>2.16.0'
44
+ end
@@ -0,0 +1,60 @@
1
+ # coding: utf-8
2
+
3
+ module KuaiJieQian
4
+ class Client
5
+ #
6
+ # 初始化SDK
7
+ # @param options_arg [Hash] 配置信息
8
+ # * host [String] java服务器 IP:port
9
+ # * project_config [Hash] 项目信息
10
+ # * http_config [Hash] 协议信息
11
+ # * sign_config [Hash] 签名信息
12
+ #
13
+ # @return [ Hash ] 结果集
14
+ # * errCode [Integer] 错误码
15
+ # * msg [String] 错误信息
16
+ # * errShow [Boolean] 错误信息是否显示
17
+ #
18
+ def initialize(options_arg)
19
+ options = Utils.symbolize_keys(options_arg)
20
+ @config = {
21
+ host: options[:host],
22
+ project_config: options[:project_config],
23
+ http_config: options[:http_config],
24
+ sign_config: options[:sign_config],
25
+ }
26
+
27
+ init_server
28
+
29
+ # 自动 include api 下的模块
30
+ recursive_include_api('KuaiJieQian::ClientMethod')
31
+ end # initialize
32
+
33
+ private
34
+ def init_server
35
+ params = {
36
+ projectConfig: @config[:project_config],
37
+ httpConfig: @config[:http_config],
38
+ signConfig: @config[:sign_config],
39
+ }
40
+
41
+ path = "tech-sdkwrapper/timevale/init"
42
+
43
+ # 向 java 服务器初始化
44
+ res = KuaiJieQian::Http.post(@config[:host], @config[:project_config][:projectId], path, params)
45
+
46
+ raise "初始化失败:#{res[:msg]}" if '0' != res[:errCode].to_s
47
+ end
48
+
49
+ def recursive_include_api(module_chain)
50
+ modules = eval("#{module_chain}.constants").each{ |constant| eval("#{module_chain}::#{constant}").class.kind_of?(Module) }
51
+
52
+ if modules.empty?
53
+ self.class.send(:include, eval(module_chain))
54
+ else
55
+ modules.each{ |constant| recursive_include_api("#{module_chain}::#{constant}") }
56
+ end
57
+ end
58
+
59
+ end # class
60
+ end
@@ -0,0 +1,72 @@
1
+ # coding: utf-8
2
+
3
+ module KuaiJieQian
4
+ module ClientMethod
5
+ module MerchantSign
6
+ #
7
+ # 平台自身签署摘要(文件流)
8
+ # @param file_stream [file] 文件流
9
+ # @param sign_type [String] 签章类型,Single(单页签章)、Multi(多页签章)、Edges(签骑缝章)、Key(关键字签章)
10
+ # @param seal_position_info [hash] 签章信息
11
+ # * pos_page [String] 签署页码, 若为多页签章,支持页码格式“1-3,5,8“, 坐标定位时不可空
12
+ # * pos_type [Integer] 默认0(若为关键字定位,签章类型(signType)必须指定为关键字定位才生效)
13
+ # * key [String] 关键字
14
+ # * pos_x [Float] 签署位置X坐标
15
+ # * pos_y [Float] 签署位置Y坐标
16
+ # * width [Float] 印章展现高度
17
+ #
18
+ # @return [ Hash ] 结果集
19
+ # * errCode [Integer] 错误码
20
+ # * msg [String] 错误信息
21
+ # * errShow [Boolean] 错误信息是否显示
22
+ # * signServiceId [String] 签署记录id
23
+ # * stream [String] 签署后的文件base64
24
+ #
25
+ def merchant_sign(file_stream, sign_type, seal_position_info)
26
+ path = "tech-sdkwrapper/timevale/sign/selfStreamSign"
27
+
28
+ params = {
29
+ :file => file_stream,
30
+ :signType => sign_type,
31
+ :signPos => seal_position_info.to_json,
32
+ }
33
+
34
+ KuaiJieQian::Http.post(@config[:host], @config[:project_config][:projectId], path, params, nil)
35
+ end
36
+ #
37
+ # 平台自身签署摘要(本地)
38
+ # @param file_info [Hash]
39
+ # * srcPdfFile [String] 待签署PDF文档本地路径
40
+ # * dstPdfFile [String] 签署后PDF文档本地路径
41
+ # * fileName [String] 文档名称
42
+ # * ownerPassword [String] 文档编辑密码
43
+ # @param sign_type [String] 签章类型,Single(单页签章)、Multi(多页签章)、Edges(签骑缝章)、Key(关键字签章)
44
+ # @param sign_pos [String] 签章信息
45
+ # * pos_page [String] 签署页码, 若为多页签章,支持页码格式“1-3,5,8“, 坐标定位时不可空
46
+ # * pos_type [Integer] 默认0(若为关键字定位,签章类型(signType)必须指定为关键字定位才生效)
47
+ # * key [String] 关键字
48
+ # * pos_x [Float] 签署位置X坐标
49
+ # * pos_y [Float] 签署位置Y坐标
50
+ # * width [Float] 印章展现高度
51
+ #
52
+ # @return [ Hash ] 结果集
53
+ # * errCode [Integer] 错误码
54
+ # * msg [String] 错误信息
55
+ # * errShow [Boolean] 错误信息是否显示
56
+ # * signServiceId [String] 签署记录id
57
+ #
58
+ def merchant_sign_with_file(file_info, sign_type, sign_pos)
59
+ path = "tech-sdkwrapper/timevale/sign/selfFileSign"
60
+
61
+ params = {
62
+ :signPos => sign_pos,
63
+ :signType => sign_type,
64
+ :file => file_info,
65
+ }
66
+
67
+ KuaiJieQian::Http.post(@config[:host], @config[:project_config][:projectId], path, params)
68
+ end
69
+
70
+ end # end module
71
+ end
72
+ end
@@ -0,0 +1,85 @@
1
+ # coding: utf-8
2
+
3
+ module KuaiJieQian
4
+ module ClientMethod
5
+ module UserRegister
6
+ #
7
+ # 平台用户注册,生成签章
8
+ # @param type [String] 用户类型, person/company
9
+ # @param name [String] 用户名
10
+ # @param id [String] 个人:用户证件号/护照号,公司:组织机构代码、工商注册号或者统一社会信用代码
11
+ # @param color [String] 生成印章的颜色,RED(红色)、BLACK(黑色)、BLUE(蓝色)
12
+ # @param template_type [String] 印章模板类型
13
+ # @param reg_type [String] 公司类型。NORMAL(组织机构代码)、MERGE(社会信用代码)、REGCODE(工商注册号),默认NORMAL
14
+ #
15
+ # @return [ Hash ] 结果集
16
+ # * account_id [String] 账户标识
17
+ # * seal_data [String] 电子印章图片base64数据
18
+ #
19
+ def user_register(type, name, id, color, template_type, reg_type="NORMAL")
20
+ if "person" == type
21
+ account_id = create_person_account(name, id)
22
+ seal_data = create_person_seal(account_id, color, template_type)
23
+ elsif "company" == type
24
+ account_id = create_company_account(name, id, reg_type)
25
+ seal_data = create_company_seal(account_id, color, template_type)
26
+ else
27
+ raise "type 错误"
28
+ end
29
+
30
+ return { :account_id => account_id, :seal_data => seal_data}
31
+ end
32
+
33
+
34
+ private
35
+
36
+ # 创建个人用户账号
37
+ def create_person_account(user_name, id)
38
+ path = "tech-sdkwrapper/timevale/account/addPerson"
39
+ params = {
40
+ "name": user_name,
41
+ "idNo": id
42
+ }
43
+ account_data = KuaiJieQian::Http.post(@config[:host], @config[:project_config][:projectId], path, params)
44
+ return account_data[:accountId]
45
+ end
46
+
47
+ #创建个人用户印章
48
+ def create_person_seal(account_id, color, template_type)
49
+ path = "tech-sdkwrapper/timevale/seal/addPersonSeal"
50
+ params = {
51
+ "accountId": account_id,
52
+ "color": color,
53
+ "templateType": template_type
54
+ }
55
+ seal_data = KuaiJieQian::Http.post(@config[:host], @config[:project_config][:projectId], path, params)
56
+ return seal_data[:sealData]
57
+ end
58
+
59
+ #创建企业用户账号
60
+ def create_company_account(name, id, reg_type)
61
+ path = "tech-sdkwrapper/timevale/account/addOrganize"
62
+ params = {
63
+ "name": name ,
64
+ "organCode": id,
65
+ "regType": reg_type
66
+ }
67
+ account_data = KuaiJieQian::Http.post(@config[:host], @config[:project_config][:projectId], path, params)
68
+ return account_data[:accountId]
69
+ end
70
+
71
+ #创建企业用户印章
72
+ def create_company_seal(account_id, color, template_type)
73
+ path = "tech-sdkwrapper/timevale/seal/addOrganizeSeal"
74
+ params = {
75
+ "accountId": account_id,
76
+ "color": color,
77
+ "templateType": template_type
78
+ }
79
+ seal_data = KuaiJieQian::Http.post(@config[:host], @config[:project_config][:projectId], path, params)
80
+ return seal_data[:sealData]
81
+ end
82
+
83
+ end # end module
84
+ end
85
+ end
@@ -0,0 +1,59 @@
1
+ # coding: utf-8
2
+
3
+ module KuaiJieQian
4
+ module ClientMethod
5
+ module UserSign
6
+ #
7
+ # 平台用户签署摘要(文件流)
8
+ # @param account_id [String] 签署账户标识
9
+ # @param seal_data [String] 印章图片base64
10
+ # @param file_stream [file] 文件流
11
+ # @param sign_type [String] 签章类型,Single(单页签章)、Multi(多页签章)、Edges(签骑缝章)、Key(关键字签章)
12
+ # @param seal_position_info [hash] 签章信息
13
+ # * pos_page [String] 签署页码, 若为多页签章,支持页码格式“1-3,5,8“, 坐标定位时不可空
14
+ # * pos_type [Integer] 默认0(若为关键字定位,签章类型(signType)必须指定为关键字定位才生效)
15
+ # * key [String] 关键字
16
+ # * pos_x [Float] 签署位置X坐标
17
+ # * pos_y [Float] 签署位置Y坐标
18
+ # * width [Float] 印章展现高度
19
+ #
20
+ # @return [ Hash ] 结果集
21
+ # * errCode [Integer] 错误码
22
+ # * msg [String] 错误信息
23
+ # * errShow [Boolean] 错误信息是否显示
24
+ # * signServiceId [String] 签署记录id
25
+ # * stream [String] 签署后的文件base64
26
+ #
27
+ def user_sign(account_id, seal_data, file_stream, sign_type, seal_position_info)
28
+ path = "tech-sdkwrapper/timevale/sign/userStreamSign"
29
+
30
+ params = {
31
+ "accountId": account_id,
32
+ "sealData": seal_data,
33
+ "file": file_stream,
34
+ "signType": sign_type,
35
+ "signPos": seal_position_info.to_json
36
+ }
37
+
38
+ KuaiJieQian::Http.post(@config[:host], @config[:project_config][:projectId], path, params, nil)
39
+
40
+ end
41
+
42
+ def user_sign_with_file(account_id, seal_data, file_info, sign_type, sign_pos)
43
+ path = "tech-sdkwrapper/timevale/sign/userFileSign"
44
+
45
+ params = {
46
+ "accountId": account_id,
47
+ "sealData": seal_data,
48
+ "file": file_info,
49
+ "signType": sign_type,
50
+ "signPos": sign_pos
51
+ }
52
+
53
+ KuaiJieQian::Http.post(@config[:host], @config[:project_config][:projectId], path, params)
54
+
55
+ end
56
+
57
+ end # end module
58
+ end
59
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+
3
+ module KuaiJieQian
4
+ module Http
5
+
6
+ def self.post(host, project_id, path, params, content_type='application/json')
7
+ final_url = "#{host}/#{path}"
8
+ header = {
9
+ "X-timevale-mode" => "package",
10
+ "X-timevale-project-id" => project_id,
11
+ "X-timevale-signature-algorithm" => "hmac-sha256",
12
+ }.merge({'Content-Type' => content_type})
13
+
14
+ if "application/json" == content_type
15
+ request_body = params.to_json
16
+ else
17
+ request_body = params
18
+ end
19
+
20
+ KuaiJieQian.logger.info "post [#{final_url}] with header: [#{header}], params: [#{params}]"
21
+
22
+ response = RestClient.post(final_url, request_body, header)
23
+
24
+ KuaiJieQian.logger.info "post [#{final_url}] got result: [#{response}]\n"
25
+
26
+ begin
27
+ res = Utils.symbolize_keys(JSON.parse(response))
28
+ rescue
29
+ raise "post [#{final_url}] 解析结果出错"
30
+ end
31
+
32
+ KuaiJieQian.logger.info "res: [#{res}]\n"
33
+ res
34
+ end
35
+
36
+ end # end module
37
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+
3
+ module KuaiJieQian
4
+ module Logger
5
+
6
+ def logger
7
+ @logger ||= default_logger
8
+ end
9
+
10
+ def default_logger
11
+ _logger = ::Logger.new(STDOUT)
12
+ _logger.level = ::Logger::INFO
13
+ _logger
14
+ end
15
+
16
+ def logger=(log)
17
+ @logger = (log ? log : ::Logger.new('/dev/null'))
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ # coding: utf-8
2
+
3
+ module KuaiJieQian
4
+ class Railtie < ::Rails::Railtie
5
+ initializer "KuaiJieQian.logger" do
6
+ KuaiJieQian.logger = Rails.logger
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+
3
+ module KuaiJieQian
4
+ module Utils
5
+ #
6
+ # 把 hash 中的 key,都转化为 symbol 类型
7
+ # @param hash [Hash] 需要更改的 hash
8
+ #
9
+ # @return [Hash] 更改后的 hash
10
+ #
11
+ def self.symbolize_keys(hash)
12
+ new_hash = {}
13
+ hash.each do |key, value|
14
+ new_hash[(key.to_sym rescue key) || key] = value
15
+ end
16
+ new_hash
17
+ end
18
+
19
+ def self.html_to_pdf(html_file_stream)
20
+ kit = PDFKit.new(html_file_stream)
21
+ kit.to_pdf
22
+ end
23
+
24
+ def self.pdf_to_png(file)
25
+ pdf = Grim.reap(file)
26
+ png = pdf[0].save(file.split(".").first + '.png',
27
+ {:quality => 90, :alpha => "remove", :colorspace => "RGB"}
28
+ )
29
+
30
+ end
31
+
32
+ end # end module
33
+ end
@@ -0,0 +1,3 @@
1
+ module KuaiJieQian
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ require 'logger'
3
+ require "json"
4
+ require "rest-client"
5
+ require "pdfkit"
6
+ require "base64"
7
+ require "grim"
8
+ require 'RMagick'
9
+
10
+ require "kuai_jie_qian/version"
11
+ require "kuai_jie_qian/logger"
12
+ require "kuai_jie_qian/utils"
13
+ require "kuai_jie_qian/http"
14
+
15
+ # 自动加载所有 client api
16
+ Dir["#{File.dirname(__FILE__)}/kuai_jie_qian/client_method/**/*.rb"].each { |file| require file }
17
+
18
+ require "kuai_jie_qian/client"
19
+
20
+ module KuaiJieQian
21
+ # Your code goes here...
22
+ extend KuaiJieQian::Logger
23
+ end
24
+
25
+ require 'kuai_jie_qian/railtie' if defined?(::Rails)
data/tmp/.DS_Store ADDED
Binary file
data/tmp/.keep ADDED
File without changes
metadata ADDED
@@ -0,0 +1,220 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kuai_jie_qian
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - tony
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '9.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '9.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faker
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.8'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 1.8.4
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '1.8'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 1.8.4
89
+ - !ruby/object:Gem::Dependency
90
+ name: rest-client
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '2.0'
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 2.0.2
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '2.0'
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 2.0.2
109
+ - !ruby/object:Gem::Dependency
110
+ name: pdfkit
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: 0.8.2
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: 0.8.2
123
+ - !ruby/object:Gem::Dependency
124
+ name: wkhtmltopdf-binary
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: 0.12.3.1
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: 0.12.3.1
137
+ - !ruby/object:Gem::Dependency
138
+ name: grim
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ - !ruby/object:Gem::Dependency
152
+ name: rmagick
153
+ requirement: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: 2.16.0
158
+ type: :development
159
+ prerelease: false
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - "~>"
163
+ - !ruby/object:Gem::Version
164
+ version: 2.16.0
165
+ description: 签宝之快捷签接口
166
+ email:
167
+ - tony@omniaccount.com
168
+ executables: []
169
+ extensions: []
170
+ extra_rdoc_files: []
171
+ files:
172
+ - ".gitignore"
173
+ - ".rspec"
174
+ - ".travis.yml"
175
+ - CODE_OF_CONDUCT.md
176
+ - Gemfile
177
+ - LICENSE.txt
178
+ - README.md
179
+ - Rakefile
180
+ - bin/console
181
+ - bin/setup
182
+ - kuai_jie_qian.gemspec
183
+ - lib/kuai_jie_qian.rb
184
+ - lib/kuai_jie_qian/client.rb
185
+ - lib/kuai_jie_qian/client_method/merchant_sign.rb
186
+ - lib/kuai_jie_qian/client_method/user_register.rb
187
+ - lib/kuai_jie_qian/client_method/user_sign.rb
188
+ - lib/kuai_jie_qian/http.rb
189
+ - lib/kuai_jie_qian/logger.rb
190
+ - lib/kuai_jie_qian/railtie.rb
191
+ - lib/kuai_jie_qian/utils.rb
192
+ - lib/kuai_jie_qian/version.rb
193
+ - tmp/.DS_Store
194
+ - tmp/.keep
195
+ homepage: https://github.com/omniaccountcorp/kuai_jie_qian
196
+ licenses:
197
+ - MIT
198
+ metadata:
199
+ allowed_push_host: https://rubygems.org
200
+ post_install_message:
201
+ rdoc_options: []
202
+ require_paths:
203
+ - lib
204
+ required_ruby_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ required_rubygems_version: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ requirements: []
215
+ rubyforge_project:
216
+ rubygems_version: 2.6.14
217
+ signing_key:
218
+ specification_version: 4
219
+ summary: E签宝之快捷签
220
+ test_files: []