我现在做的一个网站要做微信支付,扫码和jsapi支付都做好了,现在PC生成了扫码支付的二维码后,不支付,在去微信端用JSAPI支付时出现了订单重复的问题,$input->SetTrade_type("JSAPI"); 只是改变了支付类型,是不是要把这个没支付的订单在重新生成个订单号才行?我想实现的是PC端用扫码,手机浏览器用H5,微信端用JSAPI现在遇到这个坑卡着了,还请各位大哥帮忙看下,谢谢了
//调用微信jsapi支付接口
case 'wxjsapipay':
if(empty($_GET['sn']))
{
die('error: no order sn');
}
$sn=mysqli_real_escape_string($GLOBALS['db']->conn, htmlspecialchars(stripslashes($_GET['sn'])));
$title_sn='订单号'.$sn;
$order=orders_get_by_sn($sn);
ini_set('date.timezone','Asia/Shanghai');
require_once "wxpay/lib/WxPay.Api.php";
require_once "wxpay/example/WxPay.JsApiPay.php";
require_once 'wxpay/example/log.php';
//①、获取用户openid
$tools = new JsApiPay();
if(!isset($_SESSION[USERSESSION]['wx_openId']) && empty($_SESSION[USERSESSION]['wx_openId'])){
$_SESSION[USERSESSION]['wx_openId'] = $tools->GetOpenid();
}
$money=$order['buy_total']*100;
//②、统一下单
$input = new WxPayUnifiedOrder();
$input->SetBody($title_sn);
$input->SetAttach($title_sn);
$input->SetOut_trade_no($sn);
$input->SetTotal_fee($money);
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag($title_sn);
$input->SetNotify_url("http://www.xxx.com/qrcode/notify.php");
$input->SetTrade_type("JSAPI");
$input->SetOpenid($_SESSION[USERSESSION]['wx_openId']);
$order = WxPayApi::unifiedOrder($input);
// echo "
";
// print_r($order);die;
$jsApiParameters = $tools->GetJsApiParameters($order);
// $editAddress = $tools->GetEditAddressParameters();
$smarty->assign('money', number_format($money/100, 2, '.', ''));
$smarty->assign('jsApiParameters', $jsApiParameters);
$smarty->assign('sn', $sn);
$smarty->display("wxpay.shtml");
exit();
break;//调用微信扫码支付接口 case 'wxpay': if(empty($_GET['sn'])) { die('error: no order sn'); } $sn=mysqli_real_escape_string($GLOBALS['db']->conn, htmlspecialchars(stripslashes($_GET['sn']))); $title_sn='订单号'.$sn; $order=orders_get_by_sn($sn); ini_set('date.timezone','Asia/Shanghai'); require_once "wxpay/lib/WxPay.Api.php"; require_once "wxpay/example/WxPay.NativePay.php"; require_once 'wxpay/example/log.php'; $notify = new NativePay(); $money=$order['buy_total']*100; $input = new WxPayUnifiedOrder(); $input->SetBody($title_sn); $input->SetAttach($title_sn); $input->SetOut_trade_no($sn); $input->SetTotal_fee($money); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag($title_sn); $input->SetNotify_url("http://www.xxx.com/qrcode/notify.php"); $input->SetTrade_type("NATIVE"); $input->SetProduct_id($order['id']); $result = $notify->GetPayUrl($input);
// echo "
";
// print_r($result);die;
if (!isset($result["code_url"]))
{
$content = 'Preferential code error
';
$result['content'] = 'Failed to obtain QR code. Please try again later';
$result['title'] = 'Tip';
$result['content_cn'] = '获取支付二维码失败,请稍后再试';
$result['title_cn'] = '提示';
$result['success'] = false;
$order_confirm_url = $ac->createPluginsUrl(array('plug'=>'member','ac'=>'default'));
$result['button'] = 'Back';
$result['button_cn'] = '返回';
$smarty->assign('data', $result);
$smarty->display('sys-info.shtml');
exit();
}
$url2 = $result["code_url"];
$smarty->assign('url2', $url2);
$smarty->assign('money', number_format($money/100, 2, '.', ''));
$smarty->assign('sn', $sn);
$smarty->display("wxpay.shtml");
exit();
break;