彩虹易支付-易支付对接易支付 漏单自助补单插件

远昔 代码记录 2024-03-10 629 0

前言:今天朋友易支付网站(彩虹易支付系统串接),上游易支付订单状态是支付成功(没漏单),他网站订单却是未支付状态(漏单)。听他说检查了服务器宽带+cpu+磁盘读写都不高,程序也没改动过,以前也不漏单,就很莫名其妙,但我估计是他检查得不及时,可能之前服务器被攻击了,导致的他网站漏单!

于是朋友叫我帮忙写个自助补单插件:

原理①:用户提交订单号,然后自动对上游易支付订单状态进行比对,若上游订单是支付成功,而他网站订单是未支付(漏单),则进行自动补单!

原理②:虽然彩虹系统自带有订单异步通知重试任务功能,但是此插件任然会判断订单是否通知成功,不成功的话,又再异步通知一遍!

有能力的话,可自行加个极限验证之类的,不多说了,下方直接上代码与演示图:

<? include("./includes/common.php"); //在网站根目录随便创建一个php文件放入此代码 即可使用!
$act=isset($_GET['act'])?daddslashes($_GET['act']):null;
if($act=="budan"){
header('Access-Control-Allow-Origin:*'); // *代表允许任何网址请求
header('Content-type: application/json');
$order=trim(daddslashes($_POST['order']));
if(!preg_match("/[0-9]/",$order)){ exit(json_encode(['code'=>202,'msg'=>'请输入正确的数字订单号!'] ,JSON_UNESCAPED_UNICODE)); }
$order=array_unique(explode("\n", $order));

if($order==null){ exit(json_encode(['code'=>202,'msg'=>'订单号不能为空!'] ,JSON_UNESCAPED_UNICODE)); }
if(!is_array($order)){ exit(json_encode(['code'=>202,'msg'=>'请输入正确的订单号!'] ,JSON_UNESCAPED_UNICODE)); }
if(count($order)>10){ exit(json_encode(['code'=>202,'msg'=>'为避免系统超时,每次最多输入十个订単号!'] ,JSON_UNESCAPED_UNICODE)); }

foreach($order as $row){
$row=trim($row);
if(!preg_match("/^[1-9][0-9]*$/" ,$row)){ $return.=$row.'-数字订单号不正确!'; continue; }
if(mb_strlen($row,'utf8')<=14){ $return.=$row.'-订单号长度不正确!'; continue; }
$info=$DB->getRow("SELECT * FROM `pre_order` WHERE `trade_no` = '{$row}' or  `out_trade_no` = '{$row}' or  `api_trade_no` = '{$row}' limit 1");
if(!$info){  $return.=$row.'-订单号不存在系统!'; continue; }
if($info['status']==1&&$info['notify']==0){  $return.=$row.'-订单状态正常 无需补单!'; continue; }

if($info['status']==1&&$info['notify']<=1){
$url=creat_callback($info['trade_no']);
if(do_notify($url['notify'])){ $DB->exec("UPDATE pre_order SET notify=0 WHERE trade_no='{$info['trade_no']}'"); } //状态改为通知成功
$return.=$row.'-订単已支付了-执行异步通知回调!'; continue;  }

if($info['status']!=1){
$channel=$DB->getRow("SELECT * FROM `pre_channel` WHERE `id` ='{$info['channel']}' limit 1");
if(!$channel||$channel['plugin']!='epay'){ $return.=$row.'-此订单的支付插件无法使用自助补单!'; continue;  }
$epay_url=$channel['appurl'].'api.php?act=order&'; $epay_id=$channel['appid']; $epay_key=$channel['appkey'];
if($epay_id==null||$epay_key==null){ $return.=$row.'-此订单的支付插件配置信息不完整!'; continue;  }
$bu=json_decode(get_curl($epay_url.'pid='.$epay_id.'&key='.$epay_key.'&out_trade_no='.$info['trade_no']) ,true);
if($bu['code']!=1){ $return.=$row.'-支付订单系统运行出错,请稍后重试!'; continue; }
if($bu['status']!=1){ $return.=$row.'-已查询确认,此订单未支付,没有漏単!'; continue; }
if($bu['status']==1){
	if($DB->exec("update `pre_order` set `status` ='1' where `trade_no`='{$info['trade_no']}'")){
		$DB->exec("update `pre_order` set `endtime` =NOW(),`date` =NOW() where `trade_no`='{$info['trade_no']}'");
processOrder($info);
$return.=$row.'-未支付漏单,系统已自动补单!'; continue;
	} }
$return.=$row.'-补单查询出错拉,请联系站长反馈!'; continue; } }
$return=str_replace('!','!<br>',$return);
exit(json_encode(['code'=>200,'msg'=>$return] ,JSON_UNESCAPED_UNICODE));


}else
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>自助补单 - <?=$conf['sitename']?></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="//yuanxiapi.cn/assets/public/layui/2.5.7/css/layui.css" media="all">

    <style>
        body {background: #1E9FFF;}

        body:after {
            content: '';
            background-repeat: no-repeat;
            background-size: cover;
            -webkit-filter: blur(3px);
            -moz-filter: blur(3px);
            -o-filter: blur(3px);
            -ms-filter: blur(3px);
            filter: blur(3px);
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            z-index: -1;
        }

        .layui-container {
            margin-top: 4%;
        }

        .admin-login-background {
            width: 96%;
            height: auto;
        }

        .logo-title {
            text-align: center;
            letter-spacing: 2px;
            padding: 14px 0;
        }

        .logo-title h1 {
            color: #1E9FFF;
            font-size: 25px;
            font-weight: bold;
        }

        .login-form {
            background-color: #fff;
            border: 1px solid #fff;
            border-radius: 3px;
            padding: 14px 20px;
            box-shadow: 0 0 8px #eeeeee;
        }

        .login-form .layui-form-item {
            position: relative;
        }

        .login-form .layui-form-item label {
            position: absolute;
            left: 1px;
            top: 1px;
            width: 38px;
            line-height: 36px;
            text-align: center;
            color: #d2d2d2;
        }

        .login-form .layui-form-item input {
            padding-left: 36px;
        }

        .captcha {
            width: 60%;
            display: inline-block;
        }

        .captcha-img {
            display: inline-block;
            width: 34%;
            float: right;
        }

        .captcha-img img {
            height: 34px;
            border: 1px solid #e6e6e6;
            height: 36px;
            width: 100%;
        }

        .ccrow {
            border: 1px solid #9F9F9F;
            padding-top: 10px;
            margin-bottom: 10px;
        }

        .conttitle {
            color: #000;
            font-size: 15px;
            font-weight: bold;
            text-align: right;
            padding-right: 8px;
        }

        .cont1 {
            font-size: 14px;
            text-align: left;
        }
    </style>
</head>
<body>
    

    <div class="layui-container">
        <div class="admin-login-background">
            
            <div class="layui-form login-form">
<div class="layui-form-item logo-title"><h1><?=$conf['sitename']?>-自助补单</h1></div>
<div class="layui-elem-quote"><p>可用于未支付的漏单补单</p></div>


<form class="layui-form layui-form-pane" action="">
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">订单号</label>
<div class="layui-input-block">
<textarea placeholder="请输入系统订单号或商户订单号,一行一个!" class="layui-textarea" style="margin-top: 0px; margin-bottom: 0px; height: 159px;"  onmouseover="layer.tips('请输入订单号,一行一个,单次最多十个!<br>',this,{ tips:[1,&quot;black&quot;],closeBtn:1,time:9999999});" id="order"></textarea>
</div></div></form>
                    
                <div class="layui-form-item">
<button class="layui-btn layui-btn layui-btn-normal layui-btn-fluid" id="query_order">补单查询</button>
</div><br>
               
<hr class="layui-border-blue">
<div class="layui-form-item"><div style="margin-top:8px;">
<pre><font color="#FF0000">(1).</font><font color="#0000FF">请输入系统订单号或商户订单号,一行一个!</font></pre>
<pre><font color="#FF0000">(2).</font><font color="#0000FF">为了避免系统超时,每次最多输入十个订単号!</font></pre>
<pre><font color="#FF0000">(3).</font><font color="#0000FF">用于:未支付漏单或未能成功通知的订単可自动进行回调!</font></pre>
<pre><font color="#FF0000">(4).</font><font color="blue">彩虹易支付默认补单提示success是成功,ERROR或Fail是补单失败!</font></pre>
</div></div>


                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;text-align: center;padding-right: 35px;">
                    <legend>Copyright © <?=date("Y")?> - <?=$conf['sitename']?></legend>
                </fieldset>
                <div id="content_list"></div>
            </div>
        </div>
    </div>
<script src="//yuanxiapi.cn/assets/public/jquery/1.12.4/jquery.min.js"></script>
<script src="//yuanxiapi.cn/assets/public/layer/3.5.1/layer.js"></script>
<script> var area = [$(window).width() > 480 ? "500px" : "95%", ";max-height:100%"];

            $('#query_order').on('click', function() {
                var order = $("#order").val();
                if (!order) { layer.msg('订单号不能为空!'); return false; }

                var ii = layer.load(3, { shade: [0.3, '#000'],
success: function (layero) {
layero.find('.layui-layer-content').after('<div class="layer-load"><h4><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>努力补单中...</h4></div>');
  	layero.find('.layer-load').css({ transform: 'translateX(-50%) translateY(10px)',position: 'absolute',
  	 width: 'max-content',left: '50%', }); }
});
                $.ajax({
                    type: 'POST',
                    url: '?act=budan',
                    data : {order:order},
                    dataType: 'json',
                    cache: false,
                    success: function(data){ layer.close(ii);
if(data.code==200){
    layer.open({
        type: 1,title:"本次补单查询结果" 
        ,closeBtn:2  //关闭按钮,1 2和false
        ,shade: 0.8
        ,area: area
        ,btn: ["关闭窗口"]
    ,btnAlign: "c"
        ,anim:6 //弹出动画,6抖动
        ,moveType: 1 //拖拽模式,0或者1
        ,content:'<center><h4>'+data.msg+'</h4></center>'});

} else { layer.msg(data.msg); return false; }

},error: function(data) { layer.close(ii); layer.msg('服务器错误,请稍后重试!'); return false; }
                });
            });</script>
</body></html>


评论

发表评论:

挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论