config.php配置
'pay_type' => ['alipay' => ['pay_code'=>'alipay', 'pay_name'=>'支付宝', 'logo'=>'/static/home/img/_/pay2.jpg'],'wechat' => ['pay_code'=>'wechat', 'pay_name'=>'微信支付', 'logo'=>'/static/home/img/_/pay3.jpg'],'union' => ['pay_code'=>'union', 'pay_name'=>'银联', 'logo'=>'/static/home/img/_/pay4.jpg'],]
表单抬起第三方连接echo "<form id='alipayment' action='/pluegin/alipay/wappay/pay.php' method='post' style='display:none'><input id='WIDout_trade_no' name='WIDout_trade_no' value='1000'/><input id='WIDsubject' name='WIDsubject' value='品优购订单' /><input id='WIDtotal_amount' name='WIDtotal_amount' value='1111'/><input id='WIDbody' name='WIDbody' value='品优购订单,测试订单,你付款了我也不发货' /></form><script>document.getElementById('alipayment').submit();</script>";
在第三方config.php中修改
$config = array ( //应用ID,您的APPID。'app_id' => "",//商户私钥,您的原始格式RSA私钥'merchant_private_key' => "",//异步通知地址'notify_url' => "/finish",//同步跳转'return_url' => "/finish",//编码格式'charset' => "UTF-8",//签名方式'sign_type'=>"RSA2",//支付宝网关'gatewayUrl' => "/gateway.do",//支付宝公钥,查看地址:/platform/keyManage.htm 对应APPID下的支付宝公钥。'alipay_public_key' => "",);
//同步回滚
public function callback()
{
//参考/plugins/alipay/return_url.php
//接收参数
$params = input();
//参数检测(签名验证) 接收到的参数 和 支付宝传递的参数 是否发生改变
require_once("./plugins/alipay/config.php");
require_once './plugins/alipay/pagepay/service/AlipayTradeService.php';
$alipaySevice = new \AlipayTradeService($config);
$result = $alipaySevice->check($params);
if($result){
//验签成功
$order_sn = $params['out_trade_no'];
$order = \app\common\model\Order::where('order_sn', $order_sn)->find();
//展示结果
return view('paysuccess', ['pay_name' => '支付宝', 'order_amount'=>$params['total_amount'], 'order' => $order]);
}else{
//验签失败
//展示结果
return view('payfail', ['msg' => '支付失败']);
}
}
/支付页面
<title>支付页</title><link rel="stylesheet" type="text/css" href="/static/home/css/pages-pay.css" /><script src="/libs/jquery/2.1.4/jquery.min.js"></script><div class="cart py-container"><!--主内容--><div class="checkout py-container pay"><div class="checkout-tit"><h4 class="tit-txt"><span class="success-icon"></span><span class="success-info">订单提交成功,请您及时付款,以便尽快为您发货~~</span></h4><div class="paymark"><span class="fl">请您在提交订单<em class="orange time">30分钟</em>之内完成支付,超时订单会自动取消。订单号:<em>{$payData.rng}</em></span><span class="fr"><em class="sui-lead">应付金额:</em><em class="orange money">¥{$payData.price}</em></span></div></div><div class="qrpay"><div class="step-tit"><h5>扫码付(支持支付宝、微信)</h5></div></div><!--需增加的代码结束--><div class="checkout-steps"><!--收件人信息--><div class="step-tit"><h5>支付平台</h5></div><div class="step-cont"><ul class="payType">{foreach $pay_type as $v}<li class="" pay_code="{$v.pay_code}" {if($v.pay_code == 'alipay')}style="border: 2px solid rgb(228, 57, 60);"{/if}>{$v.pay_name}</li>{/foreach}</ul></div><div class="hr"></div><div class="submit sui-text-center"><a class="sui-btn btn-danger btn-xlarge" href="javascript:;">立即支付</a></div></div></div></div><form id="payForm" action="/payfor" method="post"><input type="hidden" name="order_sn" value="{$payData.rng}"><input type="hidden" name="pay_code" value=""><input type="hidden" name="price" value="price"></form><script type="text/javascript">$(function(){$("ul.payType li").click(function(){$(this).css("border","2px solid #E4393C").siblings().css("border-color","#ddd");});//去支付$('.submit').click(function(){//获取选择的支付方式var pay_code = '';$('.payType li').each(function(i,v){//i是下标,v是li标签//console.log($(v).css('border-color'));if($(v).css('border-color') == 'rgb(228, 57, 60)'){//console.log($(v).attr('pay_code'));pay_code = $(v).attr('pay_code');}});//将支付方式pay_code放到表单中$('input[name=pay_code]').val(pay_code);//发送请求 表单提交$('#payForm').submit();})})</script><script>$(function(){//轮询, 查询支付状态var order_sn = "{$payData.rng}";var timer = setInterval(function(){$.ajax({"url":"{:url('home/order/status')}","type":"post","data":"order_sn=" + order_sn,"dataType":"json","success":function(res){if(res.code == 200 && res.data == 1){clearInterval(timer);location.href = "{:url('home/order/payresult')}?order_sn=" + order_sn;}}});}, 1000);})</script>