From 02f56a0de5191f18556d4efef53dbe49ede4b90a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Thu, 9 Oct 2025 20:08:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A5=BF=E6=9D=A5=E5=96=9C=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Payment.php | 78 +++++++++- extend/Xilaixi/Xilaixi.php | 135 ++++++++++++++++ extend/Xilaixi/epayapi.php | 60 ++++++++ extend/Xilaixi/index.php | 205 +++++++++++++++++++++++++ extend/Xilaixi/lib/EpayCore.class.php | 154 +++++++++++++++++++ extend/Xilaixi/lib/epay.config.php | 13 ++ extend/Xilaixi/notify_url.php | 45 ++++++ extend/Xilaixi/return_url.php | 55 +++++++ 8 files changed, 744 insertions(+), 1 deletion(-) create mode 100644 extend/Xilaixi/Xilaixi.php create mode 100644 extend/Xilaixi/epayapi.php create mode 100644 extend/Xilaixi/index.php create mode 100644 extend/Xilaixi/lib/EpayCore.class.php create mode 100644 extend/Xilaixi/lib/epay.config.php create mode 100644 extend/Xilaixi/notify_url.php create mode 100644 extend/Xilaixi/return_url.php diff --git a/application/api/controller/Payment.php b/application/api/controller/Payment.php index 3bc4e6f..5413468 100644 --- a/application/api/controller/Payment.php +++ b/application/api/controller/Payment.php @@ -22,7 +22,7 @@ class Payment extends Controller * APP支付 */ public function app_pay() { - $type = input('type', 0); //1-微信 2-支付宝 4-通联支付宝 5-通联微信 + $type = input('type', 0); //1-微信 2-支付宝 4-通联支付宝 5-通联微信 6-西来喜微信,7-西来喜支付宝,8-西来喜QQ钱包,9-西来喜云闪付 $user_id = input('user_id', 0); $money = input('money', 0); $coin = input('coin', 0); @@ -82,6 +82,11 @@ class Payment extends Controller Loader::import('TongLian.TongLian', EXTEND_PATH, '.php'); $tonglian = new \TongLian(); $result['tl'] = $tonglian->TongLianPay($data, $type); + }elseif ($type == 6 || $type == 7 || $type == 8 || $type == 9){ + //引用西来喜 + Loader::import('Xilaixi.Xilaixi', EXTEND_PATH, '.php'); + $xilaixi = new \Xilaixi(); + $result['xlx'] = $xilaixi->XilaixiPay($data, $type); } return V(1, 'app支付', $result); @@ -314,4 +319,75 @@ class Payment extends Controller echo "fail"; } } + + //西来喜支付回调 + public function XilaixiPayNotify(){ + //引用西来喜 + Loader::import('Xilaixi.Xilaixi', EXTEND_PATH, '.php'); + $xilaixi = new \Xilaixi(); + $verify_result = $xilaixi->verifyNotify(); + + if($verify_result) {//验证成功 + + //商户订单号 + $out_trade_no = $_GET['out_trade_no']; + + //彩虹易支付交易号 + $trade_no = $_GET['trade_no']; + + //交易状态 + $trade_status = $_GET['trade_status']; + + //支付方式 + $type = $_GET['type']; + + //6-西来喜微信,7-西来喜支付宝,8-西来喜QQ钱包,9-西来喜云闪付 + if($type == 'wxpay'){ + $pay_type = 6; + }elseif ($type == 'alipay'){ + $pay_type = 7; + }elseif ($type == 'qqpay'){ + $pay_type = 8; + }elseif ($type == 'bank'){ + $pay_type = 9; + }else{ + $pay_type = 0; + } + + //支付金额 + $money = $_GET['money']; + + if ($_GET['trade_status'] == 'TRADE_SUCCESS') { + //判断该笔订单是否在商户网站中已经做过处理 + //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 + //如果有做过处理,不执行商户的业务程序 + + Log::record("通联支付回调信息验签成功".json_encode($_GET),"info"); + //此处进行业务逻辑处理 + //成功后的业务逻辑处理 + $where['order_sn']=$out_trade_no; + $where['order_type']=1;//1 充值 + $where['pay_type']=$pay_type;//1微信2支付宝 3通联支付宝 4通联微信 //6-西来喜微信,7-西来喜支付宝,8-西来喜QQ钱包,9-西来喜云闪付 + + $data=[ + 'trade_no'=>$trade_no + ]; + + $res = handelCharge($where,$data); + if($res==0){ + echo "fail"; + return; + } + //验证成功返回 + echo "success"; + }else{ + echo "fail"; + } + + } + else { + //验证失败 + echo "fail"; + } + } } \ No newline at end of file diff --git a/extend/Xilaixi/Xilaixi.php b/extend/Xilaixi/Xilaixi.php new file mode 100644 index 0000000..3898bad --- /dev/null +++ b/extend/Xilaixi/Xilaixi.php @@ -0,0 +1,135 @@ +pid = Env::get('AllinPay.appId');//平台分配的APPID + $this->key = Env::get('AllinPay.appId');//平台分配的APPID + } + + /** + * 西来喜支付 + */ + public function XilaixiPay($date, $type) { + //6-西来喜微信,7-西来喜支付宝,8-西来喜QQ钱包,9-西来喜云闪付 + if($type == 6){ + $type = 'wxpay'; + }elseif ($type == 7){ + $type = 'alipay'; + }elseif ($type == 8){ + $type = 'qqpay'; + }elseif ($type == 9){ + $type = 'bank'; + } + //构造要请求的参数数组,无需改动 + $parameter = array( + "pid" => $this->pid, + "type" => $type, + "notify_url" => get_system_config_value("web_site")."/api/Payment/XilaixiPayNotify", + "return_url" => '', + "out_trade_no" => $date['order_sn'],//商户订单号, + "name" => $date['remarke'],//订单标题(不能有空格), + "money" => $date['money'], + ); + $param = $this->buildRequestParam($parameter); + $response = $this->getHttpResponse($this->mapi_url, http_build_query($param)); + return json_decode($response, true); + } + + private function buildRequestParam($param){ + $mysign = $this->getSign($param); + $param['sign'] = $mysign; + $param['sign_type'] = $this->sign_type; + return $param; + } + + // 计算签名 + private function getSign($param){ + ksort($param); + reset($param); + $signstr = ''; + + foreach($param as $k => $v){ + if($k != "sign" && $k != "sign_type" && $v!=''){ + $signstr .= $k.'='.$v.'&'; + } + } + $signstr = substr($signstr,0,-1); + $signstr .= $this->key; + $sign = md5($signstr); + return $sign; + } + + // 请求外部资源 + private function getHttpResponse($url, $post = false, $timeout = 10){ + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + $httpheader[] = "Accept: */*"; + $httpheader[] = "Accept-Language: zh-CN,zh;q=0.8"; + $httpheader[] = "Connection: close"; + curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + if($post){ + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); + } + $response = curl_exec($ch); + curl_close($ch); + return $response; + } + + // 异步回调验证 + public function verifyNotify(){ + if(empty($_GET)) return false; + + $sign = $this->getSign($_GET); + + if($sign === $_GET['sign']){ + $signResult = true; + }else{ + $signResult = false; + } + + return $signResult; + } + + + // 查询订单支付状态 + public function orderStatus($trade_no){ + $result = $this->queryOrder($trade_no); + if($result['status']==1){ + return true; + }else{ + return false; + } + } + + // 查询订单 + public function queryOrder($trade_no){ + $url = $this->api_url.'?act=order&pid=' . $this->pid . '&key=' . $this->key . '&trade_no=' . $trade_no; + $response = $this->getHttpResponse($url); + $arr = json_decode($response, true); + return $arr; + } + + // 订单退款 + public function refund($trade_no, $money){ + $url = $this->api_url.'?act=refund'; + $post = 'pid=' . $this->pid . '&key=' . $this->key . '&trade_no=' . $trade_no . '&money=' . $money; + $response = $this->getHttpResponse($url, $post); + $arr = json_decode($response, true); + return $arr; + } + +} \ No newline at end of file diff --git a/extend/Xilaixi/epayapi.php b/extend/Xilaixi/epayapi.php new file mode 100644 index 0000000..a91eba5 --- /dev/null +++ b/extend/Xilaixi/epayapi.php @@ -0,0 +1,60 @@ + + + + + + 正在为您跳转到支付页面,请稍候... + + + + $epay_config['pid'], + "type" => $type, + "notify_url" => $notify_url, + "return_url" => $return_url, + "out_trade_no" => $out_trade_no, + "name" => $name, + "money" => $money, +); + +//建立请求 +$epay = new EpayCore($epay_config); +$html_text = $epay->pagePay($parameter); +echo $html_text; + +?> +

正在为您跳转到支付页面,请稍候...

+ + \ No newline at end of file diff --git a/extend/Xilaixi/index.php b/extend/Xilaixi/index.php new file mode 100644 index 0000000..207f60c --- /dev/null +++ b/extend/Xilaixi/index.php @@ -0,0 +1,205 @@ + + + + + 彩虹易支付接口测试 + + + + +
+ +
+
    +
  1. 1、确认信息 →
  2. +
  3. 2、点击确认 →
  4. +
  5. 3、确认完成
  6. +
+
+
+
+
+
商户订单号:
+
+ * + "/> + 商户网站订单系统中唯一订单号,必填 + +
+
商品名称:
+
+ * + + 必填 + +
+
付款金额:
+
+ * + + 必填 + +
+
支付方式:
+
+      +
+ + +
+
+ +
+
+
+
+ +
+ + \ No newline at end of file diff --git a/extend/Xilaixi/lib/EpayCore.class.php b/extend/Xilaixi/lib/EpayCore.class.php new file mode 100644 index 0000000..b3a5a78 --- /dev/null +++ b/extend/Xilaixi/lib/EpayCore.class.php @@ -0,0 +1,154 @@ +pid = $config['pid']; + $this->key = $config['key']; + $this->submit_url = $config['apiurl'].'submit.php'; + $this->mapi_url = $config['apiurl'].'mapi.php'; + $this->api_url = $config['apiurl'].'api.php'; + } + + // 发起支付(页面跳转) + public function pagePay($param_tmp, $button='正在跳转'){ + $param = $this->buildRequestParam($param_tmp); + + $html = '
'; + foreach ($param as $k=>$v) { + $html.= ''; + } + $html .= '
'; + + return $html; + } + + // 发起支付(获取链接) + public function getPayLink($param_tmp){ + $param = $this->buildRequestParam($param_tmp); + $url = $this->submit_url.'?'.http_build_query($param); + return $url; + } + + // 发起支付(API接口) + public function apiPay($param_tmp){ + $param = $this->buildRequestParam($param_tmp); + $response = $this->getHttpResponse($this->mapi_url, http_build_query($param)); + $arr = json_decode($response, true); + return $arr; + } + + // 异步回调验证 + public function verifyNotify(){ + if(empty($_GET)) return false; + + $sign = $this->getSign($_GET); + + if($sign === $_GET['sign']){ + $signResult = true; + }else{ + $signResult = false; + } + + return $signResult; + } + + // 同步回调验证 + public function verifyReturn(){ + if(empty($_GET)) return false; + + $sign = $this->getSign($_GET); + + if($sign === $_GET['sign']){ + $signResult = true; + }else{ + $signResult = false; + } + + return $signResult; + } + + // 查询订单支付状态 + public function orderStatus($trade_no){ + $result = $this->queryOrder($trade_no); + if($result['status']==1){ + return true; + }else{ + return false; + } + } + + // 查询订单 + public function queryOrder($trade_no){ + $url = $this->api_url.'?act=order&pid=' . $this->pid . '&key=' . $this->key . '&trade_no=' . $trade_no; + $response = $this->getHttpResponse($url); + $arr = json_decode($response, true); + return $arr; + } + + // 订单退款 + public function refund($trade_no, $money){ + $url = $this->api_url.'?act=refund'; + $post = 'pid=' . $this->pid . '&key=' . $this->key . '&trade_no=' . $trade_no . '&money=' . $money; + $response = $this->getHttpResponse($url, $post); + $arr = json_decode($response, true); + return $arr; + } + + private function buildRequestParam($param){ + $mysign = $this->getSign($param); + $param['sign'] = $mysign; + $param['sign_type'] = $this->sign_type; + return $param; + } + + // 计算签名 + private function getSign($param){ + ksort($param); + reset($param); + $signstr = ''; + + foreach($param as $k => $v){ + if($k != "sign" && $k != "sign_type" && $v!=''){ + $signstr .= $k.'='.$v.'&'; + } + } + $signstr = substr($signstr,0,-1); + $signstr .= $this->key; + $sign = md5($signstr); + return $sign; + } + + // 请求外部资源 + private function getHttpResponse($url, $post = false, $timeout = 10){ + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + $httpheader[] = "Accept: */*"; + $httpheader[] = "Accept-Language: zh-CN,zh;q=0.8"; + $httpheader[] = "Connection: close"; + curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + if($post){ + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); + } + $response = curl_exec($ch); + curl_close($ch); + return $response; + } +} diff --git a/extend/Xilaixi/lib/epay.config.php b/extend/Xilaixi/lib/epay.config.php new file mode 100644 index 0000000..5c1fe69 --- /dev/null +++ b/extend/Xilaixi/lib/epay.config.php @@ -0,0 +1,13 @@ +verifyNotify(); + +if($verify_result) {//验证成功 + + //商户订单号 + $out_trade_no = $_GET['out_trade_no']; + + //彩虹易支付交易号 + $trade_no = $_GET['trade_no']; + + //交易状态 + $trade_status = $_GET['trade_status']; + + //支付方式 + $type = $_GET['type']; + + //支付金额 + $money = $_GET['money']; + + if ($_GET['trade_status'] == 'TRADE_SUCCESS') { + //判断该笔订单是否在商户网站中已经做过处理 + //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 + //如果有做过处理,不执行商户的业务程序 + } + + //验证成功返回 + echo "success"; +} +else { + //验证失败 + echo "fail"; +} +?> \ No newline at end of file diff --git a/extend/Xilaixi/return_url.php b/extend/Xilaixi/return_url.php new file mode 100644 index 0000000..6c14466 --- /dev/null +++ b/extend/Xilaixi/return_url.php @@ -0,0 +1,55 @@ + + + + + + 支付返回页面 + + +verifyReturn(); + +if($verify_result) {//验证成功 + + //商户订单号 + $out_trade_no = $_GET['out_trade_no']; + + //支付宝交易号 + $trade_no = $_GET['trade_no']; + + //交易状态 + $trade_status = $_GET['trade_status']; + + //支付方式 + $type = $_GET['type']; + + + if($_GET['trade_status'] == 'TRADE_SUCCESS') { + //判断该笔订单是否在商户网站中已经做过处理 + //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 + //如果有做过处理,不执行商户的业务程序 + } + else { + echo "trade_status=".$_GET['trade_status']; + } + + echo "

验证成功


"; +} +else { + //验证失败 + echo "

验证失败

"; +} +?> + + \ No newline at end of file