Example #1
0
 public function pay()
 {
     ini_set('date.timezone', 'Asia/Shanghai');
     require_once "lib/WxPay.Api.php";
     require_once "WxPay.JsApiPay.php";
     $sn = $_GET['sn'];
     $code = $_GET['code'];
     $data = json_decode(cookie('login'), true);
     $arr = D('Shop')->orderdetail($sn, $data['user']);
     if ($arr['show_status'] == '未付款') {
         $tools = new JsApiPay();
         $openId = $tools->getOpenidFromMp($code);
         $input = new WxPayUnifiedOrder();
         $input->SetBody("民间厨王");
         $input->SetAttach("test");
         $input->SetOut_trade_no($sn);
         $total_fee = $arr['goods_price'] * 100;
         $input->SetTotal_fee(intval($total_fee));
         $input->SetTime_start(date("YmdHis"));
         $input->SetTime_expire(date("YmdHis", time() + 600));
         $input->SetGoods_tag("test");
         $input->SetNotify_url("http://www.minjianchuwang.com/Home/Order/notify_url.html");
         $input->SetTrade_type("JSAPI");
         $input->SetOpenid($openId);
         $order = WxPayApi::unifiedOrder($input);
         $jsApiParameters = $tools->GetJsApiParameters($order);
         $this->assign('jsApiParameters', $jsApiParameters);
         $daojishi = $arr['add_time'] + 600 - time();
         $this->assign('daojishi', $daojishi);
         $this->assign('orderdetail', $arr);
         $this->assign('address', explode(';', $arr['address']));
         $totalcount = M('cart')->where(array('user' => $data['user']))->sum('goods_number');
         $this->assign('totalcount', $totalcount);
         $this->display('order_details');
     } else {
         $this->redirect('Order/index');
     }
 }