feat: 添加噜噜支付SDK和前端懒加载指令

This commit is contained in:
AIGC Developer
2026-01-06 14:33:01 +08:00
parent a99cfa28e5
commit a66bd806b2
32 changed files with 1236 additions and 114 deletions

59
SDK_2.0/SDK/epayapi.php Normal file
View File

@@ -0,0 +1,59 @@
<!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['out_trade_no'];
//商户网站订单系统中唯一订单号,必填
//支付方式可传入alipay,wxpay,qqpay,bank,jdpay
$type = $_POST['type'];
//商品名称
$name = $_POST['name'];
//付款金额
$money = $_POST['money'];
/************************************************************/
//构造要请求的参数数组,无需改动
$parameter = array(
"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>

61
SDK_2.0/SDK/index.php Normal file
View File

@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="zh-CN">
<body>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>彩虹易支付接口测试</title>
<link href="//lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<link rel="stylesheet" href="./assets/css/captcha.css" type="text/css" />
<style>.form-group{margin-bottom:18px} #captcha{margin: auto;margin-bottom:16px}</style>
</head>
<div class="container">
<div class="col-xs-12 col-sm-10 col-lg-8 center-block" style="float: none;">
<div class="page-header">
<h4>彩虹易支付接口测试</h4>
</div>
<div class="panel panel-primary">
<div class="panel-body">
<form name="alipayment" method="POST" action="epayapi.php" class="form-horizontal">
<div class="form-group">
<label class="col-sm-3 control-label">商户订单号</label>
<div class="col-sm-8">
<input class="form-control" type="text" name="out_trade_no" value="<?php echo date("YmdHis").mt_rand(100,999); ?>" autocomplete="off">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">商品名称</label>
<div class="col-sm-8">
<input class="form-control" type="text" name="name" value="支付测试" autocomplete="off">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">支付金额</label>
<div class="col-sm-8">
<input class="form-control" type="text" name="money" value="1" autocomplete="off">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">支付方式</label>
<div class="col-sm-8">
<div class="radio">
<label class="i-checks"><input type="radio" name="type" value="alipay" checked="checked"><i></i>支付宝</label>&nbsp;
<label class="i-checks"><input type="radio" name="type" value="wxpay"><i></i>微信支付</label>&nbsp;
<label class="i-checks"><input type="radio" name="type" value="qqpay"><i></i>QQ钱包</label>&nbsp;
<label class="i-checks"><input type="radio" name="type" value="bank"><i></i>云闪付</label>&nbsp;
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-8"><input type="submit" value="确 认" class="btn btn-primary form-control"><br>
</div>
</div>
</form>
</div>
<div class="panel-footer text-center">
<span class="text-muted">此页面只是为了方便商户测试而提供的样例页面,商户可以根据自己网站的需要,按照技术文档编写</span>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,184 @@
<?php
/* *
* 彩虹易支付SDK服务类
* 说明:
* 包含发起支付、查询订单、回调验证等功能
*/
class EpayCore
{
private $apiurl;
private $pid;
private $platform_public_key;
private $merchant_private_key;
private $sign_type = 'RSA';
function __construct($config){
$this->apiurl = $config['apiurl'];
$this->pid = $config['pid'];
$this->platform_public_key = $config['platform_public_key'];
$this->merchant_private_key = $config['merchant_private_key'];
}
// 发起支付(页面跳转)
public function pagePay($param_tmp, $button='正在跳转'){
$requrl = $this->apiurl.'api/pay/submit';
$param = $this->buildRequestParam($param_tmp);
$html = '<form id="dopay" action="'.$requrl.'" 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){
$requrl = $this->apiurl.'api/pay/submit';
$param = $this->buildRequestParam($param_tmp);
$url = $requrl.'?'.http_build_query($param);
return $url;
}
// 发起支付API接口
public function apiPay($params){
return $this->execute('api/pay/create', $params);
}
// 发起API请求
public function execute($path, $params){
$path = ltrim($path, '/');
$requrl = $this->apiurl.$path;
$param = $this->buildRequestParam($params);
$response = $this->getHttpResponse($requrl, http_build_query($param));
$arr = json_decode($response, true);
if($arr && $arr['code'] == 0){
if(!$this->verify($arr)){
throw new \Exception('返回数据验签失败');
}
return $arr;
}else{
throw new \Exception($arr ? $arr['msg'] : '请求失败');
}
}
// 回调验证
public function verify($arr){
if(empty($arr) || empty($arr['sign'])) return false;
if(empty($arr['timestamp']) || abs(time() - $arr['timestamp']) > 300) return false;
$sign = $arr['sign'];
return $this->rsaPublicVerify($this->getSignContent($arr), $sign);
}
// 查询订单支付状态
public function orderStatus($trade_no){
$result = $this->queryOrder($trade_no);
if($result && $result['status']==1){
return true;
}else{
return false;
}
}
// 查询订单
public function queryOrder($trade_no){
$params = [
'trade_no' => $trade_no,
];
return $this->execute('api/pay/query', $params);
}
// 订单退款
public function refund($out_refund_no, $trade_no, $money){
$params = [
'trade_no' => $trade_no,
'money' => $money,
'out_refund_no' => $out_refund_no,
];
return $this->execute('api/pay/refund', $params);
}
private function buildRequestParam($params){
$params['pid'] = $this->pid;
$params['timestamp'] = time().'';
$mysign = $this->getSign($params);
$params['sign'] = $mysign;
$params['sign_type'] = $this->sign_type;
return $params;
}
// 生成签名
private function getSign($params){
return $this->rsaPrivateSign($this->getSignContent($params));
}
// 获取待签名字符串
private function getSignContent($params){
ksort($params);
$signstr = '';
foreach ($params as $k => $v) {
if(is_array($v) || $this->isEmpty($v) || $k == 'sign' || $k == 'sign_type') continue;
$signstr .= '&' . $k . '=' . $v;
}
$signstr = substr($signstr, 1);
return $signstr;
}
private function isEmpty($value)
{
return $value === null || trim($value) === '';
}
// 商户私钥签名
private function rsaPrivateSign($data){
$key = "-----BEGIN PRIVATE KEY-----\n" .
wordwrap($this->merchant_private_key, 64, "\n", true) .
"\n-----END PRIVATE KEY-----";
$privatekey = openssl_get_privatekey($key);
if(!$privatekey){
throw new \Exception('签名失败,商户私钥错误');
}
openssl_sign($data, $sign, $privatekey, OPENSSL_ALGO_SHA256);
return base64_encode($sign);
}
// 平台公钥验签
private function rsaPublicVerify($data, $sign){
$key = "-----BEGIN PUBLIC KEY-----\n" .
wordwrap($this->platform_public_key, 64, "\n", true) .
"\n-----END PUBLIC KEY-----";
$publickey = openssl_get_publickey($key);
if (!$publickey) {
throw new \Exception("验签失败,平台公钥错误");
}
$result = openssl_verify($data, base64_decode($sign), $publickey, OPENSSL_ALGO_SHA256);
return $result === 1;
}
// 请求外部资源
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;
}
}

