代碼在這里:
頁面一室谚、 勾選商品選項(xiàng)
為防止刷新頁面引起的時(shí)間戳和隨機(jī)數(shù)的變動(dòng)德迹,所以這倆var需要在前一個(gè)頁面設(shè)置好
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 ;
帶上選好的參數(shù)調(diào)到支付頁面勺远,上邊有調(diào)用微信公眾號支付的按鈕
location.href = 'makeorder/coinrecharge2?data_re='+data_re+'&data_co='+data_co+'&id='+id+'&rand_str='+rand_str+'&time='+time+'';
頁面二增显、 接收上個(gè)頁面?zhèn)鱽淼膮?shù)疗涉,用laravel的對象易稠,不用數(shù)組缸废,數(shù)組遇到空白會報(bào)錯(cuò)。
設(shè)置訂單生成時(shí)間:$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>