wx_pay 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f7728aa39f6881fdc10e4f9ce5eb0ea4e8f1aa4
4
- data.tar.gz: 06ef45d78a887b2472f7dc3fabe6a32432c18567
3
+ metadata.gz: 509e50b1a6926828e434a63bf8621fd853709ac0
4
+ data.tar.gz: fee8d3226f9576f72209bcc74ed02b514483ecc2
5
5
  SHA512:
6
- metadata.gz: 7724c41f2256d30f2813bc2ab5a70e4917abe6627566e6cd9dd7ad6f9edf849690dfed287c8dd6ad018593fe0ac06a6babf8f83a455bfa8e4abb6fe344b261e7
7
- data.tar.gz: 861bae20ef39e12fcaf639240c2aa3aa039ee7fdf765193bd69a789520ae972d98397b7882b2460ab690387ac6e601900692862be3d661cf09f638c4bdd00af6
6
+ metadata.gz: 448dbfed70032ce996f2ec727f2af69ac2c2d9a0e03ee01baa4ec91a9f8b87c5dbd7340b5c6255fd216d8cb86c508d015c989abee0b3b707783e2ac5de4e54ed
7
+ data.tar.gz: b203b3950ff9663896e8d4cde3ad2042cd525a418be4e4f0bc0978fb00fb5ab3c1a5a42810623f9b9ea25f0533950e9361dab8ca69b5b0d9a699b7a2ac44bf3f
data/lib/wx_pay.rb CHANGED
@@ -8,7 +8,7 @@ module WxPay
8
8
  @debug_mode = true
9
9
 
10
10
  class<< self
11
- attr_accessor :appid, :mch_id, :key, :extra_rest_client_options, :debug_mode
11
+ attr_accessor :appid, :mch_id, :key, :appsecret, :extra_rest_client_options, :debug_mode
12
12
  attr_reader :apiclient_cert, :apiclient_key
13
13
 
14
14
  def set_apiclient_by_pkcs12(str, pass)
@@ -1,10 +1,30 @@
1
1
  require 'rest_client'
2
+ require 'json'
3
+ require 'cgi'
4
+ require 'securerandom'
2
5
  require 'active_support/core_ext/hash/conversions'
3
6
 
4
7
  module WxPay
5
8
  module Service
6
9
  GATEWAY_URL = 'https://api.mch.weixin.qq.com'
7
10
 
11
+ def self.generate_authorize_url(redirect_uri, state = nil)
12
+ state ||= SecureRandom.hex 16
13
+ "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{WxPay.appid}&redirect_uri=#{CGI::escape redirect_uri}&response_type=code&scope=snsapi_base&state=#{state}"
14
+ end
15
+
16
+ def self.authenticate(authorization_code, options = {})
17
+ options = WxPay.extra_rest_client_options.merge(options)
18
+ url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=#{WxPay.appid}&secret=#{WxPay.appsecret}&code=#{authorization_code}&grant_type=authorization_code"
19
+
20
+ ::JSON.parse(RestClient::Request.execute(
21
+ {
22
+ method: :get,
23
+ url: url
24
+ }.merge(options)
25
+ ), quirks_mode: true)
26
+ end
27
+
8
28
  INVOKE_UNIFIEDORDER_REQUIRED_FIELDS = [:body, :out_trade_no, :total_fee, :spbill_create_ip, :notify_url, :trade_type]
9
29
  def self.invoke_unifiedorder(params, options = {})
10
30
  params = {
@@ -193,9 +213,9 @@ module WxPay
193
213
  nonce_str: SecureRandom.uuid.tr('-', '')
194
214
  }.merge(params)
195
215
 
196
- check_required_options(params, ORDER_QUERY_REQUIRED_FIELDS)
197
216
 
198
217
  r = WxPay::Result.new(Hash.from_xml(invoke_remote("#{GATEWAY_URL}/pay/orderquery", make_payload(params), options)))
218
+ check_required_options(params, ORDER_QUERY_REQUIRED_FIELDS)
199
219
 
200
220
  yield r if block_given?
201
221
 
@@ -267,7 +287,7 @@ module WxPay
267
287
  private
268
288
 
269
289
  def check_required_options(options, names)
270
- return if !WxPay.debug_mode?
290
+ return unless WxPay.debug_mode?
271
291
  names.each do |name|
272
292
  warn("WxPay Warn: missing required option: #{name}") unless options.has_key?(name)
273
293
  end
@@ -1,3 +1,3 @@
1
1
  module WxPay
2
- VERSION = "0.11.0"
2
+ VERSION = "0.12.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wx_pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jasl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-13 00:00:00.000000000 Z
11
+ date: 2016-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client