public function checkSign() { $fields = \Input::All(); if (!\Input::has('sign') || true !== SignUtil::checkSign($fields)) { $this->ret['err_code'] = ErrCode::ERR_SIGN_ERROR; return $this->render(); } }
protected function render() { if (!isset($this->ret['channel'])) { $this->ret['channel'] = \Input::get('channel'); } $this->ret['is_success'] = $this->ret['err_code'] == ErrCode::ERR_SUCCESS ? 'T' : 'F'; $this->ret['sign'] = SignUtil::makeSign((array) $this->ret); return \Response::json($this->ret); }
public function returnAction($channel, $gateway, $merRechargeNo, $plat, $timestamp, $sign) { $fields = array('channel' => $channel, 'gateway' => $gateway, 'mer_recharge_no' => $merRechargeNo, 'plat' => $plat, 'timestamp' => $timestamp, 'sign' => $sign); $ret = $this->_checkParams($fields); if ($ret['err_code'] == ErrCode::ERR_SUCCESS) { $ret = SerReturnBiz::getInstance()->payReturn(array('mer_recharge_no' => $ret['mer_recharge_no'])); if ($ret->is_success == 'T') { $returnUrl = $ret->return_url; if ($ret->data) { $returnUrl .= false === strpos($returnUrl, '?') ? '?' : '&'; $ret->data->timestamp = time(); $ret->data->sign = Util\SignUtil::makeSign(get_object_vars($ret->data)); $params = get_object_vars($ret->data); while (list($key, $val) = each($params)) { $returnUrl .= $key . '=' . $val . '&'; } } return \Redirect::to($returnUrl); } } }
public function notifyCallback(BaseModel $order, $notifyType) { $params = new \stdClass(); if (!$order) { throw new PayException(ErrCode::ERR_ORDER_NO_EXISTS); } elseif ($order->callback_url == '') { throw new PayException(ErrCode::ERR_ORDER_NO_EXISTS, '订单callback_url不存在!'); } $params->channel = $order->channel; $params->user_id = $order->user_id; switch ($notifyType) { case 'direct': $params->is_success = $order->status == RechargeModel::STATUS_SUCCESS ? 'T' : 'F'; $params->error = $order->status == RechargeModel::STATUS_SUCCESS ? '' : '充值失败:' . $order->status; $params->pay_recharge_id = $order->id; $params->mer_recharge_no = $order->mer_recharge_no; $params->ser_recharge_no = $order->ser_recharge_no; $params->busi_recharge_no = $order->busi_recharge_no; $params->recharge_amount = $order->recharge_amount; $params->geteway = $order->gateway; $params->gateway_account = $order->gateway_account; break; case 'consume': $params->is_success = $order->status == RechargeModel::STATUS_SUCCESS ? 'T' : 'F'; $params->error = $order->status == RechargeModel::STATUS_SUCCESS ? '' : '消费失败:' . $order->status; $params->pay_consume_id = $order->id; $params->busi_consume_no = $order->busi_consume_no; $params->recharge_amount = $order->recharge_amount; $params->consume_amount = $order->consume_amount; $rechargeOrder = RechargeModel::find($order->recharge_id); if ($rechargeOrder) { $params->pay_recharge_id = $rechargeOrder->id; $params->recharge_amount = $rechargeOrder->recharge_amount; $params->geteway = $rechargeOrder->gateway; } break; case 'refund': $params->is_success = $order->ser_notify_status == RefundModel::STATUS_SUCCESS ? 'T' : 'F'; $params->error = $order->ser_notify_status == RefundModel::STATUS_SUCCESS ? '' : '退款失败:' . $order->ser_notify_log; $params->pay_refund_id = $order->id; $params->busi_refund_no = $order->busi_refund_no; $params->refund_amount = $order->amount; $params->gateway = $order->gateway; $params->refund_time = $order->refund_time; $rechargeOrder = RechargeModel::find($order->recharge_id); if ($rechargeOrder) { $params->mer_recharge_no = $rechargeOrder->mer_recharge_no; $params->recharge_amount = $rechargeOrder->recharge_amount; } break; case 'trans': $params->is_success = $order->ser_notify_status == TransModel::STATUS_SUCCESS ? 'T' : 'F'; $params->error = $order->ser_notify_status == TransModel::STATUS_SUCCESS ? '' : '提现失败:' . $order->ser_notify_log; $params->gateway = $order->gateway; $params->pay_trans_id = $order->id; $params->busi_trans_no = $order->busi_trans_no; $params->trans_amount = $order->trans_amount; $params->trans_time = $order->pay_time; break; default: throw new PayException(ErrCode::ERR_REQUEST_METHOD, "notifyFail. 未知通知类型:{$notifyType}"); break; } $params->timestamp = time(); $params->sign = SignUtil::makeSign(get_object_vars($params)); $ret = $this->_sendCallback($order->callback_url, $params); $order->callback_count++; $order->callback_time = time(); $order->callback_status = $ret == 'succeed' ? 2 : 1; $order->save(); return $ret == 'succeed' ? true : false; }