gateUrl; } /** * 设置入口地址,不包含参数值 * * @param $gateUrl */ protected function setGateURL($gateUrl) { $this->gateUrl = $gateUrl; } /** * 获取参数值 * * @param $parameter * @return mixed */ protected function getParameter($parameter) { return $this->parameters[$parameter]; } /** * 设置参数值 * * @param $parameter * @param $parameterValue */ protected function setParameter($parameter, $parameterValue) { $this->parameters[$parameter] = $parameterValue; } /** * 获取所有请求的参数 * * @return array */ protected function getAllParameters() { return $this->parameters; } /** * 获取密钥 * * @return string */ function getKey() { return $this->key; } /** * 设置密钥 * * @param $key * @return void */ function setKey($key) { $this->key = $key; } /** * 预下单 * * @return array */ protected function preOrder() { $params = ksort($this->parameters); $params = array2xml($params); $response = ihttp_request($this->getGateURL(), $params); return $response; } public function encryption() {} protected function decryption() {} protected function noticeUrl() {} protected function returnUrl() {} /** * 统一化支付失败返回数据格式 * @param string $msg * @param array $result * @return array */ public function fail($msg = '',$result = []) { return ['status' => 0, 'msg' => $msg, 'data' => $result]; } /** * 统一化支付成功返回数据格式 * @param string $msg * @param array $result * @return array */ public function success($msg = '',$result = []) { return ['status' => 1, 'msg' => $msg, 'data' => $result]; } /** * 支付访问日志 * * @var void */ public static function payAccessLog() { PayAccessLog::create([ 'uniacid' => \YunShop::app()->uniacid?:0, 'member_id' => \YunShop::app()->getMemberId(), 'url' => self::getHttpURL(), 'http_method' => self::getHttpMethod(), 'ip' => self::getClientIP(), 'input' => file_get_contents('php://input'), ]); } /** * 支付日志 * * @param $type * @param $third_type * @param $price * @param $operation */ public static function payLog($type, $third_type, $price, $operation, $member_id) { PayLog::create([ 'uniacid' => \YunShop::app()->uniacid, 'member_id' => $member_id, 'type' => $type, 'third_type' => $third_type, 'price' => $price, 'operation' => $operation, 'ip' => self::getClientIP() ]); } /** * 支付单 * * @param $out_order_no 订单号 * @param $status 支付单状态 * @param $type 支付类型 * @param $third_type 支付方式 * @param $price 支付金额 */ public static function payOrder($out_order_no, $status, $type, $third_type, $price) { return PayOrder::create([ 'uniacid' => \YunShop::app()->uniacid, 'member_id' => \YunShop::app()->getMemberId(), 'int_order_no' => self::createPayOrderNo(), 'out_order_no' => $out_order_no, 'status' => $status, 'type' => $type, 'third_type' => $third_type, 'price' => $price ]); } protected function payWithdrawOrder($out_order_no, $status, $third_type, $price) { return PayWithdrawOrder::create([ 'uniacid' => \YunShop::app()->uniacid, 'member_id' => \YunShop::app()->getMemberId(), 'int_order_no' => self::createPayOrderNo(), 'out_order_no' => $out_order_no, 'status' => $status, 'type' => $third_type, 'price' => $price ]); } protected function payRefundOrder($out_order_no, $status, $third_type, $price) { return PayRefundOrder::create([ 'uniacid' => \YunShop::app()->uniacid, 'member_id' => \YunShop::app()->getMemberId(), 'int_order_no' => self::createPayOrderNo(), 'out_order_no' => $out_order_no, 'status' => $status, 'type' => $third_type, 'price' => $price ]); } /** * 支付请求数据记录 * * @param string $out_order_no 订单号 * @param int $type 支付类型 * @param string $third_type 支付方式 * @param array $params 请求数据 */ public static function payRequestDataLog($out_order_no, $type, $third_type, $params) { PayRequestDataLog::create([ 'uniacid' => \YunShop::app()->uniacid, 'out_order_no' => $out_order_no, 'type' => $type, 'third_type' => $third_type, 'params' => $params ]); } /** * 支付响应数据记录 * * @param $out_order_no 订单号 * @param $third_type 支付方式 * @param $params 响应结果 */ public static function payResponseDataLog($out_order_no, $third_type, $params) { PayResponseDataLog::create([ 'uniacid' => \YunShop::app()->uniacid ? : 0, 'out_order_no' => $out_order_no, 'third_type' => $third_type, 'params' => $params ]); } /** * 支付单号 * * 格式:P+YYMMDD+31位流水号(数字+字母) * * @return string */ private static function createPayOrderNo() { return 'P' . date('Ymd', time()) . self::generate_string(23); } /** * 创建退款/提现订单批次号 * * @param $uniacid 统一公众号 * @param $strleng 统一公众号长度 * @return string */ public static function setUniacidNo($uniacid, $strleng=5) { $part1 = date('Ymd', time()); $part2 = self::generate_string(); $uniacid_lenght = strlen($uniacid); if ($uniacid_lenght > $strleng) { return self::INVALID_UNIACID_LENGTH; } if ($uniacid_lenght >= 1 && $uniacid_lenght <= $strleng) { $part3 = sprintf("%0{$strleng}s", $uniacid); } else { return self::INVALID_UNIACID_LENGTH; } return $part1 . substr($part2, 0, 9) . $part3 . substr($part2, 9); } /** * 退款/提现流水号 * * @param int $length * @return string */ private static function generate_string ($length = 19) { $nps = ""; for($i=0;$i<$length;$i++) { $nps .= chr((mt_rand(1, 36) <= 26) ? mt_rand(97, 122) : mt_rand(48, 57 )); } return $nps; } /** * 支付日志 * * @param $type * @param $third_type * @param $amount * @param $operation * @param $order_no * @param $status * * @return mixed */ protected function log($type, $third_type, $amount, $operation, $order_no, $status, $member_id) { //访问日志 self::payAccessLog(); //支付日志 self::payLog($type, $third_type, $amount, $operation, $member_id); //支付单记录 $model = self::payOrder($order_no, $status, $type, $third_type, $amount); return $model; } /** * 退款日志 * * @param $type * @param $third_type * @param $amount * @param $operation * @param $order_no * @param $status * * @return mixed */ protected function refundlog($type, $third_type, $amount, $operation, $order_no, $status, $member_id) { //访问日志 self::payAccessLog(); //支付日志 self::payLog($type, $third_type, $amount, $operation, $member_id); //退款单记录 $model = self::payRefundOrder($order_no, $status, $third_type, $amount); return $model; } /** * 提现日志 * * @param $type * @param $third_type * @param $amount * @param $operation * @param $order_no * @param $status * * @return mixed */ protected function withdrawlog($type, $third_type, $amount, $operation, $order_no, $status, $member_id) { //访问日志 self::payAccessLog(); //支付日志 self::payLog($type, $third_type, $amount, $operation, $member_id); //提现单记录 $model = self::payWithdrawOrder($order_no, $status, $third_type, $amount); return $model; } }