/**
  * 获取prepay_id
  * @orderNo订单号,或是交易号out_trade_no
  * @ruturn 如果库里有,证明
  */
 public function getPrepayId()
 {
     $orderNo = $this->parameters["out_trade_no"];
     $orderForm = new OrderRelationModel();
     $orderForm->setPayId($orderNo);
     $prepay_id = $orderForm->getPrepayId();
     $data = array();
     if ($prepay_id == FALSE) {
         $this->postXml();
         $this->result = $this->xmlToArray($this->response);
         if ($this->result['result_code'] == 'FAIL') {
             $data['state'] = 'error';
             $data['msg'] = $this->result['err_code_des'];
             return $data;
         } elseif ($this->result['return_code'] == 'FAIL') {
             $data['state'] = 'error';
             $data['msg'] = $this->result['return_msg'];
             return $data;
         }
         $prepay_id = $this->result["prepay_id"];
         $orderForm->savePrepayId($prepay_id);
     }
     $data['state'] = 'success';
     $data['prepay_id'] = $prepay_id;
     return $data;
 }
 public function indexAction()
 {
     //不进行任何的过滤,获取XML数据,并转化为数组
     $xml = I('globals.HTTP_RAW_POST_DATA', '', false);
     if ($xml == '') {
         return;
     }
     $postArr = xml_to_array($xml);
     /*
      * 验证签名的有效性,证明是微信官方发回的文件
      * 很重要
      * 不然会有服务欺骗
      * 验证成功,返回success
      * 不成功,直接跳出
      */
     $sign = $postArr['sign'];
     unset($postArr['sign']);
     if ($sign == get_wechat_sign($postArr)) {
         echo 'SUCCESS';
     } else {
         return;
     }
     /*
      * 依据PAYID进行订单状态的更新操作.
      * 1.更新支付ID表
      * 2.更新订单表
      */
     $orderRelation = new OrderRelationModel();
     $res = $orderRelation->saveInfo($postArr);
     //返回值为false,证明数据重复提交,直接退出
     if ($res == false) {
         return;
     }
     $orderForm = new OrderFormModel();
     $orderForm->setPostArr($postArr);
     $orderForm->saveInfo();
     return;
 }
Exemplo n.º 3
0
 public function payNowAction()
 {
     $orderRelation = new OrderRelationModel();
     $payId = I('get.payid', '');
     $this->openid = get_openid();
     $state = 1;
     //订单的prepay_id信息的有效性
     if ($payId == '') {
         $this->assign('tips', '参数错误!');
         $state = 0;
     } else {
         $arrRes = $orderRelation->chcekPayid($payId, $this->openid);
         if ($arrRes['state'] == 0) {
             $this->assign('tips', $arrRes['msg']);
             $state = 0;
         }
     }
     //判断repayid,如果为null,证明订单信息有误
     if ($state == 0) {
         $jumpUrl = U('Home/Index/index');
         //跳转地址
         $waitSecond = 10;
         //跳转时间
         $this->assign('waitSecond', $waitSecond);
         $this->assign('jumpUrl', $jumpUrl);
         $this->assign('tips', $tips);
         $this->assign('YZBody', $this->fetch('payResult'));
         $this->display(YZ_TEMPLATE);
         return;
     }
     $this->assign('css', $this->fetch("orderPayTipsCss"));
     $this->assign("YZBody", $this->fetch("orderPayTips"));
     $this->display(YZ_TEMPLATE);
     $this->setOrderNo($payId);
     $this->orderPayInfo = $arrRes['res'];
     $this->_payJs();
     //获取JS签名信息
     $actionUrl['error'] = U('payResult');
     $actionUrl['success'] = U('payResult');
     $this->assign('actionUrl', $actionUrl);
     $this->display('payNowJs');
     //调用JS事件,处发支付
 }