Commit 5a77d2b526167477318e40216d4b0a06336c35a8
1 parent
4114e50a
Exists in
master
add functions easy to set apiclient
Showing
1 changed file
with
17 additions
and
0 deletions
Show diff stats
lib/wx_pay.rb
1 | require 'wx_pay/result' | 1 | require 'wx_pay/result' |
2 | require 'wx_pay/sign' | 2 | require 'wx_pay/sign' |
3 | require 'wx_pay/service' | 3 | require 'wx_pay/service' |
4 | +require 'openssl' | ||
4 | 5 | ||
5 | module WxPay | 6 | module WxPay |
6 | @rest_client_options = {} | 7 | @rest_client_options = {} |
7 | 8 | ||
8 | class<< self | 9 | class<< self |
9 | attr_accessor :appid, :mch_id, :key, :apiclient_cert, :apiclient_key, :extra_rest_client_options | 10 | attr_accessor :appid, :mch_id, :key, :apiclient_cert, :apiclient_key, :extra_rest_client_options |
11 | + | ||
12 | + def set_apiclient_by_pkcs12(str, pass) | ||
13 | + pkcs12 = OpenSSL::PKCS12.new(str, pass) | ||
14 | + @apiclient_cert = pkcs12.certificate | ||
15 | + @apiclient_key = pkcs12.key | ||
16 | + | ||
17 | + pkcs12 | ||
18 | + end | ||
19 | + | ||
20 | + def apiclient_cert=(cert) | ||
21 | + @apiclient_cert = OpenSSL::X509::Certificate.new(cert) | ||
22 | + end | ||
23 | + | ||
24 | + def apiclient_key=(key) | ||
25 | + @apiclient_key = OpenSSL::PKey::RSA.new(key) | ||
26 | + end | ||
10 | end | 27 | end |
11 | end | 28 | end |