支付生成二维码和回调地址

const NOTIFY_URL = 'http://pay.gbicom.cn/index.php/dispatch/weixinNotify';
 
/*
     *  生成支付二维码
     */
    public function createCodeAction(){
       $ContractNumber = $this->request['order_card'];
       $SysOrderModel = new SysOrderModel();
       $where['ContractNumber'] = $ContractNumber;
       $data = $SysOrderModel->getOne($where);
       if(!empty($data) && ($data['order_total_fee'] - $data['order_coupons_money']) <= $data['order_pay_money']){
           Tools::redirect('http://home.gbicom.cn/order/paySuccess?connum='.$ContractNumber);
           exit;
       }

        $u_sn = $data['ContractNumber'].'_'.($data['order_total_fee'])*100;

        $param = array(
                'attach'           => base64_encode($data['ContractNumber']),
                'body'             => $data['ContractNumber'],
                'out_trade_no'     => $u_sn.'_'.time(),
                'total_fee'        => ($data['order_total_fee'])*100,
                'spbill_create_ip' => $_SERVER['REMOTE_ADDR'],
                'trade_type'       => 'NATIVE',
                'product_id'       => rand(),
          );
        try
        {
            $redis = new common_Redis($host = '127.0.0.1', $port = 6379);
            $g_data = $redis->get($u_sn);
            if(!empty($g_data))
            {
            $codeUrl = $g_data;
            }
            else
            {
//            $order = new Order();
//            $order->close($u_sn);
            $code = new Qrcode();
            $codeUrl = $code->interim($param);
            $redis->setex($u_sn,$codeUrl,7200);
            }
        }
        catch (WxException $ex)
        {
            $ex->showError();
        }
        $ret =  array('code'=>200,'msg'=>$codeUrl);
        $ret = json_encode($ret);
        echo $ret;
    }
	
  //回调地址处理逻辑	
  public function weixinNotifyAction(){
   try
    {
      $xml = file_get_contents('php://input', 'r');
      Log::record('[微信支付成功后返回的数据xml]:' . $xml, Log::LOG_LEVEL_DEBUG);
      $payInfo = Xml::xmlToArr($xml);

      Sign::verify($payInfo);

      $out_trade_no = $payInfo['out_trade_no'];
      $out_trade_no = explode('_', $out_trade_no);
      if(count($out_trade_no) > 2)
      {
          array_pop($out_trade_no);
          $payInfo['out_trade_no'] = join('_',$out_trade_no);
      }

      $log = new PaylogModel() ;
      $log ->add(array('channel'=> 4,'json' => 'yibu'.json_encode($payInfo)));

      $channelId = SetupNotifyModel::CHANNEL_WEIXIN;
      $payInfo['appId'] = 13;
      $payInfo['channelId'] = $channelId;
      $cWeixin = new WxpayController();
      $result  = $cWeixin->notify($payInfo);
   }
   catch (WxException $ex)
   {
          $ex->showError();
   }
}

/*
 * 支付异步通知方法
 */
public function notify($payInfo) {
   $log = new PaylogModel() ;
   $log->add(array('channel'=>4,'json' => 'weixin_notify_url###'.json_encode($payInfo)));
    //Sign::verify($payInfo);
        if ($payInfo['result_code'] == 'SUCCESS')
        {
            $res = common_NotifyOrder::notifyweixin(self::PAY_STATUS_URL, $payInfo);
            $log->add(array('json'=>json_encode($res)));
            $res = (array)$res;
            if($res['errorCode'] == 1)
            {
               $this->payBook($payInfo);
               $ret = array('return_code'=>'SUCCESS');
            }
            else
            {
               $ret = array('return_code'=>'FAIL','return_msg'=>'CRM Send Fail');
                    $log->add(array('json' => 'CRM Send Fail'));
            }
        }
        else
        {
               $ret = array('return_code'=>'FAIL','return_msg'=>'Bussiness Error');
                    $log->add(array('json' => 'Bussiness Error'));
        }
                
         $xml = Xml::arrToXml($ret);
         Log::record('[送给微信的回调信息]: ' . $xml, Log::LOG_LEVEL_DEBUG);
         header("Content-type:text/xml");
         echo $xml;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值