
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
微信支付: https://open.weixin.qq.com/cgi-bin/frame?t=home/pay_tmpl&lang=zh_CN
It contains:
MRI Ruby 2.0.0 and newer are supported. 1.9.2 should work as well but not tested.
Add this line to your application's Gemfile:
gem 'wechat_pay'
And then execute:
$ bundle
Or install it yourself as:
$ gem install wechat_pay
WechatPay.app_id = 'YOUR_APP_ID'
WechatPay.app_secret = 'YOUR_APP_SECRET'
WechatPay.pay_sign_key = 'YOUR_PAY_SIGN_KEY'
WechatPay.partner_id = 'YOUR_PARTNER_ID'
WechatPay.partner_key = 'YOUR_PARTNER_KEY'
WechatPay::AccessToken.generate # => { access_token: 'ACCESS_TOKEN', expires_in: 7200 }
Your should cache the access_token
, see http://mp.weixin.qq.com/wiki/index.php...
You may wanna do something like this in Rails:
Rails.cache.fetch(:wechat_pay_access_token, expires_in: 7200.seconds, raw: true) do
WechatPay::AccessToken.generate[:access_token]
end
# Please keep in mind that all key MUST be Symbol
params = {
body: 'body',
traceid: 'traceid', # Your user id
out_trade_no: 'out_trade_no', # Your order id
total_fee: '100', # 注意:单位是分,不是元
notify_url: 'http://your_domain.com/notify',
spbill_create_ip: '192.168.1.1'
}
WechatPay::App.payment('ACCESS_TOKEN', params)
# =>
# {
# nonce_str: 'noncestr',
# package: 'Sign=WXpay',
# partner_id: 'partner_id',
# prepay_id: 'prepay_id',
# timestamp: '1407165191',
# sign: 'sign'
# }
params = {
body: 'body',
out_trade_no: 'out_trade_no'
total_fee: '100'
notify_url: 'http://your_domain.com/notify',
spbill_create_ip: '192.168.1.1'
}
@order_params = WechatPay::JS.payment(params)
# =>
# {
# app_id: "app_id",
# timestamp: "1407165191",
# nonce_str: "noncestr",
# package: "Sign=WXpay",
# pay_sign: "pay_sign",
# sign_type: 'SHA1'
# }
= link_to "wechat_payment_btn", "javascript:void(0)", id: "wechatPaymentBtn"
javascript:
var orderParams = {
appId: "#{@order_params[:app_id]}",
timeStamp: "#{@order_params[:timestamp]}",
nonceStr: "#{@order_params[:nonce_str]}",
package: "#{@order_params[:package]}",
paySign: "#{@order_params[:pay_sign]}",
signType: "#{@order_params[:sign_type]}"
};
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
$('#wechatPaymentBtn').click(function(){
WeixinJSBridge.invoke('getBrandWCPayRequest', orderParams, function(res) {
if (res.err_msg == "get_brand_wcpay_request:ok") {
alert('pay for success!');
} else {
alert(res.err_msg);
}
});
});
}, false);
# Rails example
def app_notify
# except :controller_name, :action_name, :host, etc.
notify_params = params.except(*request.path_parameters.keys)
if WechatPay::Notify.verify?(notify_params)
# Valid notify status
if params[:trade_state] == '0'
# Code your business logic
end
render text: 'success'
else
render text: 'error'
end
end
# Please keep in mind that all key MUST be Symbol
params = {
openid: 'openid',
transid: 'transid',
out_trade_no: 'out_trade_no',
deliver_msg: 'ok', # optional, default is 'ok'
deliver_status: '1', # optional, default is '1'
deliver_timestamp: '1410105134' # optional, default is `Time.now.to_i.to_s`
}
WechatPay::DeliverNotify.request('ACCESS_TOKEN', params)
# => { errcode: 0, errmsg: 'ok' }
WechatPay::OrderQuery.request('ACCESS_TOKEN', 'YOUR_OUT_TRADE_NO')
# => { errcode: 0, errmsg: 'ok', order_info: { ret_code: 0, ... } }
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that wechat_pay demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.