Commit 04edd39f1bc753fe81b4395d6b52704ddc213f32
1 parent
b8ad7aa4
Exists in
master
add the code for trade_type is app
Showing
1 changed file
with
17 additions
and
0 deletions
Show diff stats
lib/wx_pay/service.rb
... | ... | @@ -17,6 +17,23 @@ module WxPay |
17 | 17 | |
18 | 18 | r = invoke_remote("#{GATEWAY_URL}/unifiedorder", make_payload(params)) |
19 | 19 | |
20 | + # when trade_type is app, signing again is needed, the sigin params are below | |
21 | + # appid,partnerid,prepayid,noncestr,timestamp,package。 | |
22 | + # notice: package is "Sign=WXPay", noncestr is the same as the params[:nonce_str] | |
23 | + # prepayid is the r["prepay_id"] | |
24 | + if params[:trade_type] == 'APP' && r["return_code"] == "SUCCESS" && r["result_code"] == "SUCCESS" | |
25 | + sign_again_params = { | |
26 | + appid: params[:appid], | |
27 | + noncestr: params[:nonce_str], | |
28 | + package: 'Sign=WXPay', | |
29 | + partnerid: params[:mch_id], | |
30 | + timestamp: Time.now.to_i.to_s, | |
31 | + prepayid: r["prepay_id"] | |
32 | + } | |
33 | + r["sign"] = Sign.generate(sign_again_params) | |
34 | + | |
35 | + end | |
36 | + | |
20 | 37 | yield r if block_given? |
21 | 38 | |
22 | 39 | r | ... | ... |