Skip to content

Commit

Permalink
use md5
Browse files Browse the repository at this point in the history
  • Loading branch information
yigefaxian committed Nov 10, 2024
1 parent fc68aa1 commit 10065a0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/apis/wx_pay/api/mch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def pay_micropay(out_trade_no:, auth_code:, body:, total_fee:, spbill_create_ip:
opts.merge! sign: WxPay::Sign::Hmac.generate(opts, key: @mch.key)

r = @client.with_options(origin: BASE, debug: Rails.logger.broadcasts[0].instance_values['logdev'].dev, debug_level: 2)
.post('pay/micropay', body: opts.to_xml(root: 'xml', skip_types: true, skip_instruct: true, dasherize: false))
.post('/pay/micropay', body: opts.to_xml(root: 'xml', skip_types: true, skip_instruct: true, dasherize: false))
Hash.from_xml(r.to_s)['xml']
end

Expand Down
4 changes: 2 additions & 2 deletions app/apis/wx_pay/api/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ def pay_micropay(out_trade_no:, auth_code:, body:, total_fee:, spbill_create_ip:
auth_code: auth_code,
**v2_common_payee_params
}
opts.merge! sign: WxPay::Sign::Hmac.generate(opts, key: @mch.key)
opts.merge! sign: WxPay::Sign::Hmac.generate_md5(opts, key: @mch.key)

r = @client.with_options(origin: BASE, debug: Rails.logger.broadcasts[0].instance_values['logdev'].dev, debug_level: 2)
.post('pay/micropay', body: opts.to_xml(root: 'xml', skip_types: true, skip_instruct: true, dasherize: false))
.post('/pay/micropay', body: opts.to_xml(root: 'xml', skip_types: true, skip_instruct: true, dasherize: false))
Hash.from_xml(r.to_s)['xml']
end

Expand Down
9 changes: 9 additions & 0 deletions app/apis/wx_pay/sign/hmac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,14 @@ def generate(params, key:)
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, string_sign_temp).upcase
end

def generate_md5(params, key:)
query = params.compact_blank.sort.map.each do |k, v|
"#{k}=#{v}"
end.join('&')
string_sign_temp = "#{query}&key=#{key}"

Digest::MD5.hexdigest(string_sign_temp).upcase
end

end
end

0 comments on commit 10065a0

Please sign in to comment.