Commit c7dc42e33a98741edc8680f02f4b9f50cec994de
Committed by
GitHub
Exists in
master
Merge pull request #97 from ScorpiusZ/master
Add Multi Account Support for authenticate
Showing
1 changed file
with
16 additions
and
2 deletions
Show diff stats
lib/wx_pay/service.rb
... | ... | @@ -17,11 +17,18 @@ module WxPay |
17 | 17 | |
18 | 18 | def self.authenticate(authorization_code, options = {}) |
19 | 19 | options = WxPay.extra_rest_client_options.merge(options) |
20 | - url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=#{WxPay.appid}&secret=#{WxPay.appsecret}&code=#{authorization_code}&grant_type=authorization_code" | |
20 | + payload = { | |
21 | + appid: options.delete(:appid) || WxPay.appid, | |
22 | + secret: options.delete(:appsecret) || WxPay.appsecret, | |
23 | + code: authorization_code, | |
24 | + grant_type: 'authorization_code' | |
25 | + } | |
26 | + url = "https://api.weixin.qq.com/sns/oauth2/access_token" | |
21 | 27 | |
22 | 28 | ::JSON.parse(RestClient::Request.execute( |
23 | 29 | { |
24 | 30 | method: :get, |
31 | + payload: payload, | |
25 | 32 | url: url |
26 | 33 | }.merge(options) |
27 | 34 | ), quirks_mode: true) |
... | ... | @@ -40,11 +47,18 @@ module WxPay |
40 | 47 | |
41 | 48 | def self.authenticate_from_weapp(js_code, options = {}) |
42 | 49 | options = WxPay.extra_rest_client_options.merge(options) |
43 | - url = "https://api.weixin.qq.com/sns/jscode2session?appid=#{WxPay.appid}&secret=#{WxPay.appsecret}&js_code=#{js_code}&grant_type=authorization_code" | |
50 | + payload = { | |
51 | + appid: options.delete(:appid) || WxPay.appid, | |
52 | + secret: options.delete(:appsecret) || WxPay.appsecret, | |
53 | + js_code: authorization_code, | |
54 | + grant_type: 'authorization_code' | |
55 | + } | |
56 | + url = "https://api.weixin.qq.com/sns/jscode2session" | |
44 | 57 | |
45 | 58 | ::JSON.parse(RestClient::Request.execute( |
46 | 59 | { |
47 | 60 | method: :get, |
61 | + payload: payload, | |
48 | 62 | url: url |
49 | 63 | }.merge(options) |
50 | 64 | ), quirks_mode: true) | ... | ... |