如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
<!doctype html> <html> <head> <meta charset="utf-8"> <title>微信支付</title> <meta name="keywords" content=""/> <meta name="description" content=""/> <meta content="telephone=no" name="format-detection" /> <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" /> <meta content="yes" name="apple-mobile-web-app-capable" /> <meta content="black" name="apple-mobile-web-app-status-bar-style" /> <script src="__TPL__/js/mui.min.js"></script> <link href="__TPL__/css/mui.min.css" rel="stylesheet"/> <link rel="stylesheet" type="text/css" href="__TPL__/css/style.css"/> <link rel="stylesheet" type="text/css" href="__TPL__/fonts/iconfont.css"/> <script type="text/javascript" charset="utf-8"> mui.init(); </script> <script type="text/javascript"> //调用微信JS api 支付 function jsApiCall() { WeixinJSBridge.invoke( 'getBrandWCPayRequest', <?php echo $jsApiParameters; ?>, function(res){ WeixinJSBridge.log(res.err_msg); if(res.err_msg=='get_brand_wcpay_request:ok'){ window.location.href="__URL__/paysuccess/{$order[order_sn]}.html"; } //alert(res.err_code+res.err_desc+res.err_msg); } ); } function callpay() { if (typeof WeixinJSBridge == "undefined"){ if( document.addEventListener ){ document.addEventListener('WeixinJSBridgeReady', jsApiCall, false); }else if (document.attachEvent){ document.attachEvent('WeixinJSBridgeReady', jsApiCall); document.attachEvent('onWeixinJSBridgeReady', jsApiCall); } }else{ jsApiCall(); } } //获取共享地址 function editAddress() { WeixinJSBridge.invoke( 'editAddress', <?php echo $editAddress; ?>, function(res){ var value1 = res.proviceFirstStageName; var value2 = res.addressCitySecondStageName; var value3 = res.addressCountiesThirdStageName; var value4 = res.addressDetailInfo; var tel = res.telNumber; alert(value1 + value2 + value3 + value4 + ":" + tel); } ); } /*window.onload = function(){ if (typeof WeixinJSBridge == "undefined"){ if( document.addEventListener ){ document.addEventListener('WeixinJSBridgeReady', editAddress, false); }else if (document.attachEvent){ document.attachEvent('WeixinJSBridgeReady', editAddress); document.attachEvent('onWeixinJSBridgeReady', editAddress); } }else{ editAddress(); } };*/ </script> </head> <body style="background:#fff;"> <div class="roomCgtitle"> <i class="iconfont">  </i> <h5>订单提交成功</h5> </div> <div class="roomCgif"> <ul> <li><b>订单编号:</b><span>{$order['order_id']}</span></li> <li><b>交易方式:</b><span>微信支付</span></li> <li><b>下单时间: </b><span>{$order['createtime']}</span></li> <li><b>订单金额</b><span>¥{$order['money']}</span></li> </ul> <div class="mui-content-padded paddingTop03"> <a href="javascript:callpay();"><button type="button" class="mui-btn mui-btn-success1 mui-btn-block">立即支付</button></a> </div> </div> </body> </html> //php内容 public function hd_payment() { // var_dump();die; $condition['order_id'] = $_GET[0]; $condition['uid'] = $_SESSION['user']['uid']; $condition['pay_status'] = 0; //未支付 $order_sn = $this->model->table('hdorder')->where($condition)->find(); if (empty($order_sn)) { $this->success('Order not exist', 'back'); } ini_set('date.timezone','Asia/Shanghai'); $thisTime = time(); //初始化日志 $logHandler= new CLogFileHandler(dirname(__FILE__)."/logs/".date('Y-m-d').'.log'); $log = Log::Init($logHandler, 15); //①、获取用户openid $tools = new JsApiPay(); $openId = $_SESSION['user']['openid']; //②、统一下单 $input = new WxPayUnifiedOrder(); $input->SetBody("微信支付"); $input->SetAttach("微信支付"); $input->SetOut_trade_no($order_sn['order_id']); $input->SetTotal_fee($order_sn['money']*100); //$input->SetTotal_fee(1); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 6000)); $input->SetGoods_tag("微信支付"); $input->SetNotify_url("http://www.123456.cn/weixin/index.php/notify.html"); $input->SetTrade_type("JSAPI"); $input->SetOpenid($openId); $order = WxPayApi::unifiedOrder($input); $jsApiParameters = $tools->GetJsApiParameters($order); //获取共享收货地址js函数参数 $editAddress = $tools->GetEditAddressParameters(); $this->assign("jsApiParameters", $jsApiParameters); $this->assign("editAddress", $editAddress); $this->assign('order', $order_sn); // echo "<pre>"; // var_dump($order_sn);die; $this->display('hd_wxpay'); } //在回调中修改状态