Exemple #1
0
 /**
  * 获取支付请求
  * 主要是用户充值操作
  * @param $uid 用户id
  * @param $amount 充值金额---( 以"分"为单位的整型)
  * @return array  返回用户的支付订单号和验证码发送手机
  * @throws ErrorException
  */
 public static function payment($uid, $amount)
 {
     $uid = (int) $uid;
     $amount = (int) $amount;
     $info = Bindbankcard::findOne(['uid' => $uid, 'status' => yeepay::SUCCEED]);
     if ($info) {
         $orderid = self::build_order_no();
         $transtime = time();
         $amount = (int) $amount;
         $productname = '充值';
         $identityid = $info->identityid;
         $card_top = $info->card_top;
         $card_last = $info->card_last;
         $phone = $info->phone;
         $orderexpdate = 20;
         $callbackurl = "http://120.27.40.36/yjpay-php-demo/callback.php";
         $userip = Yii::$app->request->userIP;
         if ($userip == '::1') {
             $userip = '127.0.0.1';
         }
         $pay = new yeepayClass();
         $respond = $pay->directPayment($orderid, $transtime, $amount, $productname, $identityid, $card_top, $card_last, $callbackurl, $userip, $orderexpdate);
         //充值信息通过了验证
         if (is_array($respond) && $respond['orderid'] == $orderid) {
             if ($respond['phone'] == $phone) {
                 /////TODO 测试环境下部发送
                 if (!$respond['smsconfirm']) {
                     //发送支付验证码
                     $result = $pay->sendValidateCode($orderid);
                     if (is_array($result) && $result['orderid'] == $orderid) {
                         $status = yeepay::CONFIRM;
                         $msg = "支付验证已发送";
                         $res = self::paymentLog($uid, $orderid, $transtime, $amount, $productname, $identityid, $orderexpdate, $phone, $userip, $status, $msg);
                         if ($res) {
                             $return = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => array('orderid' => $orderid, 'phone' => $phone));
                             return $return;
                         } else {
                             $return = array('errorNum' => '1', 'errorMsg' => '数据记录失败', 'data' => null);
                             return $return;
                         }
                     } else {
                         $status = yeepay::ERROR;
                         $msg = "支付验证码发送失败";
                         self::paymentLog($uid, $orderid, $transtime, $amount, $productname, $identityid, $orderexpdate, $phone, $userip, $status, $msg);
                         $return = array('errorNum' => '1', 'errorMsg' => '发送支付验证码失败', 'data' => null);
                         return $return;
                     }
                 } else {
                     //TODO
                     throw new ErrorException("不发送短信");
                 }
             } else {
                 $status = yeepay::ERROR;
                 $msg = "银行预留手机已更改";
                 self::paymentLog($uid, $orderid, $transtime, $amount, $productname, $identityid, $orderexpdate, $phone, $userip, $status, $msg);
                 $return = array('errorNum' => '1', 'errorMsg' => '银行预留手机已更改', 'data' => null);
                 return $return;
             }
         } else {
             $status = yeepay::ERROR;
             $msg = "用户信息错误";
             self::paymentLog($uid, $orderid, $transtime, $amount, $productname, $identityid, $orderexpdate, $phone, $userip, $status, $msg);
             $return = array('errorNum' => '1', 'errorMsg' => $respond, 'data' => null);
             return $return;
         }
     } else {
         $return = array('errorNum' => '1', 'errorMsg' => '用户未绑定银行卡', 'data' => null);
         return $return;
     }
 }