那就来嘛,小哥哥
@fodcool 用第三方聚合支付吧。
欢迎各位小伙伴踊跃报名。
感谢以上各位的回答。看来是不用做 https 容错的方案。
piaoling 垃圾公司,谁去谁当雷锋,至今拖欠员工工资。
除非有特定的异常需要处理,其它的一律抛出给 errbit
多大的群,人满了。
mina 是相比 cap 要简洁的多,不过多个 domain 部署,cap 是可以的,不知道 mina 是否也行?有大神解惑一下
#1 楼 @sun528 thx ,这个问题解决了,有需要的可以参考一下,只是简单的实现
# 银联支付
require 'net/https'
require 'uri'
module OPE
class Unionpay
def self.default_options
#txnType 00 查询交易 01:消费 02:预授权
# merId 商户Id
#accessType 0:商户直连接入 1:收单机构接入 2:平台商户接入
options = {:version => '5.0.0', :txnType => "01", :backUrl => "#{Settings.domain}/notify/unionpay",
:merId => Settings.unionpay_store_no, :accessType => "0", :bizType => '000201',
:currencyCode => "156", :signMethod => "01", :certId => get_cert_id, :txnSubType => "01",
:encoding => "utf-8", :channelType => "07",
:frontUrl => "#{Settings.domain}/unionpay/front"}
end
def self.create_direct_pay(order,custom_options = {})
# 测试参数
options = self.get_options(order)
options.merge!(custom_options) rescue nil
options.symbolize_keys!
signature = self.sign(options)
options.merge(:signature => signature)
end
def self.query_options(order)
options = self.get_options(order)
options.delete(:backUrl)
options.delete(:frontUrl)
options.merge!(:txnType => '00', :txnSubType => '00')
signature = self.sign(options)
options.merge(:signature => signature)
end
def self.get_options(order)
options ||= {:orderId => order.seq, :txnTime => order.created_at.to_s(:unionpay), :txnAmt => (order.credits * 100).to_i}
options.merge! self.default_options
end
def self.get_cert_id
get_certificate.certificate.serial.to_i
end
def self.get_cret_key
get_certificate.key
end
def self.get_certificate
OpenSSL::PKCS12.new(File.read(Settings.unionpay_certificate), Settings.unionpay_certificate_psw)
end
def self.get_validate_certificate
OpenSSL::X509::Certificate.new(File.read(Settings.unionpay_validate_certificate))
end
def self.sign(param)
sign_str = self.convert_params(param)
sha1_sign = Digest::SHA1.hexdigest(sign_str)
digest = OpenSSL::Digest::SHA1.new
openssl_sha1 = self.get_cret_key.sign(digest, sha1_sign)
Base64.encode64(openssl_sha1).gsub(/\s/, '')
end
def self.validate(param)
param.delete('controller')
param.delete('action')
signature_str = param.delete('signature')
signature_str.gsub!(/\s/, '+')
Rails.logger.info("signature_str #{signature_str}")
signature = Base64.decode64(signature_str)
sign_str = self.convert_params(param)
sha1_sign = Digest::SHA1.hexdigest(sign_str)
digest = OpenSSL::Digest::SHA1.new
self.get_validate_certificate.public_key.verify(digest, signature, sha1_sign)
end
def self.convert_params(param)
sign_str = param.sort.map do |k, v|
"#{k}=#{v}"
end.join("&").strip
end
def self.app_order(order)
options = self.create_direct_pay(order)
page = Mechanize.new { |a| a.ssl_version, a.verify_mode = 'SSLv3', OpenSSL::SSL::VERIFY_NONE }
doc = page.post(Settings.unionpay_app_front_url, options)
result = Rack::Utils.parse_query(doc.body)
if result['respCode'] == '00' && self.validate(result)
return result
else
return false
end
end
#查询订单
def self.query(order)
options = query_options(order)
page = Mechanize.new { |a| a.ssl_version, a.verify_mode = 'SSLv3', OpenSSL::SSL::VERIFY_NONE }
doc = page.post(Settings.unionpay_query_url, options)
result = Rack::Utils.parse_query(doc.body)
order = Order.find_by(:seq => result['orderId'])
order.trades = result.to_s
if result['respCode'] == '00' && self.validate(result)
if result['origRespCode'].blank?
if order.may_finish?
order.finish
end
end
end
order.save!
result
end
end
end
公司地点在哪?能透露一下吗?
顶一下,难道小伙伴们都在期待年终奖?
@lhy20062008 这个都不是问题,来试一试火力。
@lhy20062008 有什么难言之隐?
@SharpX 谢谢支持,有母公司的资源支持,产品是肯定没有问题,现在就是需要人手,一切从头开始呀..
@lgn21st 不觉的有种淡淡的时尚气息...
在 application.js 里 带上这段
$.ajaxSetup({
beforeSend: function (xhr) {
xhr.setRequestHeader('X-CSRF-Token',
$('meta[name="csrf-token"]').attr('content'));
}
});
from 本身就不可以嵌套,为什么要这样做呢?和 rails 无关