View File

@@ -0,0 +1,19 @@
<?php
/* *
* 配置文件
*/
$epay_config = [
//支付接口地址
'apiurl' => 'http://pay.www.com/',
//商户ID
'pid' => '1000',
//平台公钥
'platform_public_key' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApHG7SIN16fd9uZfjZunZuAReemVQe5YNxBhbkogsRkZ86xuDVDCmhRXEzw7Ta3tXPnMIFRJFdjOCfFVarqcOLICtBiiZZ7Y4D6aIMhmOSliIJ3qWUnU75Wr2WMTIJ1o2pnPmczQ2YjAAy1DtQCc/qs35j24zuNYZw2WluSdiMckPFgge93RK6cq/Feqfuzq7y+m87x02gxbbTGVf24YH2f7H9qZSKCxRXHQoVIWTlyHULcY3OY+1CVdU2SKlIWHJ31eoPznXBLUo0UB0rNZnYrHG2mIlD2S119UTwZwx9WTG/v7Cb2lHVybjfL5/KLitddfqcLjJsYXh6KhEtsO6CwIDAQAB',
//商户私钥
'merchant_private_key' => 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCBIB1e5lAYtFyXq5I8UIQ6KidYZcWkn0SwVS8Rk0SNZVrvL/UJk6Q1zkJs4pUCykTBS/tTrP2rNPOsK1VO/AQHIzhvAujsv7UK2LptcsuNRPCF5GYxndQnOawAGKNQKsMuNcDzyuyTMbZIBEYSRWIoU3dMz4wWEFso/VdVS4uKTZWZnBOeCDdzDAJ7TwbmaOkT919DfZbXAoMH9n3sG4BMpqQExTDoFY6dq6EPXCWVZgoUfecAgNKSfX5TagSUaAxq4eF5vsUfvj+LFpYIrIssmSVErtZuRXLHWVSEbsNxdDPNuS3BtxWEY7GRPF9RJevtoC5L5LN7Gn+RYCqZNZv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YUqwouTEgp7rE36wQ28THj0a88HLU4CeiCR6LQAEGpKk04Vst97C1Q5ZeD5rc4xKINl8K5HUH8SsdMDq3r22xur2qr4kanW4hf2P/ehOeEKGuhSL+ZWeApvt1c0rqH4MQT1/7qR/dO2MikkMg=',
];

View 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->verify($_GET);
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";
}
?>

17
SDK_2.0/SDK/query.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
/**
* 查询订单
*/
require_once("lib/epay.config.php");
require_once("lib/EpayCore.class.php");
$trade_no = '2024071519404366151';
$epay = new EpayCore($epay_config);
try{
$result = $epay->queryOrder($trade_no);
}catch(Exception $e){
echo $e->getMessage();
exit;
}
print_r($result);

19
SDK_2.0/SDK/refund.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
/**
* 退款
*/
require_once("lib/epay.config.php");
require_once("lib/EpayCore.class.php");
$out_refund_no = date("YmdHis").rand(111,999);
$trade_no = '2024071519404366151';
$money = '1.00';
$epay = new EpayCore($epay_config);
try{
$result = $epay->refund($out_refund_no, $trade_no, $money);
}catch(Exception $e){
echo $e->getMessage();
exit;
}
print_r($result);

View 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->verify($_GET);
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>