西来喜支付
This commit is contained in:
@@ -22,7 +22,7 @@ class Payment extends Controller
|
|||||||
* APP支付
|
* APP支付
|
||||||
*/
|
*/
|
||||||
public function app_pay() {
|
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);
|
$user_id = input('user_id', 0);
|
||||||
$money = input('money', 0);
|
$money = input('money', 0);
|
||||||
$coin = input('coin', 0);
|
$coin = input('coin', 0);
|
||||||
@@ -82,6 +82,11 @@ class Payment extends Controller
|
|||||||
Loader::import('TongLian.TongLian', EXTEND_PATH, '.php');
|
Loader::import('TongLian.TongLian', EXTEND_PATH, '.php');
|
||||||
$tonglian = new \TongLian();
|
$tonglian = new \TongLian();
|
||||||
$result['tl'] = $tonglian->TongLianPay($data, $type);
|
$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);
|
return V(1, 'app支付', $result);
|
||||||
@@ -314,4 +319,75 @@ class Payment extends Controller
|
|||||||
echo "fail";
|
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
135
extend/Xilaixi/Xilaixi.php
Normal file
135
extend/Xilaixi/Xilaixi.php
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use think\Env;
|
||||||
|
|
||||||
|
class Xilaixi
|
||||||
|
{
|
||||||
|
private $pid;
|
||||||
|
private $key;
|
||||||
|
private string $sign_type = 'MD5';
|
||||||
|
private string $mapi_url = 'https://wxjs.980city.com/mapi.php';
|
||||||
|
private string $api_url = 'https://wxjs.980city.com/api.php';//https://wxjs.980city.com/api.php?
|
||||||
|
|
||||||
|
function __construct(){
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
60
extend/Xilaixi/epayapi.php
Normal file
60
extend/Xilaixi/epayapi.php
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>正在为您跳转到支付页面,请稍候...</title>
|
||||||
|
<style type="text/css">
|
||||||
|
body{margin:0;padding:0}
|
||||||
|
p{position:absolute;left:50%;top:50%;height:35px;margin:-35px 0 0 -160px;padding:20px;font:bold 16px/30px "宋体",Arial;text-indent:40px;border:1px solid #c5d0dc}
|
||||||
|
#waiting{font-family:Arial}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once("lib/epay.config.php");
|
||||||
|
require_once("lib/EpayCore.class.php");
|
||||||
|
|
||||||
|
/**************************请求参数**************************/
|
||||||
|
$notify_url = "http://127.0.0.1/SDK/notify_url.php";
|
||||||
|
//需http://格式的完整路径,不能加?id=123这类自定义参数
|
||||||
|
|
||||||
|
//页面跳转同步通知页面路径
|
||||||
|
$return_url = "http://127.0.0.1/SDK/return_url.php";
|
||||||
|
//需http://格式的完整路径,不能加?id=123这类自定义参数
|
||||||
|
|
||||||
|
//商户订单号
|
||||||
|
$out_trade_no = $_POST['WIDout_trade_no'];
|
||||||
|
//商户网站订单系统中唯一订单号,必填
|
||||||
|
|
||||||
|
//支付方式(可传入alipay,wxpay,qqpay,bank,jdpay)
|
||||||
|
$type = $_POST['type'];
|
||||||
|
//商品名称
|
||||||
|
$name = $_POST['WIDsubject'];
|
||||||
|
//付款金额
|
||||||
|
$money = $_POST['WIDtotal_fee'];
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************************/
|
||||||
|
|
||||||
|
//构造要请求的参数数组,无需改动
|
||||||
|
$parameter = array(
|
||||||
|
"pid" => $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;
|
||||||
|
|
||||||
|
?>
|
||||||
|
<p>正在为您跳转到支付页面,请稍候...</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
205
extend/Xilaixi/index.php
Normal file
205
extend/Xilaixi/index.php
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
<?php
|
||||||
|
/* *
|
||||||
|
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||||
|
*/
|
||||||
|
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>彩虹易支付接口测试</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<style>
|
||||||
|
*{
|
||||||
|
margin:0;
|
||||||
|
padding:0;
|
||||||
|
}
|
||||||
|
ul,ol{
|
||||||
|
list-style:none;
|
||||||
|
}
|
||||||
|
.title{
|
||||||
|
color: #ADADAD;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: bold;
|
||||||
|
padding: 8px 16px 5px 10px;
|
||||||
|
}
|
||||||
|
.hidden{
|
||||||
|
display:none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.new-btn-login-sp{
|
||||||
|
border:1px solid #D74C00;
|
||||||
|
padding:1px;
|
||||||
|
display:inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.new-btn-login{
|
||||||
|
background-color: #ff8c00;
|
||||||
|
color: #FFFFFF;
|
||||||
|
font-weight: bold;
|
||||||
|
border: medium none;
|
||||||
|
width:82px;
|
||||||
|
height:28px;
|
||||||
|
}
|
||||||
|
.new-btn-login:hover{
|
||||||
|
background-color: #ffa300;
|
||||||
|
width: 82px;
|
||||||
|
color: #FFFFFF;
|
||||||
|
font-weight: bold;
|
||||||
|
height: 28px;
|
||||||
|
}
|
||||||
|
.bank-list{
|
||||||
|
overflow:hidden;
|
||||||
|
margin-top:5px;
|
||||||
|
}
|
||||||
|
.bank-list li{
|
||||||
|
float:left;
|
||||||
|
width:153px;
|
||||||
|
margin-bottom:5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main{
|
||||||
|
width:750px;
|
||||||
|
margin:0 auto;
|
||||||
|
font-size:14px;
|
||||||
|
font-family:'宋体';
|
||||||
|
}
|
||||||
|
#logo{
|
||||||
|
background-color: transparent;
|
||||||
|
background-image: url("images/new-btn-fixed.png");
|
||||||
|
border: medium none;
|
||||||
|
background-position:0 0;
|
||||||
|
width:166px;
|
||||||
|
height:35px;
|
||||||
|
float:left;
|
||||||
|
}
|
||||||
|
.red-star{
|
||||||
|
color:#f00;
|
||||||
|
width:10px;
|
||||||
|
display:inline-block;
|
||||||
|
}
|
||||||
|
.null-star{
|
||||||
|
color:#fff;
|
||||||
|
}
|
||||||
|
.content{
|
||||||
|
margin-top:5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content dt{
|
||||||
|
width:160px;
|
||||||
|
display:inline-block;
|
||||||
|
text-align:right;
|
||||||
|
float:left;
|
||||||
|
|
||||||
|
}
|
||||||
|
.content dd{
|
||||||
|
margin-left:100px;
|
||||||
|
margin-bottom:5px;
|
||||||
|
}
|
||||||
|
#foot{
|
||||||
|
margin-top:10px;
|
||||||
|
}
|
||||||
|
.foot-ul li {
|
||||||
|
text-align:center;
|
||||||
|
}
|
||||||
|
.note-help {
|
||||||
|
color: #999999;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 130%;
|
||||||
|
padding-left: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cashier-nav {
|
||||||
|
font-size: 14px;
|
||||||
|
margin: 15px 0 10px;
|
||||||
|
text-align: left;
|
||||||
|
height:30px;
|
||||||
|
border-bottom:solid 2px #CFD2D7;
|
||||||
|
}
|
||||||
|
.cashier-nav ol li {
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
.cashier-nav li.current {
|
||||||
|
color: #AB4400;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.cashier-nav li.last {
|
||||||
|
clear:right;
|
||||||
|
}
|
||||||
|
.alipay_link {
|
||||||
|
text-align:right;
|
||||||
|
}
|
||||||
|
.alipay_link a:link{
|
||||||
|
text-decoration:none;
|
||||||
|
color:#8D8D8D;
|
||||||
|
}
|
||||||
|
.alipay_link a:visited{
|
||||||
|
text-decoration:none;
|
||||||
|
color:#8D8D8D;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body text=#000000 bgColor=#ffffff leftMargin=0 topMargin=4>
|
||||||
|
<div id="main">
|
||||||
|
<div id="head">
|
||||||
|
<dl class="alipay_link">
|
||||||
|
</dl>
|
||||||
|
<span class="title">彩虹易支付接口测试</span>
|
||||||
|
</div>
|
||||||
|
<div class="cashier-nav">
|
||||||
|
<ol>
|
||||||
|
<li class="current">1、确认信息 →</li>
|
||||||
|
<li>2、点击确认 →</li>
|
||||||
|
<li class="last">3、确认完成</li>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
<form name=alipayment action=epayapi.php method=post target="_blank">
|
||||||
|
<div id="body" style="clear:left">
|
||||||
|
<dl class="content">
|
||||||
|
<dt>商户订单号:</dt>
|
||||||
|
<dd>
|
||||||
|
<span class="null-star">*</span>
|
||||||
|
<input size="30" name="WIDout_trade_no" value="<?php echo date("YmdHis").mt_rand(100,999); ?>"/>
|
||||||
|
<span>商户网站订单系统中唯一订单号,必填
|
||||||
|
</span>
|
||||||
|
</dd>
|
||||||
|
<dt>商品名称:</dt>
|
||||||
|
<dd>
|
||||||
|
<span class="null-star">*</span>
|
||||||
|
<input size="30" name="WIDsubject" value="测试商品"/>
|
||||||
|
<span>必填
|
||||||
|
</span>
|
||||||
|
</dd>
|
||||||
|
<dt>付款金额:</dt>
|
||||||
|
<dd>
|
||||||
|
<span class="null-star">*</span>
|
||||||
|
<input size="30" name="WIDtotal_fee" value="1"/>
|
||||||
|
<span>必填
|
||||||
|
</span>
|
||||||
|
</dd>
|
||||||
|
<dt>支付方式:</dt>
|
||||||
|
<dd>
|
||||||
|
<label><input type="radio" name="type" value="alipay" checked="">支付宝</label> <label><input type="radio" name="type" value="qqpay">QQ钱包</label> <label><input type="radio" name="type" value="wxpay">微信支付</label> <label><input type="radio" name="type" value="bank">云闪付</label>
|
||||||
|
</dd>
|
||||||
|
|
||||||
|
|
||||||
|
<dt></dt>
|
||||||
|
<dd>
|
||||||
|
<span class="new-btn-login-sp">
|
||||||
|
<button class="new-btn-login" type="submit" style="text-align:center;">确 认</button>
|
||||||
|
</span>
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<div id="foot">
|
||||||
|
<ul class="foot-ul">
|
||||||
|
<li><font class="note-help">如果您点击“确认”按钮,即表示您同意该次的执行操作。 </font></li>
|
||||||
|
<li>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
154
extend/Xilaixi/lib/EpayCore.class.php
Normal file
154
extend/Xilaixi/lib/EpayCore.class.php
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
<?php
|
||||||
|
/* *
|
||||||
|
* 彩虹易支付SDK服务类
|
||||||
|
* 说明:
|
||||||
|
* 包含发起支付、查询订单、回调验证等功能
|
||||||
|
*/
|
||||||
|
|
||||||
|
class EpayCore
|
||||||
|
{
|
||||||
|
private $pid;
|
||||||
|
private $key;
|
||||||
|
private $submit_url;
|
||||||
|
private $mapi_url;
|
||||||
|
private $api_url;
|
||||||
|
private $sign_type = 'MD5';
|
||||||
|
|
||||||
|
function __construct($config){
|
||||||
|
$this->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 = '<form id="dopay" action="'.$this->submit_url.'" method="post">';
|
||||||
|
foreach ($param as $k=>$v) {
|
||||||
|
$html.= '<input type="hidden" name="'.$k.'" value="'.$v.'"/>';
|
||||||
|
}
|
||||||
|
$html .= '<input type="submit" value="'.$button.'"></form><script>document.getElementById("dopay").submit();</script>';
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
13
extend/Xilaixi/lib/epay.config.php
Normal file
13
extend/Xilaixi/lib/epay.config.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
/* *
|
||||||
|
* 配置文件
|
||||||
|
*/
|
||||||
|
|
||||||
|
//支付接口地址
|
||||||
|
$epay_config['apiurl'] = 'http://pay.www.com/';
|
||||||
|
|
||||||
|
//商户ID
|
||||||
|
$epay_config['pid'] = '1000';
|
||||||
|
|
||||||
|
//商户密钥
|
||||||
|
$epay_config['key'] = 'WWc3Z2jkK7jhNGPALcGKjHLPK47wRK85';
|
||||||
45
extend/Xilaixi/notify_url.php
Normal file
45
extend/Xilaixi/notify_url.php
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
/* *
|
||||||
|
* 功能:彩虹易支付异步通知页面
|
||||||
|
* 说明:
|
||||||
|
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once("lib/epay.config.php");
|
||||||
|
require_once("lib/EpayCore.class.php");
|
||||||
|
|
||||||
|
//计算得出通知验证结果
|
||||||
|
$epay = new EpayCore($epay_config);
|
||||||
|
$verify_result = $epay->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";
|
||||||
|
}
|
||||||
|
?>
|
||||||
55
extend/Xilaixi/return_url.php
Normal file
55
extend/Xilaixi/return_url.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
/* *
|
||||||
|
* 功能:彩虹易支付页面跳转同步通知页面
|
||||||
|
* 说明:
|
||||||
|
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once("lib/epay.config.php");
|
||||||
|
require_once("lib/EpayCore.class.php");
|
||||||
|
?>
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<title>支付返回页面</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<?php
|
||||||
|
//计算得出通知验证结果
|
||||||
|
$epay = new EpayCore($epay_config);
|
||||||
|
$verify_result = $epay->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 "<h3>验证成功</h3><br />";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//验证失败
|
||||||
|
echo "<h3>验证失败</h3>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user