public function jsapi()
 {
     $jsApiParameters = "";
     $config = C("WXPAY_CONFIG");
     //①、获取用户openid
     $tools = new \Common\Api\Wxpay\JsApi($config);
     $openId = $tools->GetOpenid();
     //		dump($openId);
     //②、统一下单
     $input = new \Common\Api\Wxpay\WxPayUnifiedOrder();
     $input->setConfig($config);
     //		dump($input);
     $input->SetBody("test2");
     $input->SetAttach("test2");
     $input->SetOut_trade_no('10027619' . date("YmdHis"));
     $input->SetTotal_fee("1");
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     //		$input->SetGoods_tag("test");
     $input->SetNotify_url("http://2test.8raw.com/index.php/Shop/WxpayNotify/index");
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     \Common\Api\Wxpay\WxPayApi::setConfig($config);
     $order = \Common\Api\Wxpay\WxPayApi::unifiedOrder($input);
     //		dump($order);
     $jsApiParameters = $tools->GetJsApiParameters($order);
     $this->assign("jsApiParameters", $jsApiParameters);
     $this->display();
     //③、在支持成功回调通知中处理成功之后的事宜,见 notify.php
 }
 /**
  * 查询订单根据out_trade_no
  */
 public function queryByOutTradeNo($out_trade_no)
 {
     $input = new WxPayOrderQuery();
     $input->setConfig($this->config);
     $input->SetOut_trade_no($out_trade_no);
     \Common\Api\Wxpay\WxPayApi::setConfig($this->config);
     return \Common\Api\Wxpay\WxPayApi::orderQuery($input);
 }
 /**
  *
  * @param 微信支付配置 $config
  * @param 订单ID $trade_no
  * @param $body
  * @param 总价格 $total_fee
  * @param string $attach
  * @throws Api\Wxpay\WxPayException
  * @internal param 微信支付配置 $config
  * @internal param 订单ID $trade_no
  * @internal param 商品描述 $itemdesc
  * @internal param 总价格 $total_fee
  */
 private function setWxpayConfig($config, $trade_no, $body, $total_fee, $attach = '')
 {
     try {
         $jsApiParameters = "";
         //①、获取用户openid
         $tools = new Api\Wxpay\JsApi($config);
         //			$openId = $tools -> GetOpenid();
         $openId = $this->openid;
         //②、统一下单
         $input = new Api\Wxpay\WxPayUnifiedOrder();
         $input->setConfig($config);
         //
         $input->SetBody($body);
         //string(32)
         $input->SetAttach($attach);
         //
         $input->SetOut_trade_no($trade_no);
         $input->SetTotal_fee($total_fee);
         $input->SetTime_start(date("YmdHis"));
         $input->SetTime_expire(date("YmdHis", time() + 60 * 30));
         //			$input -> SetGoods_tag("test");
         $input->SetNotify_url($config['NOTIFYURL']);
         $input->SetTrade_type("JSAPI");
         $input->SetOpenid($openId);
         WxPayApi::setConfig($config);
         $order = WxPayApi::unifiedOrder($input);
         if (isset($order['return_code']) && $order['return_code'] == 'FAIL') {
             $this->error($order['return_msg']);
         }
         if (isset($order['return_code']) && $order['result_code'] == 'FAIL') {
             $this->error($order['err_code_des']);
         }
         //            addWeixinLog($order,"GETJsApiParameters");
         $jsApiParameters = $tools->GetJsApiParameters($order);
         $this->assign("jsApiParameters", $jsApiParameters);
     } catch (WxPayException $sdkexcep) {
         $error = $sdkexcep->errorMessage();
         $this->assign("error", $error);
     }
 }