コード例 #1
0
ファイル: WeixinPayUtil.php プロジェクト: guohao214/xinya
 /**
  *  获得支付后推送的异步通知数据
  */
 public function notifyData()
 {
     $notify = new Notify_pub($this);
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     LogUtil::weixinLog('异步回调参数:', $notify->data);
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
         return $notify->returnXml();
     }
     return $notify->data;
 }
コード例 #2
0
ファイル: Order.php プロジェクト: guohao214/xinya
 /**
  * 订单支付
  * @param $orderNo
  */
 public function pay($orderNo)
 {
     // 是否授权
     $openId = (new WeixinUtil())->getOpenId();
     if (!$openId) {
         $this->message('错误的授权!');
     }
     // 获得订单信息
     $where = array('order_no' => $orderNo, 'open_id' => $openId);
     $orders = (new OrderModel())->getOrder($where, OrderModel::ORDER_NOT_PAY);
     if (!$orders) {
         $this->message('订单不存在!');
     }
     if (!isset($orders[0])) {
         $this->message('订单不存在!');
     }
     // 如果有多条, 获得第一条的订单记录
     $order = array_shift($orders);
     if ($order['order_status'] == OrderModel::ORDER_PAYED) {
         $this->message('订单已经支付!');
     }
     // 订单时间, 2个小时过期
     if (!DateUtil::orderIsValidDate($order['create_time'])) {
         $this->message('订单已经过期!');
     }
     // 判断相同的时间是否已经被预约
     $findHasPayedAppointTimeWhere = array('appointment_day' => $order['appointment_day'], 'appointment_start_time' => $order['appointment_start_time'], 'order_status' => OrderModel::ORDER_PAYED, 'beautician_id' => $order['beautician_id']);
     $findOrder = (new CurdUtil(new OrderModel()))->readOne($findHasPayedAppointTimeWhere);
     if ($findOrder) {
         $this->message('由于您未能及时付款,此时间段已被预约!');
     }
     // 获得预付款ID
     $weixinPay = new WeixinPayUtil();
     $prePayId = $weixinPay->fetchPrepayId($openId, '购买不期而遇美容产品', $orderNo, $order['total_fee']);
     LogUtil::weixinLog('预付款ID:', $prePayId);
     if (!$prePayId) {
         $this->message('获得微信预付款ID失败,请重试!');
     }
     //生成支付参数
     $payParams = $weixinPay->getParameters($prePayId);
     LogUtil::weixinLog('支付参数:', $payParams);
     $shops = (new ShopModel())->getAllShops();
     $shop = $shops[$order['shop_id']];
     $this->view('order/pay', array('order' => $order, 'payParams' => $payParams, 'shop' => $shop));
 }
コード例 #3
0
ファイル: WeixinUtil.php プロジェクト: guohao214/xinya
 /**
  * 获得微信用户信息
  * @param $accessToken
  * @param $openId
  */
 public function getWeixinUserInfo($accessToken, $openId)
 {
     $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={$accessToken}&openid={$openId}&lang=zh_CN";
     $userInfo = RequestUtil::get($url);
     LogUtil::weixinLog('获得用户信息:', $url);
     if ($userInfo['errcode']) {
         LogUtil::weixinLog('获取用户信息失败:', $userInfo['errcode'] . '--' . $userInfo['errmsg']);
         return null;
     } else {
         LogUtil::weixinLog('获取用户信息成功', $userInfo);
         return $userInfo;
     }
 }