public function index() { //echo "one"; $this->load->library('wxpayexception'); //echo "two"; define('APPID', $this->config->get('wxpay_appid')); define('MCHID', $this->config->get('wxpay_mchid')); define('KEY', $this->config->get('wxpay_key')); define('APPSECRET', $this->config->get('wxpay_appsecret')); define('SSLCERT_PATH', DIR_SYSTEM . 'helper/wxpay_api/apiclient_cert.pem'); define('SSLKEY_PATH', DIR_SYSTEM . 'helper/wxpay_api/apiclient_key.pem'); define('CURL_PROXY_HOST', '0.0.0.0'); define('CURL_PROXY_PORT', 0); define('REPORT_LEVENL', 1); //echo "three"; $this->load->library('wxpaydata'); //echo "four"; $this->load->library('wxpayapi'); //echo "five"; $this->load->library('wxpayjsapipay'); $tools = new JsApiPay(); $openId = $tools->GetOpenidFromMp($_GET['code']); $this->session->data['weixin_openid'] = $openId; //echo $this->session->data['redirect']; //echo "微信支付测试中......"; //exit; $url = $this->url->link('checkout/checkout', '', 'SSL'); header("Location: {$url}"); //exit(); //$this->response->redirect(str_replace('&', '&', $this->sesssion->data['redirect'])); }
public function wxpay_js() { $tools = new JsApiPay(); if (!Input::has('code')) { $data = array('period_id' => Input::get('period_id'), 'user_id' => Session::get('user.id')); $base_url = urlencode('http://test.zerioi.com/pay/wxpay_js?' . http_build_query($data, '', '&')); //$base_url = urlencode( 'http://test.zerioi.com/pay/wxpay?period_id='.Input::get('period_id') ); $url = $tools->CreateOauthUrlForCode($base_url); return Redirect::to($url); } $open_id = Session::get('user.open_id'); if (!isset($open_id)) { $open_id = $tools->GetOpenidFromMp(Input::get('code')); Session::put('user.open_id', $open_id); } else { Session::forget('user.open_id'); } // 选择用户默认账户 $user_id = Input::get('user_id'); $account = RegisterAccount::where('user_id', $user_id)->first(); if (!isset($account)) { return Response::make('请先申请挂号账户'); } $account_id = $account->id; $period_id = Input::get('period_id'); $period = Period::find($period_id); if (!$this->validate_peirod($period)) { return Response::make('无效时间段,请重新选择'); } /** * 创建订单时先将对应时间段的挂号数加1, * 以避免微信支付异步通知顺序不一致导致 * 挂号记录创建顺序不一致 */ $period->start = date('H:i', strtotime($period->start)); $period->end = date('H:i', strtotime($period->end)); $schedule = $period->schedule; $doctor = $schedule->doctor; $possible_period = array('上午', '下午'); $schedule = array('date' => $schedule->date, 'period' => $possible_period[$schedule->period]); // 附加信息 $attach = array('period_id' => (int) Input::get('period_id'), 'account_id' => $account_id); // 创建订单 $order = $this->create_order(Input::get('user_id'), 'JSAPI', json_encode($attach), (int) ($doctor->register_fee * 100), $open_id); $para = $tools->GetJsApiParameters($order); $data = array('period' => $period, 'schedule' => $schedule, 'doctor' => $doctor, 'department' => $doctor->department->name, 'para' => $para); return View::make('register.pay', $data); }