fadada 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e33af833d5f5c2548f193f9ef47bc0c46e8a3f4f74c96115162284eb76452cc4
4
+ data.tar.gz: ef6b7df502b0b8bef1f74dc21cc115b47c33d4b824068f10c96458a2f1bd1621
5
+ SHA512:
6
+ metadata.gz: 7452866a9181a3ddc390a510a78ef5b47fa68bc039b3447d82f60b9f3938d9443a048264748c4b42e618257f52dbd5cd27bf139c6182209d42012104b73ab906
7
+ data.tar.gz: 8f8bea3062babea4c7b95552ebd173c5e1aafac2e860eebe7efbd76ecf4d0492f1d6deba8197853c20dd804678af39b9784b52b654717738cceb16fc4aaa3a03
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
File without changes
@@ -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 402399938@qq.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,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fadada.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 wangrui
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.
@@ -0,0 +1,45 @@
1
+ # 法大大实名存证电子合同Ruby SDK
2
+
3
+ ## 法大大电子合同分为实名认证版和实名存证版
4
+
5
+ 1. `实名认证`版中客户的实名认证是在法大大侧,需要人工审核
6
+ 2. `实名存证`版中客户的实名认证是在调用方侧,实时性高
7
+
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'fadada'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install fadada
24
+
25
+ ## Usage
26
+
27
+ $ rails generate fadada:install
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ 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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fadada. 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.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
42
+
43
+ ## Code of Conduct
44
+
45
+ Everyone interacting in the Fadada project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/fadada/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fadada"
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__)
@@ -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,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "fadada/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fadada"
8
+ spec.version = Fadada::VERSION
9
+ spec.authors = ["wangrui"]
10
+ spec.email = ["402399938@qq.com"]
11
+
12
+ spec.summary = %q{法大大实名认证电子合同}
13
+ spec.description = %q{法大大实名认证电子合同Ruby SDK}
14
+ spec.homepage = "https://github.com/wangrui438/fadada"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/wangrui438/fadada"
24
+ spec.metadata["changelog_uri"] = "https://github.com/wangrui438/fadada/blob/master/CHANGELOG.md"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 2.0"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency 'httparty', '~> 0.17.0'
42
+ end
@@ -0,0 +1,45 @@
1
+ # 法大大实名认证接口调用顺序(二)
2
+
3
+ file = File.open('xxx')
4
+
5
+ # 个人实名信息存证
6
+ options = {
7
+ customer_id: customer_id,
8
+ preservation_name: '个人实名信息存证', # 存证名称
9
+ preservation_data_provider: 'XX网络科技有限公司', # 存证提供方
10
+ name: '张三',
11
+ idcard: 'xxx', # 证件号
12
+ idcard_positive_file: '', # 证件照正面
13
+ idcard_negative_file: '', # 证件照反面
14
+ verified_time: DateTime.now.strftime('%Y-%m-%d %H:%M:%S'),
15
+ verified_type: 'Z', # 实名认证类型,Z 其他
16
+ cert_flag: '0'
17
+ }
18
+ evidence_no = Fadada::Authentication.person_deposit(options)
19
+
20
+ # 企业实名信息存证
21
+ options = {
22
+ customer_id: customer_id,
23
+ preservation_name: '企业实名信息存证',
24
+ preservation_data_provider: 'XX网络科技有限公司',
25
+ company_name: 'XX公司',
26
+ document_type: '1', # 证件类型 1:三证合一 2:旧版营业执照
27
+ credit_code: '91827364817263', # 统一社会信用代码
28
+ credit_code_file: file, # 统一社会信用代码电子版
29
+ verified_time: DateTime.now.strftime('%Y-%m-%d %H:%M:%S'), # 实名时间
30
+ verified_mode: '1', # 实名认证方式 1:授权委托书 2:银行对公打款
31
+ power_attorney_file: file, # 授权委托书电子版
32
+ company_principal_type: '1', # 企业负责人身份:1. 法人,2 代理人
33
+ company_principal_verified_msg: { # 企业负责人实名存证信息
34
+ customer_id: '671C6CC93D9F4C0630911735795666A2',
35
+ preservation_name: '个人实名信息存证',
36
+ preservation_data_provider: 'XX网络科技有限公司', # 存证提供方
37
+ name: '张三',
38
+ idcard: 'xxx', # 证件号
39
+ verified_time: DateTime.now.strftime('%Y-%m-%d %H:%M:%S'),
40
+ verified_type: 'Z' # 实名认证类型,Z 其他
41
+ }.to_json,
42
+ transaction_id: '127635172637217', # 交易号
43
+ cert_flag: '0'
44
+ }
45
+ evidence_no = Fadada::Authentication.company_deposit(options)
@@ -0,0 +1,5 @@
1
+ # 法大大实名认证接口调用顺序(三)
2
+ # 编号证书申请
3
+ customer_id = 'xxx' # 客户编号
4
+ evidence_no = 'xxx' # 存证编号
5
+ cert = Fadada::Certificate.apply(customer_id: customer_id, evidence_no: evidence_no)
@@ -0,0 +1,57 @@
1
+ # 法大大实名认证接口调用顺序(五)
2
+
3
+ contract_id = "19273648172364987165"
4
+ doc_title = "这是一个测试合同"
5
+ contract_file = File.open('xxx')
6
+
7
+ # 上传合同
8
+ options = {
9
+ contract_id: contract_id, # 合同编号
10
+ doc_title: doc_title,
11
+ file: contract_file
12
+ }
13
+ Fadada::Contract.upload_doc(options)
14
+
15
+ # 上传合同模板
16
+ options = {
17
+ template_id: '9769867876876876',
18
+ file: contract_file
19
+ }
20
+ Fadada::Contract.upload_template(options)
21
+
22
+ # 模板填充
23
+ options = {
24
+
25
+ }
26
+ Fadada::Contract.generate(options)
27
+
28
+ # 自动签署合同
29
+ options = {
30
+ transaction_id: 'A1028374019287342342',
31
+ contract_id: contract_id,
32
+ doc_title: doc_title,
33
+ }
34
+ Fadada::Contract.auto_sign(options)
35
+
36
+ # 手动签署合同
37
+ options = {
38
+ transaction_id: 'B1028374019287341114',
39
+ contract_id: contract_id,
40
+ customer_id: '926064BA49FB4EAA0F1323A0B000DA22',
41
+ doc_title: doc_title,
42
+ sign_keyword: '甲方(盖章):',
43
+ keyword_strategy: '2',
44
+ customer_name: 'xx',
45
+ customer_ident_no: 'xx',
46
+ return_url: 'http://baidu.com'
47
+ }
48
+ Fadada::Contract.sign(options)
49
+
50
+ # 查看合同
51
+ Fadada::Contract.show(contract_id)
52
+
53
+ # 下载合同
54
+ Fadada::Contract.download(contract_id)
55
+
56
+ # 合同归档
57
+ Fadada::Contract.filing(contract_id)
@@ -0,0 +1,6 @@
1
+ # 法大大实名认证接口调用顺序(一)
2
+ # 个人开户
3
+ customer_id = Fadada::Account.person_register('N12345678901')
4
+
5
+ # 企业开户
6
+ customer_id = Fadada::Account.company_register('N09876543211')
@@ -0,0 +1,10 @@
1
+ # 法大大实名认证接口调用顺序(四)
2
+ # 上传签章
3
+ customer_id = '' # 客户编号
4
+ path = 'xx' # 签章图片 base64
5
+ sign = Fadada::Signature.upload(customer_id: customer_id, image: path, type: 'path')
6
+
7
+ # 自定义签章
8
+ customer_id = '' # 客户编号
9
+ content = '测试测试' # 印章展示的内容,可以是企业名称或者客户名称
10
+ sign = Fadada::Signature.custom(customer_id: customer_id, content: content)
@@ -0,0 +1,25 @@
1
+ require "fadada/version"
2
+ require "fadada/configuration"
3
+ require "fadada/http_client"
4
+
5
+ # resources
6
+ require "fadada/account"
7
+ require "fadada/authentication"
8
+ require "fadada/certificate"
9
+ require "fadada/contract"
10
+ require "fadada/signature"
11
+
12
+ # exceptions
13
+ require "fadada/api_service_exception"
14
+
15
+ module Fadada
16
+ class << self
17
+ def setup
18
+ yield config
19
+ end
20
+
21
+ def config
22
+ @config ||= Configuration.new
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,39 @@
1
+ # 法大大账户相关接口
2
+ module Fadada
3
+ class Account
4
+
5
+ # 注册账号
6
+ #
7
+ # 此接口针对接入平台已有账号体系,判断 open_id 是否存在
8
+ # 存在则返回对应账号,否则随机生成账号并返回账号
9
+ #
10
+ # open_id => 用户在接入方的唯一标识,length <= 64
11
+ #
12
+ # 返回 法大大的账号
13
+ def self.person_register(open_id)
14
+ options = {
15
+ open_id: open_id,
16
+ account_type: 1 # 账户类型,1 个人;2 企业,默认 1
17
+ }
18
+ response = Fadada::HttpClient.request(:post, 'account_register.api', options)
19
+ response['data']
20
+ end
21
+
22
+ # 注册账号
23
+ #
24
+ # 此接口针对接入平台已有账号体系,判断 open_id 是否存在
25
+ # 存在则返回对应账号,否则随机生成账号并返回账号
26
+ #
27
+ # open_id => 用户在接入方的唯一标识,length <= 64
28
+ #
29
+ # 返回 法大大的账号
30
+ def self.company_register(open_id)
31
+ options = {
32
+ open_id: open_id,
33
+ account_type: 2 # 账户类型,1 个人;2 企业,默认 1
34
+ }
35
+ response = Fadada::HttpClient.request(:post, 'account_register.api', options)
36
+ response['data']
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,12 @@
1
+ # 法大大接口层面异常类
2
+ module Fadada
3
+ class ApiServiceException < StandardError
4
+ attr_reader :code, :message
5
+
6
+ def initialize(code, message)
7
+ @code = code
8
+ @message = message
9
+ super(message)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,47 @@
1
+ # 法大大实名认证相关接口
2
+ # 实名认证分为在调用方处做实名认证和在法大大处做实名认证
3
+ # 在调用方处做实名认证需要调用法大大的实名信息存证接口
4
+ # 实名存证方式有以下两种:
5
+ # 1. 实名信息哈希存证是将用户的信息放在一份文档里将这份文件进行sha256算法,将文件hash值传入到法大大这边进行存证。
6
+ # 2.(企业 or 个人)实名信息存证是将对应的信息以明文的方式通过参数传输到法大大这边进行存证。
7
+ # 建议使用方式2实名信息存证,资料尽量全一些,这是对调用方有利的。资料越齐全,以后举证越容易被采信
8
+ module Fadada
9
+ class Authentication
10
+
11
+ # 个人实名信息存证
12
+ def self.person_deposit(params = {})
13
+ _basic = %i(bank_essential_factor cert_flag customer_id document_type idcard live_detection mobile
14
+ mobile_and_bank_essential_factor mobile_essential_factor name preservation_data_provider preservation_desc
15
+ preservation_name public_security_essential_factor verified_time verified_type)
16
+ _normal = %i(idcard_positive_file idcard_negative_file live_detection_file)
17
+ options = params.slice(*(_basic + _normal))
18
+ digest_params = { _params: params.slice(*_basic) }
19
+ response = Fadada::HttpClient.request(:post, 'person_deposit.api', options, digest_params)
20
+ response['data']
21
+ end
22
+
23
+ # 企业实名信息存证
24
+ def self.company_deposit(params = {})
25
+ _basic = %i(amount_or_random_code cert_flag company_name company_principal_type company_principal_verified_msg
26
+ credit_code customer_bank customer_bank_account customer_branch_bank customer_id document_type legal_idcard
27
+ legal_name licence organization pay_type preservation_data_provider preservation_desc preservation_name
28
+ public_bank_account public_branch_bank transaction_id user_back_fill_amount_or_random_code verified_mode verified_time)
29
+ _normal = %i(credit_code_file licence_file organization_file power_attorney_file idcard_positive_file idcard_negative_file
30
+ live_detection_file)
31
+ options = params.slice(*(_basic + _normal))
32
+ digest_params = { _params: params.slice(*_basic) }
33
+ response = Fadada::HttpClient.request(:post, 'company_deposit.api', options, digest_params)
34
+ response['data']
35
+ end
36
+
37
+ # 获取企业实名认证地址
38
+ def self.company_url
39
+
40
+ end
41
+
42
+ # 获取个人实名认证地址
43
+ def self.person_url
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,19 @@
1
+ # 法大大证书相关接口
2
+ module Fadada
3
+ class Certificate
4
+
5
+ # 编号证书申请
6
+ # 调用此接口可以给相关账号颁发编号证书
7
+ #
8
+ # customer_id => 客户编号 注册账号时返回
9
+ # evidence_no => 存证编号 实名信息存证时返回
10
+ #
11
+ def self.apply(customer_id:, evidence_no:)
12
+ options = {
13
+ customer_id: customer_id,
14
+ evidence_no: evidence_no
15
+ }
16
+ response = Fadada::HttpClient.request(:post, 'apply_client_numcert.api', options)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,66 @@
1
+ module Fadada
2
+ class Configuration
3
+ # 接口地址
4
+ def server
5
+ @server ||= 'https://testapi.fadada.com:8443/api/'
6
+ end
7
+
8
+ def server=(server)
9
+ @server = server
10
+ end
11
+
12
+ # app_id
13
+ def app_id
14
+ @app_id
15
+ end
16
+
17
+ def app_id=(app_id)
18
+ @app_id = app_id
19
+ end
20
+
21
+ # app_secret
22
+ def app_secret
23
+ @app_secret
24
+ end
25
+
26
+ def app_secret=(app_secret)
27
+ @app_secret = app_secret
28
+ end
29
+
30
+ # 平台方客户编号
31
+ def customer_id
32
+ @customer_id
33
+ end
34
+
35
+ def customer_id=(customer_id)
36
+ @customer_id = customer_id
37
+ end
38
+
39
+ # 平台方客户名称
40
+ def customer_name
41
+ @customer_name
42
+ end
43
+
44
+ def customer_name=(customer_name)
45
+ @customer_name = customer_name
46
+ end
47
+
48
+ # logger
49
+ def logger
50
+ @logger ||= Logger.new(STDOUT)
51
+ end
52
+
53
+ def logger=(logger)
54
+ @logger = logger
55
+ end
56
+
57
+ # logger format
58
+ def logger_format
59
+ @logger_format ||= :curl
60
+ end
61
+
62
+ def logger_format=(logger_format)
63
+ @logger_format = logger_format.to_sym
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,100 @@
1
+ # 法大大合同相关接口
2
+ module Fadada
3
+ class Contract
4
+ # 上传合同
5
+ # 接入平台生成 PDF 文档后通过此接口将文档传输到法大大,供签署时使用。
6
+ # 非 PDF 文档请使用合同模板功能(参考合同模板传输接口和合同生成接口)
7
+ # 该接口只支持PDF文件
8
+ def self.upload_doc(params = {})
9
+ options = params.slice(:contract_id, :doc_title, :doc_url, :file).merge(doc_type: '.pdf')
10
+ digest_params = { _params: params.slice(:contract_id) }
11
+ response = Fadada::HttpClient.request(:post, 'uploaddocs.api', options, digest_params)
12
+ end
13
+
14
+ # 上传合同模板
15
+ # 此接口与模板填充接口配合使用,接入方预先将制作好的 PDF 模板通过此接口上传到法大大,
16
+ # 后续如需要签署合同时只需要将需填充的内容通过合同生成接口传入,即可生成合同供签署操作,提高效率,
17
+ # 并可防止接入方自己生成的合同出现一些不兼容或文档签署异常等情况。
18
+ def self.upload_template(params = {})
19
+ options = params.slice(:template_id, :doc_url, :file)
20
+ digest_params = { _params: params.slice(:template_id) }
21
+ response = Fadada::HttpClient.request(:post, 'uploadtemplate.api', options, digest_params)
22
+ end
23
+
24
+ # 模板填充
25
+ # 将需填充的内容通过模板填充接口传入,即可生成合同供签署操作,提高效率,
26
+ # 并可防止接入方自己生成的合同出现一些不兼容或文档签署异常等情况。
27
+ def self.generate(params = {})
28
+ _basic = %i(template_id contract_id)
29
+ _extend = %i(parameter_map)
30
+ _normal = %i(doc_title font_size font_type dynamic_tables)
31
+ options = params.slice(*(_basic + _extend + _normal))
32
+ digest_params = { _params: params.slice(*_basic), _extend_params: params.slice(*_extend) }
33
+ response = Fadada::HttpClient.request(:post, 'generate_contract.api', options, digest_params)
34
+ end
35
+
36
+ # 自动签署合同
37
+ # 自动签接口不需要用户亲自操作,当接入平台调用此接口时,就会在指定的电子合同上签上指定用户的电子章,
38
+ # 省略了用户交互的步骤。因此如果需要使用此接口的能力, 需要接入平台联系法大大商务签署补充协议。
39
+ #
40
+ # 默认情况下只需要传入如下参数
41
+ # {
42
+ # transaction_id: '',
43
+ # contract_id: '',
44
+ # doc_title: ''
45
+ # }
46
+ #
47
+ def self.auto_sign(params = {})
48
+ _options = {
49
+ customer_id: Fadada::config.customer_id, # 接入平台客户编号
50
+ client_role: '1', # 客户角色 1-接入平台
51
+ position_type: '0', # 定位类型 0-关键字(默认)
52
+ sign_keyword: Fadada::config.customer_name, # 定位关键字,默认按照接入平台方的名称定位
53
+ keyword_strategy: '2', # 关键字签章策略 2:最后一个关键字签章;
54
+ }
55
+ _basic = %i(customer_id)
56
+ _md5 = %i(transaction_id)
57
+ _normal = %i(contract_id client_role doc_title position_type sign_keyword keyword_strategy signature_positions notify_url)
58
+ options = _options.merge(params.slice(*(_basic + _md5 + _normal)))
59
+ digest_params = { _params: options.slice(*_basic), _md5_params: options.slice(*_md5) }
60
+ response = Fadada::HttpClient.request(:post, 'extsign_auto.api', options, digest_params)
61
+ end
62
+
63
+ # 手动签署合同
64
+ # 该接口为页面接口,接入方平台可以在合适的业务场景嵌入该接口链接,引导客户至法大大进行文档签署
65
+ # (比如可以在接入方平台网站上放置一个按钮,该按钮触发跳转至法大大或将法大大签章页面嵌入接入方流程)。
66
+ # 法大大根据浏览器 UA 信息,自动加载签 章界面对应的 PC web 版本或移动 HTML5 版本。
67
+ # 用户在法大大的签署页面中进行签署操作。
68
+ def self.sign(params = {})
69
+ _basic = %i(customer_id)
70
+ _md5 = %i(transaction_id)
71
+ _normal = %i(contract_id doc_title sign_keyword keyword_strategy return_url notify_url customer_mobile customer_name customer_ident_no)
72
+ options = params.slice(*(_basic + _md5 + _normal))
73
+ digest_params = { _params: params.slice(*_basic), _md5_params: params.slice(*_md5) }
74
+ response = Fadada::HttpClient.request(:get, 'extsign.api', options, digest_params)
75
+ end
76
+
77
+ # 合同查看
78
+ # 页面接口,返回签署页面,根据浏览器 UA 信息返回 pc 或 H5 页面.
79
+ def self.show(contract_id)
80
+ options = { contract_id: contract_id }
81
+ response = Fadada::HttpClient.request(:get, 'viewContract.api', options)
82
+ end
83
+
84
+ # 合同下载
85
+ # 通过合同编号下载文档(PDF 格式),可通过 Content-Length 取文件大小。
86
+ # 正常时直接返回 PDF 文档(MIME:application/pdf),异常时返回 JSON 报文
87
+ def self.download(contract_id)
88
+ options = { contract_id: contract_id }
89
+ response = Fadada::HttpClient.request(:get, 'downLoadContract.api', options)
90
+ end
91
+
92
+ # 合同归档
93
+ # 接入平台更新合同签署状态为-签署完成,法大大将把合同所有相关操作记录进行归档存证。
94
+ # 归档后将不能再对文档再进行签署操作。
95
+ def self.filing(contract_id)
96
+ options = { contract_id: contract_id }
97
+ response = Fadada::HttpClient.request(:post, 'contractFiling.api', options)
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,91 @@
1
+ module Fadada
2
+ class HttpClient
3
+ class << self
4
+ # HTTP 请求
5
+ # digest_params 示例:
6
+ # {
7
+ # _params: { a: 1, b: 2 },
8
+ # _md5_params: { a: 1, b: 2 },
9
+ # _extend_params: { a: 1, b: 2 }
10
+ # }
11
+ #
12
+ def request(method, action, params = {}, digest_params = nil)
13
+ _method = method.to_s.downcase
14
+ _digest_params = digest_params || { _params: params }
15
+ payload = build_basic_params(_digest_params).merge(params)
16
+ if _method == 'post'
17
+ response = HTTParty.post(
18
+ url(action),
19
+ body: payload,
20
+ header: form_header,
21
+ logger: Fadada::config.logger,
22
+ log_format: Fadada::config.logger_format
23
+ ).parsed_response
24
+ hander_exception(response)
25
+ else
26
+ "#{url(action)}?#{URI.encode_www_form(payload)}"
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def url(action)
33
+ Fadada::config.server + action
34
+ end
35
+
36
+ # 处理参数
37
+ def params_transform(options)
38
+ _options = options || {}
39
+ _options.delete_if { |key, value| value.blank? }.sort.map { |k,v| v }.join
40
+ end
41
+
42
+ def form_header
43
+ { 'Content-Type' => 'application/x-www-form-urlencoded;charset=utf8' }
44
+ end
45
+
46
+ # 构建基础请求参数
47
+ def build_basic_params(options)
48
+ _timestamp = DateTime.now.strftime("%Y%m%d%H%M%S")
49
+ {
50
+ app_id: Fadada::config.app_id,
51
+ timestamp: _timestamp,
52
+ v: '2.0',
53
+ msg_digest: digest(_timestamp, options)
54
+ }
55
+ end
56
+
57
+ # 摘要计算
58
+ # Base64(SHA1(app_id + MD5(timestamp + 参数集合1) + SHA1(app_secret + 参数集合) + 参数集合2 ))
59
+ # 示例:
60
+ # options = {
61
+ # _params: { a: 1, b: 2 },
62
+ # _md5_params: { a: 1, b: 2 },
63
+ # _extend_params: { a: 1, b: 2 }
64
+ # }
65
+ #
66
+ # params 需要排序后使用
67
+ #
68
+ def digest(timestamp, options = {})
69
+ _biz_data = Fadada::config.app_secret + params_transform(options[:_params])
70
+ _sha1_biz_data = Digest::SHA1.hexdigest(_biz_data).upcase
71
+ _md5 = Digest::MD5.hexdigest(params_transform(options[:_md5_params]) + timestamp).upcase
72
+ _extend = params_transform(options[:_extend_params])
73
+ _data = Digest::SHA1.hexdigest(::Fadada::config.app_id + _md5 + _sha1_biz_data + _extend).upcase
74
+ Base64.strict_encode64(_data)
75
+ end
76
+
77
+ # 处理异常
78
+ def hander_exception(response)
79
+ code = response['code'].to_s
80
+ return response if code == '1' || code == '1000'
81
+ message = response['msg']
82
+ if %w(0 1004).include?(code)
83
+ message = response['data'] || response['msg']
84
+ elsif code == '2'
85
+ message = '重复请求'
86
+ end
87
+ raise Fadada::ApiServiceException.new(code, message)
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,44 @@
1
+ # 法大大签章相关接口
2
+ module Fadada
3
+ class Signature
4
+ # 签章上传
5
+ # 新增用户签章图片
6
+ #
7
+ # customer_id => 客户编号
8
+ # image => 签章图片地址或者base64图片数据
9
+ # type => image 类型,base64 或者 path
10
+ #
11
+ # 返回签章图片ID
12
+ #
13
+ def self.upload(customer_id:, type: 'base64', image:)
14
+ options = {
15
+ customer_id: customer_id,
16
+ signature_img_base64: type == 'base64' ? image : image_to_base64(image)
17
+ }
18
+ response = Fadada::HttpClient.request(:post, 'add_signature.api', options)
19
+ response['data']
20
+ end
21
+
22
+ # 自定义印章
23
+ # 获取用户自定义签章图片
24
+ #
25
+ # customer_id => 客户编号
26
+ # content => 印章展示的内容,可以是企业名称或者客户名称
27
+ def self.custom(customer_id:, content:)
28
+ options = {
29
+ customer_id: customer_id,
30
+ content: content
31
+ }
32
+ response = Fadada::HttpClient.request(:post, 'custom_signature.api', options)
33
+ response['data']['signature_img_base64']
34
+ end
35
+
36
+ private
37
+
38
+ def self.image_to_base64(path)
39
+ File.open(path, 'rb') do |img|
40
+ Base64.strict_encode64(img.read)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Fadada
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ module Fadada
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def create_initializer_file
6
+ template 'initializer.rb', 'config/initializers/fadada.rb'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ logger = Logger.new(STDOUT)
2
+ Fadada.setup do |config|
3
+ config.server = "https://testapi.fadada.com:8443"
4
+ config.app_id = ""
5
+ config.app_secret = ""
6
+ config.customer_id = "" # 平台方客户编号
7
+ config.customer_name = "" # 平台方客户名称
8
+ config.logger = logger
9
+ config.logger_format = :curl
10
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fadada
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - wangrui
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-19 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
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: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.17.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.17.0
55
+ description: 法大大实名认证电子合同Ruby SDK
56
+ email:
57
+ - 402399938@qq.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CHANGELOG.md
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - fadada.gemspec
72
+ - lib/examples/auth.rb
73
+ - lib/examples/cert.rb
74
+ - lib/examples/contract.rb
75
+ - lib/examples/register.rb
76
+ - lib/examples/sign.rb
77
+ - lib/fadada.rb
78
+ - lib/fadada/account.rb
79
+ - lib/fadada/api_service_exception.rb
80
+ - lib/fadada/authentication.rb
81
+ - lib/fadada/certificate.rb
82
+ - lib/fadada/configuration.rb
83
+ - lib/fadada/contract.rb
84
+ - lib/fadada/http_client.rb
85
+ - lib/fadada/signature.rb
86
+ - lib/fadada/version.rb
87
+ - lib/generators/fadada/install_generator.rb
88
+ - lib/generators/fadada/templates/initializer.rb
89
+ homepage: https://github.com/wangrui438/fadada
90
+ licenses:
91
+ - MIT
92
+ metadata:
93
+ allowed_push_host: https://rubygems.org
94
+ homepage_uri: https://github.com/wangrui438/fadada
95
+ source_code_uri: https://github.com/wangrui438/fadada
96
+ changelog_uri: https://github.com/wangrui438/fadada/blob/master/CHANGELOG.md
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.7.9
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: 法大大实名认证电子合同
117
+ test_files: []