代码在这里:
页面一、 勾选商品选项
为防止刷新页面引起的时间戳和随机数的变动,所以这俩var需要在前一个页面设置好
var rand_str = Math.random();
rand_str = rand_str*2000;
rand_str = Math.ceil(rand_str);
var time = Date.parse(new Date());
time = time /1000 ;
带上选好的参数调到支付页面,上边有调用微信公众号支付的按钮
location.href = 'makeorder/coinrecharge2?data_re='+data_re+'&data_co='+data_co+'&id='+id+'&rand_str='+rand_str+'&time='+time+'';
页面二、 接收上个页面传来的参数,用laravel的对象,不用数组,数组遇到空白会报错。
设置订单生成时间:$createtime = time();
$row = [
'user_id' => $id ,
'out_trade_no' => $out_trade_no ,
'data_re' => $data_re ,
'data_co' => $data_co ,
'pay_status' => 0,
'createtime' => $createtime
];
session_start();
if($row['user_id']){
$json = json_encode($row);
$_SESSION['json'] = $json;
$_SESSION['out_trade_no'] = $row['out_trade_no'];
}
如果是form表单提交:
<input type="hidden" name="rand_str" id="rand_str">
<input type="hidden" name="time" id="time">
<script src='https://code.jquery.com/jquery-3.2.1.min.js'></script>
<script type="text/javascript">
var rand_str = Math.random();
rand_str = rand_str*2000;
rand_str = Math.ceil(rand_str);
var time = Date.parse(new Date());
time = time /1000 ;
$("#rand_str").val(rand_str);
$("#time").val(time);
</script>