/** * 短信确认支付 * @param $orderid 订单号 * @param $validatecode 手机验证码 * @return bool * @throws ErrorException */ public static function confirmPayment($orderid, $validatecode) { $info = Payment::findOne(['orderid' => $orderid, 'status' => yeepay::CONFIRM]); if ($info) { if ($validatecode != "" && strlen($validatecode) == 6) { $pay = new yeepayClass(); $respond = $pay->confirmPayment($orderid, $validatecode); if (is_array($respond) && $respond['orderid'] == $orderid) { $info->yborderid = $respond['yborderid']; $info->ybamount = $respond['amount']; $info->msg = "验证中"; $flag = $info->save(); if ($flag) { ////TODO callbackurl //必须有等待时间---》进行数据处理 sleep(15); //使用交易记录进行订单的查询---确认充值的情况 $res = self::paymentQuery($orderid, $respond['yborderid']); if ($res['status'] == 0) { $info->status = yeepay::ERROR; $info->msg = "充值失败"; $info->save(); throw new ErrorException("充值失败"); } elseif ($res['status'] == 2) { $info->msg = "未处理"; throw new ErrorException("未处理"); } elseif ($res['status'] == 3) { sleep(10); $res = self::paymentQuery($orderid, $respond['yborderid']); if ($res['status'] == 1) { $info->msg = "充值成功"; $info->status = yeepay::SUCCEED; $flag = $info->save(); if ($flag) { $return['uid'] = $info->uid; $return['money'] = $res['amount']; $return['orderid'] = $res['orderid']; return $return; } } else { throw new ErrorException("操作超时"); } } elseif ($res['status'] == 1) { $info->msg = "充值成功"; $info->status = yeepay::SUCCEED; $flag = $info->save(); if ($flag) { $return['uid'] = $info->uid; $return['money'] = $res['amount']; $return['orderid'] = $res['orderid']; return $return; } else { throw new ErrorException('写入数据失败'); } } else { $info->status = yeepay::ERROR; $info->msg = "未知错误"; $info->save(); throw new ErrorException('未知错误'); } } else { throw new ErrorException('写入数据库失败'); } } else { $info->msg = (string) $respond; $info->save(); throw new ErrorException((string) $respond); } } else { throw new ErrorException('请正确填写验证码'); } } else { throw new ErrorException('订单号错误'); } }
/** * 短信确认支付 * @param $orderid 订单号 * @param $validatecode 手机验证码 * @return bool * @throws ErrorException */ public static function confirmPayment($orderid, $validatecode) { $info = Payment::findOne(['orderid' => $orderid, 'status' => yeepay::CONFIRM]); if ($info) { if ($validatecode != "" && strlen($validatecode) == 6) { $pay = new yeepayClass(); $respond = $pay->confirmPayment($orderid, $validatecode); if (is_array($respond) && $respond['orderid'] == $orderid) { $info->yborderid = $respond['yborderid']; $info->ybamount = $respond['amount']; $info->msg = "验证中"; $flag = $info->save(); if ($flag) { ////TODO callbackurl //必须有等待时间---》进行数据处理 sleep(15); //使用交易记录进行订单的查询---确认充值的情况 $res = self::paymentQuery($orderid, $respond['yborderid']); if ($res['status'] == 0) { $info->status = yeepay::ERROR; $info->msg = "充值失败"; $info->save(); $return = array('errorNum' => '1', 'errorMsg' => '充值失败', 'data' => null); return $return; } elseif ($res['status'] == 2) { $info->msg = "未处理"; $return = array('errorNum' => '1', 'errorMsg' => '未处理', 'data' => null); return $return; } elseif ($res['status'] == 3) { sleep(10); $res = self::paymentQuery($orderid, $respond['yborderid']); if ($res['status'] == 1) { $info->msg = "充值成功"; $info->status = yeepay::SUCCEED; $flag = $info->save(); if ($flag) { $return = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => array('uid' => $info->uid, 'money' => $res['amount'], 'orderid' => $res['orderid'])); return $return; } } else { $return = array('errorNum' => '1', 'errorMsg' => '操作超时', 'data' => null); return $return; } } elseif ($res['status'] == 1) { $info->msg = "充值成功"; $info->status = yeepay::SUCCEED; $flag = $info->save(); if ($flag) { $return = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => array('uid' => $info->uid, 'money' => $res['amount'], 'orderid' => $res['orderid'])); return $return; } else { $return = array('errorNum' => '1', 'errorMsg' => '写入数据失败', 'data' => null); return $return; } } else { $info->status = yeepay::ERROR; $info->msg = "未知错误"; $info->save(); $return = array('errorNum' => '1', 'errorMsg' => '未知错误', 'data' => null); return $return; } } else { $return = array('errorNum' => '1', 'errorMsg' => '写入数据库失败', 'data' => null); return $return; } } else { $info->msg = (string) $respond; $info->save(); $return = array('errorNum' => '1', 'errorMsg' => (string) $respond, 'data' => null); return $return; } } else { $return = array('errorNum' => '1', 'errorMsg' => '请正确填写验证码', 'data' => null); return $return; } } else { $return = array('errorNum' => '1', 'errorMsg' => '订单号错误', 'data' => null); return $return; } }
/** * Finds the Payment model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Payment the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Payment::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }