public function payJs()
 {
     //调用统一支付接口
     $unifiedOrder = new UnifiedOrderPubController();
     //统一支付接口
     $jsApi = new JsApiPubController();
     //JSAPI支付——H5网页端调起支付接口
     $openid = $this->openId;
     //取用户OPENID
     $body = $this->orderDescription;
     //订单描述
     $outTradeNo = $this->orderNo;
     //传入的订单号
     $totalFee = $this->totalFee;
     //总金额,以分为单位,不能有小数点
     $notifyUrl = $this->notifyUrl;
     //接收返回值的地址
     $tradeType = 'JSAPI';
     //交易类型
     //开始设置参数
     $unifiedOrder->setParameter("openid", "{$openid}");
     $unifiedOrder->setParameter("body", "{$body}");
     $unifiedOrder->setParameter("out_trade_no", $outTradeNo);
     $unifiedOrder->setParameter("total_fee", $totalFee);
     $unifiedOrder->setParameter("notify_url", $notifyUrl);
     $unifiedOrder->setParameter("trade_type", $tradeType);
     //        $unifiedOrder->setParameter("sub_mch_id", $parameterValue);//子商户号
     //        $unifiedOrder->setParameter("device_inf", $parameterValue);//设备号
     //        $unifiedOrder->setParameter("attach", $parameterValue);//附加数据
     //        $unifiedOrder->setParameter("time_start", $parameterValue);//交易起始时间
     //        $unifiedOrder->setParameter("time_expire", $parameterValue);//交易结束时间
     //        $unifiedOrder->setParameter("goods_tag", $parameterValue);//商品标记
     //        $unifiedOrder->setParameter("openid", $parameterValue);//用户标识,JSAPI为必填项
     //        $unifiedOrder->setParameter("product_id", $parameterValue);//商品ID
     $prepayId = $unifiedOrder->getPrepayId();
     //获取replayID
     $jsApi->setPrepayId($prepayId);
     //设置prepayId
     //散闷JSAPI参数,用放置到支付页面中
     $jsApiParameters = $jsApi->getParameters();
     //获取SSDK配置信息
     //        $JSSDK = A('JSSDK');
     //        $signPackage = $JSSDK->getSignPackage();
     //        $this->assign('signPackage',$signPackage);
     $actionUrl['success'] = U('payResult?status=success');
     $actionUrl['error'] = U('payResult?status=error');
     $this->assign('actionUrl', $actionUrl);
     $this->assign('jsApiParameters', $jsApiParameters);
     return $this->fetch('Index/index');
 }
Esempio n. 2
0
 private function _payJs()
 {
     //调用统一支付接口
     $unifiedOrder = new UnifiedOrderPubController();
     //统一支付接口
     $jsApi = new JsApiPubController();
     //JSAPI支付——H5网页端调起支付接口
     $openid = $this->openid;
     //取用户OPENID
     $outTradeNo = $this->orderNo;
     //传入的订单号
     $notifyUrl = $this->notifyUrl;
     //接收返回值的地址
     $tradeType = 'JSAPI';
     //交易类型
     //传入id,取出总金额与订单描述
     $body = $this->orderPayInfo['body'] == '' ? '此订单未生成描述信息' : $this->orderPayInfo['body'];
     //订单描述
     $totalFee = $this->orderPayInfo['payable'];
     //总金额,以分为单位,不能有小数点
     if ($totalFee == 0) {
         //总金额为0,证明有问题,应该输出js提醒
         return;
     }
     $prepayId = $this->orderPayInfo['prepay_id'];
     if ($prepayId == '') {
         //开始设置参数
         $unifiedOrder->setParameter("openid", "{$openid}");
         $unifiedOrder->setParameter("body", "{$body}");
         $unifiedOrder->setParameter("out_trade_no", $outTradeNo);
         $unifiedOrder->setParameter("total_fee", $totalFee);
         $unifiedOrder->setParameter("notify_url", $notifyUrl);
         $unifiedOrder->setParameter("trade_type", $tradeType);
         //        $unifiedOrder->setParameter("sub_mch_id", $parameterValue);//子商户号
         //        $unifiedOrder->setParameter("device_inf", $parameterValue);//设备号
         //        $unifiedOrder->setParameter("attach", $parameterValue);//附加数据
         //        $unifiedOrder->setParameter("time_start", $parameterValue);//交易起始时间
         //        $unifiedOrder->setParameter("time_expire", $parameterValue);//交易结束时间
         //        $unifiedOrder->setParameter("goods_tag", $parameterValue);//商品标记
         //        $unifiedOrder->setParameter("openid", $parameterValue);//用户标识,JSAPI为必填项
         //        $unifiedOrder->setParameter("product_id", $parameterValue);//商品ID
         $prepayData = $unifiedOrder->getPrepayId();
         //获取预付费信息replayID
         //查看是否出错,出错则直接弹出alert信息
         if ($prepayData['state'] == 'error') {
             $msg = $prepayData['msg'];
             $this->assign('msg', $msg);
             $js = $this->fetch('jsError');
             echo $js;
             return;
         }
         $prepayId = $prepayData['prepay_id'];
         //更新该订单的preparid
     }
     $jsApi->setPrepayId($prepayId);
     //设置prepayId
     //散闷JSAPI参数,用放置到支付页面中
     $jsApiParameters = $jsApi->getParameters();
     //生成签名信息
     $orderSign = json_decode($jsApiParameters);
     $sign = array();
     $sign['nonce_str'] = $orderSign->nonceStr;
     $sign['sign'] = $orderSign->paySign;
     $sign['id'] = $outTradeNo;
     $this->assign('jsApiParameters', $jsApiParameters);
     return;
 }