#coding:utf-8
class AlipayController < ApplicationController
#http://www.15-1688.com:3000/alipay/respond?trade_status=TRADE_FINISHED&is_success=T&out_trade_no=201012041246501110&trade_no=1111&total_fee=2020&fee_type=1&attach=&sign=3cc3b8c94797a5f4d060a1fdb95a0301
def return_url_process
dict={}
params.each do |k,v|
if k!="sign" and k!="sign_type" and k!="action" and k!="controller" and v!=""
dict[k]=v
end
end
logger.debug(dict)
gen_sign=AlipayLib::gen_sign(dict,"asdfasdfasdfasdfasdfasdfasdfasdfsadf")#密钥
logger.debug("-----------------------------------------------------------------")
logger.debug("gen_sign")
logger.debug(gen_sign)
pay_success=false
ps=PaymentStatus.new
ps.url=request.request_uri
ps.ip=request.remote_ip
ps.from="支付宝"
ps.memo="来自同步接口"
if gen_sign==params[:sign]
sn=params[:out_trade_no]
order=Order.find_by_sn(sn)
ps.order_id=order.id
if params[:trade_status]=="TRADE_FINISHED" or params[:trade_status]="TRADE_SUCCESS"
ps.name="付款成功"
ps.success=true
ps.transaction_id=params[:trade_no]
ps.sn=sn
ps.total_fee=params[:total_fee]
order.order_statuses<<OrderStatus.create(:name=>"订单确认",:value=>2)
pay_success=true
else
ps.name="付款未成功"
end
else
ps.name="签名不对"
logger.debug("签名不对")
end
ps.save
if pay_success
redirect_to "/pay_success"
else
redirect_to "/pay_failure"
end
end
#http://www.15-1688.com:3000/alipay/notify?trade_status=TRADE_FINISHED&is_success=T&out_trade_no=201012041246501110&trade_no=1111&total_fee=2020&fee_type=1&attach=&sign=3cc3b8c94797a5f4d060a1fdb95a0301
def notify_url_process
dict={}
params.each do |k,v|
if k!="sign" and k!="sign_type" and k!="action" and k!="controller" and v!=""
dict[k]=v
end
end
logger.debug(dict)
gen_sign=AlipayLib::gen_sign(dict,"sdafasdfasdfasdfasdfasdfadsfasdf")#密钥
logger.debug("-----------------------------------------------------------------")
logger.debug("gen_sign")
logger.debug(gen_sign)
pay_success=false
ps=PaymentStatus.new
ps.url=request.request_uri
ps.ip=request.remote_ip
ps.from="支付宝"
ps.memo="来自异步步接口"
if gen_sign==params[:sign]
sn=params[:out_trade_no]
order=Order.find_by_sn(sn)
ps.order_id=order.id
if params[:trade_status]=="TRADE_FINISHED" or params[:trade_status]="TRADE_SUCCESS"
ps.name="付款成功"
ps.success=true
ps.transaction_id=params[:trade_no]
ps.sn=sn
ps.total_fee=params[:total_fee]
order.order_statuses<<OrderStatus.create(:name=>"订单确认",:value=>2)
pay_success=true
else
ps.name="付款未成功"
end
else
ps.name="签名不对"
logger.debug("签名不对")
end
ps.save
if pay_success
render :text=>"success"
else
render :text=>"error"
end
end
end