PaymentService.php 22.9 KB
Newer Older
D
v1.2.0  
devil_gong 已提交
1 2 3 4
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
D
devil_gong 已提交
5
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
D
v1.2.0  
devil_gong 已提交
6 7 8 9 10 11 12 13
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\service;

use think\Db;
14
use app\service\ResourcesService;
D
v1.2.0  
devil_gong 已提交
15 16 17 18 19 20 21 22 23 24 25

/**
 * 支付方式服务层
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-01T21:51:08+0800
 */
class PaymentService
{
    // 插件目录
26
    public static $payment_dir;
D
v1.2.0  
devil_gong 已提交
27 28

    // 支付业务类型
29
    public static $payment_business_type_all;
D
v1.2.0  
devil_gong 已提交
30 31

    // 不删除的支付方式
32
    public static $cannot_deleted_list;
D
v1.2.0  
devil_gong 已提交
33 34

    // 入口文件位置
35
    public static $dir_root_path;
D
v1.2.0  
devil_gong 已提交
36 37 38 39 40 41 42 43 44 45

    /**
     * 初始化
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-12-24
     * @desc    description
     * @param   [array]           $params [输入参数]
     */
46
    private static function Init($params = [])
D
v1.2.0  
devil_gong 已提交
47 48
    {
        // 插件目录
49
        self::$payment_dir = ROOT.'extend'.DS.'payment'.DS;
D
v1.2.0  
devil_gong 已提交
50 51

        // 支付业务类型
52
        self::$payment_business_type_all = config('shopxo.payment_business_type_all');
D
v1.2.0  
devil_gong 已提交
53 54

        // 不删除的支付方式
55
        self::$cannot_deleted_list = ['DeliveryPayment', 'CashPayment'];
D
v1.2.0  
devil_gong 已提交
56 57

        // 入口文件位置
58
        self::$dir_root_path = defined('IS_ROOT_ACCESS') ? ROOT : ROOT.'public'.DS;
D
v1.2.0  
devil_gong 已提交
59 60 61 62 63 64 65 66 67 68
    }

    /**
     * 获取支付插件列表
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-17
     * @desc    description
     */
69
    public static function PlugPaymentList()
D
v1.2.0  
devil_gong 已提交
70 71
    {
        // 初始化
72
        self::Init();
D
v1.2.0  
devil_gong 已提交
73 74 75

        // 开始处理
        $data = [];
76
        if(is_dir(self::$payment_dir))
D
v1.2.0  
devil_gong 已提交
77
        {
78
            if($dh = opendir(self::$payment_dir))
D
v1.2.0  
devil_gong 已提交
79 80 81 82 83 84 85
            {
                while(($temp_file = readdir($dh)) !== false)
                {
                    if(substr($temp_file, 0, 1) != '.')
                    {
                        // 获取模块配置信息
                        $payment = htmlentities(str_replace('.php', '', $temp_file));
86
                        $config = self::GetPaymentConfig($payment);
D
v1.2.0  
devil_gong 已提交
87 88 89
                        if($config !== false)
                        {
                            // 数据组装
90
                            $temp = self::DataAnalysis($config);
D
v1.2.0  
devil_gong 已提交
91 92 93 94
                            $temp['id'] = date('YmdHis').GetNumberCode(8);
                            $temp['payment'] = $payment;

                            // 获取数据库配置信息
95
                            $db_config = self::PaymentList(['where'=>['payment'=>$payment]]);
D
v1.2.0  
devil_gong 已提交
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
                            if(!empty($db_config[0]))
                            {
                                $temp['is_install'] = 1;
                                $temp['id'] = $db_config[0]['id'];
                                $temp['name'] = $db_config[0]['name'];
                                $temp['logo'] = $db_config[0]['logo'];
                                $temp['apply_terminal'] = $db_config[0]['apply_terminal'];
                                $temp['config'] = $db_config[0]['config'];
                                $temp['is_enable'] = $db_config[0]['is_enable'];
                                $temp['is_open_user'] = $db_config[0]['is_open_user'];
                            }
                            $data[] = $temp;
                        }
                    }
                }
                closedir($dh);
            }
        }
        return $data;
    }

    /**
     * 获取支付模块配置信息
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-17
     * @desc    description
     * @param   [string]          $payment [模块名称]
     */
126
    private static function GetPaymentConfig($payment)
D
v1.2.0  
devil_gong 已提交
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
    {
        $payment = '\payment\\'.$payment;
        if(class_exists($payment))
        {
            $obj = new $payment();
            if(method_exists($obj, 'Config') && method_exists($obj, 'Pay') && method_exists($obj, 'Respond'))
            {
                return $obj->Config();
            }
        }
        return false;
    }

    /**
     * 数据解析
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-17
     * @desc    description
     * @param   [array]          $data [插件配置信息]
     */
149
    private static function DataAnalysis($data)
D
v1.2.0  
devil_gong 已提交
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
    {
        return [
            'name'          => isset($data['base']['name']) ? htmlentities($data['base']['name']) : $payment,
            'version'       => isset($data['base']['version']) ? htmlentities($data['base']['version']) : '',
            'apply_version' => isset($data['base']['apply_version']) ? htmlentities($data['base']['apply_version']) : '',
            'desc'          => isset($data['base']['desc']) ? $data['base']['desc'] : '',
            'author'        => isset($data['base']['author']) ? htmlentities($data['base']['author']) : '',
            'author_url'    => isset($data['base']['author_url']) ? htmlentities($data['base']['author_url']) : '',
            'element'       => isset($data['element']) ? $data['element'] : [],

            'logo'          => '',
            'is_enable'     => 0,
            'is_open_user'  => 0,
            'is_install'    => 0,
            'apply_terminal'=> empty($data['base']['apply_terminal']) ? array_column(lang('common_platform_type'), 'value') : $data['base']['apply_terminal'],
            'config'        => '',
        ];
    }

    /**
     * 支付方式列表
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-19
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
178
    public static function PaymentList($params = [])
D
v1.2.0  
devil_gong 已提交
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
    {
        $where = empty($params['where']) ? [] : $params['where'];
        if(isset($params['is_enable']))
        {
            $where['is_enable'] = intval($params['is_enable']);
        }
        if(isset($params['is_open_user']))
        {
            $where['is_open_user'] = intval($params['is_open_user']);
        }

        $data = Db::name('Payment')->where($where)->field('id,logo,name,sort,payment,config,apply_terminal,apply_terminal,element,is_enable,is_open_user')->order('sort asc')->select();
        if(!empty($data) && is_array($data))
        {
            foreach($data as &$v)
            {
                $v['logo_old'] = $v['logo'];
196
                $v['logo'] = ResourcesService::AttachmentPathViewHandle($v['logo']);
D
v1.2.0  
devil_gong 已提交
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
                $v['element'] = empty($v['element']) ? '' : json_decode($v['element'], true);
                $v['config'] = empty($v['config']) ? '' : json_decode($v['config'], true);
                $v['apply_terminal'] = empty($v['apply_terminal']) ? '' : json_decode($v['apply_terminal'], true);
            }
        }
        return $data;
    }

    /**
     * 获取支付方式列表
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-19
     * @desc    下订单根据终端自动筛选支付方式
     * @param   [array]          $params [输入参数]
     */
214
    public static function BuyPaymentList($params = [])
D
v1.2.0  
devil_gong 已提交
215
    {
216
        $data = self::PaymentList($params);
D
v1.2.0  
devil_gong 已提交
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241

        $result = [];
        if(!empty($data))
        {
            foreach($data as $v)
            {
                // 根据终端类型筛选
                if(in_array(APPLICATION_CLIENT_TYPE, $v['apply_terminal']))
                {
                    $result[] = $v;
                }
            }
        }
        return $result;
    }

    /**
     * 获取订单支付名称
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-19
     * @desc    description
     * @param   [int]          $order_id [订单id]
     */
242
    public static function OrderPaymentName($order_id = 0)
D
v1.2.0  
devil_gong 已提交
243 244 245 246 247 248 249 250 251 252 253 254 255
    {
        return empty($order_id) ? null : Db::name('PayLog')->where(['order_id'=>intval($order_id)])->value('payment_name');
    }

    /**
     * 数据更新
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-12-19
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
256
    public static function PaymentUpdate($params = [])
D
v1.2.0  
devil_gong 已提交
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
    {
        // 请求类型
        $p = [
            [
                'checked_type'      => 'empty',
                'key_name'          => 'id',
                'error_msg'         => '操作id有误',
            ],
            [
                'checked_type'      => 'length',
                'key_name'          => 'name',
                'checked_data'      => '2,60',
                'error_msg'         => '名称长度 2~60 个字符',
            ],
            [
                'checked_type'      => 'empty',
                'key_name'          => 'apply_terminal',
                'error_msg'         => '至少选择一个适用终端',
            ],
            [
                'checked_type'      => 'length',
                'key_name'          => 'sort',
                'checked_data'      => '3',
                'error_msg'         => '顺序 0~255 之间的数值',
            ],
        ];
        $ret = ParamsChecked($params, $p);
        if($ret !== true)
        {
            return DataReturn($ret, -1);
        }

        // 附件
        $data_fields = ['logo'];
        $attachment = ResourcesService::AttachmentParams($params, $data_fields);

        // 数据
        $data = [
            'name'              => $params['name'],
            'apply_terminal'    => empty($params['apply_terminal']) ? '' : json_encode(explode(',', $params['apply_terminal'])),
            'logo'              => $attachment['data']['logo'],
298
            'config'            => json_encode(self::GetPlugConfig($params)),
D
v1.2.0  
devil_gong 已提交
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
            'sort'              => intval($params['sort']),
            'is_enable'         => isset($params['is_enable']) ? intval($params['is_enable']) : 0,
            'is_open_user'      => isset($params['is_open_user']) ? intval($params['is_open_user']) : 0,
        ];

        $data['upd_time'] = time();
        if(Db::name('Payment')->where(['id'=>intval($params['id'])])->update($data))
        {
            return DataReturn('编辑成功', 0);
        }
        return DataReturn('编辑失败', -100); 
    }

    /**
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-18
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
320
    private static function GetPlugConfig($params = [])
D
v1.2.0  
devil_gong 已提交
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
    {
        $data = [];
        foreach($params as $k=>$v)
        {
            if(substr($k, 0, 8) == 'plugins_')
            {
                $data[substr($k, 8)] = $v;
            }
        }
        return $data;
    }

    /**
     * 状态更新
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2016-12-06T21:31:53+0800
     * @param    [array]          $params [输入参数]
     */
341
    public static function PaymentStatusUpdate($params = [])
D
v1.2.0  
devil_gong 已提交
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
    {
        // 请求参数
        $p = [
            [
                'checked_type'      => 'empty',
                'key_name'          => 'id',
                'error_msg'         => '操作id有误',
            ],
            [
                'checked_type'      => 'empty',
                'key_name'          => 'field',
                'error_msg'         => '未指定操作字段',
            ],
            [
                'checked_type'      => 'in',
                'key_name'          => 'state',
                'checked_data'      => [0,1],
                'error_msg'         => '状态有误',
            ],
        ];
        $ret = ParamsChecked($params, $p);
        if($ret !== true)
        {
            return DataReturn($ret, -1);
        }

        // 数据更新
        if(Db::name('Payment')->where(['payment'=>$params['id']])->update([$params['field']=>intval($params['state']), 'upd_time'=>time()]))
        {
            return DataReturn('操作成功');
        }
        return DataReturn('操作失败', -100);
    }

    /**
     * 权限校验
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2018-09-29T00:01:49+0800
     */
383
    private static function PowerCheck()
D
v1.2.0  
devil_gong 已提交
384 385
    {
        // 入口文件目录
386
        if(!is_writable(self::$dir_root_path))
D
v1.2.0  
devil_gong 已提交
387
        {
388
            return DataReturn('目录没有操作权限'.'['.self::$dir_root_path.']', -3);
D
v1.2.0  
devil_gong 已提交
389 390 391
        }

        // 插件权限
392
        if(!is_writable(self::$payment_dir))
D
v1.2.0  
devil_gong 已提交
393
        {
394
            return DataReturn('目录没有操作权限'.'['.self::$payment_dir.']', -3);
D
v1.2.0  
devil_gong 已提交
395 396 397 398 399 400 401 402 403 404 405 406
        }
    }

    /**
     * 上传插件
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-17
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
407
    public static function Upload($params = [])
D
v1.2.0  
devil_gong 已提交
408 409
    {
        // 初始化
410
        self::Init();
D
v1.2.0  
devil_gong 已提交
411 412

        // 权限
413
        $ret = self::PowerCheck();
D
v1.2.0  
devil_gong 已提交
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
        if($ret['code'] != 0)
        {
            return $ret;
        }

        // 文件上传校验
        $error = FileUploadError('file');
        if($error !== true)
        {
            return DataReturn($error, -1);
        }

        // 文件格式化校验
        $type = array('text/php');
        if(!in_array($_FILES['file']['type'], $type))
        {
            return DataReturn('文件格式有误,必须php文件', -2);
        }

        // 是否已有存在插件
434
        if(file_exists(self::$payment_dir.$_FILES['file']['name']))
D
v1.2.0  
devil_gong 已提交
435 436 437 438
        {
            return DataReturn('已存在相同插件', -3);
        }

G
gongfuxiang 已提交
439 440 441 442
        // 文件名称过滤
        $name = substr($_FILES['file']['name'], 0, strlen($_FILES['file']['name'])-4);
        $payment = str_replace(array('.', '/', '\\', ':'), '', $name);

D
v1.2.0  
devil_gong 已提交
443
        // 存储文件
444
        $file = self::$payment_dir.$payment.'.php';
G
gongfuxiang 已提交
445
        if(!move_uploaded_file($_FILES['file']['tmp_name'], $file))
D
v1.2.0  
devil_gong 已提交
446 447 448 449 450
        {
            return DataReturn('上传失败', -100);
        }

        // 文件校验
451
        $config = self::GetPaymentConfig($payment);
D
v1.2.0  
devil_gong 已提交
452 453
        if($config === false)
        {
G
gongfuxiang 已提交
454
            @unlink($file);
D
v1.2.0  
devil_gong 已提交
455 456 457 458 459 460 461 462 463 464 465 466 467 468
            return DataReturn('插件编写有误,请参考文档编写', -10);
        }
        return DataReturn('上传成功');
    }

    /**
     * 安装
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-17
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
469
    public static function Install($params = [])
D
v1.2.0  
devil_gong 已提交
470 471
    {
        // 初始化
472
        self::Init();
D
v1.2.0  
devil_gong 已提交
473 474 475 476 477 478 479 480 481

        // 参数
        if(empty($params['id']))
        {
            return DataReturn('参数错误', -1);
        }

        // 数据处理
        $payment = $params['id'];
482
        $config = self::GetPaymentConfig($payment);
D
v1.2.0  
devil_gong 已提交
483 484
        if($config !== false)
        {
485
            $data = self::DataAnalysis($config);
D
v1.2.0  
devil_gong 已提交
486 487 488 489 490 491 492 493 494 495 496 497 498 499
            $data['payment'] = $payment;
            $data['element'] = empty($data['element']) ? '' : json_encode($data['element']);
            $data['apply_terminal'] = empty($data['apply_terminal']) ? '' : json_encode($data['apply_terminal']);
            $data['sort'] = 0;
            $data['add_time'] = time();

            // 移除多余的字段
            unset($data['is_install']);

            // 开启事务
            Db::startTrans();
            if(Db::name('Payment')->insertGetId($data) > 0)
            {
                // 入口文件生成
500
                $ret = self::PaymentEntranceCreated($payment);
D
v1.2.0  
devil_gong 已提交
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
                if($ret['code'] == 'code')
                {
                    // 提交事务
                    Db::commit();

                   return DataReturn('安装成功'); 
                } else {
                    // 事务回滚
                    Db::rollback();
                    return $ret;
                }
            } else {
                // 事务回滚
                Db::rollback();
                return DataReturn('安装失败', -100);
            }
        } else {
            return DataReturn('插件配置有误', -10);
        }
    }

    /**
     * 删除插件
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-17
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
531
    public static function Delete($params = [])
D
v1.2.0  
devil_gong 已提交
532 533
    {
        // 初始化
534
        self::Init();
D
v1.2.0  
devil_gong 已提交
535 536

        // 权限
537
        $ret = self::PowerCheck();
D
v1.2.0  
devil_gong 已提交
538 539 540 541 542 543 544 545 546 547 548 549 550
        if($ret['code'] != 0)
        {
            return $ret;
        }

        // 参数
        if(empty($params['id']))
        {
            return DataReturn('参数错误', -1);
        }

        // 是否禁止删除
        $payment = $params['id'];
551
        if(in_array($payment, self::$cannot_deleted_list))
D
v1.2.0  
devil_gong 已提交
552 553 554 555 556
        {
            return DataReturn('该支付方式禁止删除', -10);
        }

        // 是否存在
557
        $file = self::$payment_dir.$payment.'.php';
D
v1.2.0  
devil_gong 已提交
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
        if(!file_exists($file))
        {
            return DataReturn('资源不存在或已被删除', -2);
        }

        // 权限
        if(!is_writable($file))
        {
            return DataReturn('没操作权限', -3);
        }

        // 删除
        if(!@unlink($file))
        {
            return DataReturn('删除失败', -100);
        }

        // 删除入口文件
576
        self::PaymentEntranceDelete($payment);
D
v1.2.0  
devil_gong 已提交
577 578 579 580 581 582 583 584 585 586 587 588 589

        return DataReturn('删除成功');
    }

    /**
     * 卸载
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-17
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
590
    public static function Uninstall($params = [])
D
v1.2.0  
devil_gong 已提交
591 592 593 594 595 596 597 598
    {
        // 参数
        if(empty($params['id']))
        {
            return DataReturn('参数错误', -1);
        }

        // 初始化
599
        self::Init();
D
v1.2.0  
devil_gong 已提交
600 601 602 603 604 605

        // 开始卸载
        $payment = $params['id'];
        if(db('Payment')->where(['payment'=>$payment])->delete())
        {
            // 删除入口文件
606
            self::PaymentEntranceDelete($payment);
D
v1.2.0  
devil_gong 已提交
607 608 609 610 611 612 613 614 615 616 617 618 619 620

            return DataReturn('卸载成功', 0);
        }
        return DataReturn('卸载失败', -100);
    }

    /**
     * [PaymentEntranceCreated 入口文件创建]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2018-09-28T23:38:52+0800
     * @param    [string]        $payment [支付唯一标记]
     */
621
    private static function PaymentEntranceCreated($payment)
D
v1.2.0  
devil_gong 已提交
622 623
    {
        // 权限
624
        $ret = self::PowerCheck();
D
v1.2.0  
devil_gong 已提交
625 626 627 628 629 630
        if($ret['code'] != 0)
        {
            return $ret;
        }

        // 批量创建
631
        foreach(self::$payment_business_type_all as $v)
D
v1.2.0  
devil_gong 已提交
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
        {
            $name = strtolower($v['name']);

            if(defined('IS_ROOT_ACCESS'))
            {
// 异步
$notify=<<<php
<?php

/**
 * {$v['desc']}支付异步入口
 */

// 默认绑定模块
\$_GET['s'] = '/api/{$name}notify/notify';

// 支付模块标记
define('PAYMENT_TYPE', '{$payment}');

// 根目录入口
define('IS_ROOT_ACCESS', true);

// 引入公共入口文件
require './public/index.php';
?>
php;

// 同步
$respond=<<<php
<?php

/**
 * {$v['desc']}支付同步入口
 */

// 默认绑定模块
\$_GET['s'] = '/index/{$name}/respond';

// 支付模块标记
define('PAYMENT_TYPE', '{$payment}');

// 根目录入口
define('IS_ROOT_ACCESS', true);

// 引入公共入口文件
require './public/index.php';
?>
php;

            } else {

// 异步
$notify=<<<php
<?php

/**
 * {$v['desc']}支付异步入口
 */

// 默认绑定模块
\$_GET['s'] = '/api/{$name}notify/notify';

// 支付模块标记
define('PAYMENT_TYPE', '{$payment}');

// 引入入口文件
require __DIR__.'/index.php';
?>
php;

// 同步
$respond=<<<php
<?php

/**
 * {$v['desc']}支付同步入口
 */

// 默认绑定模块
\$_GET['s'] = '/index/{$name}/respond';

// 支付模块标记
define('PAYMENT_TYPE', '{$payment}');

// 引入入口文件
require __DIR__.'/index.php';
?>
php;
            }

722
            @file_put_contents(self::$dir_root_path.'payment_'.$name.'_'.strtolower($payment).'_respond.php', $respond);
D
v1.2.0  
devil_gong 已提交
723 724

            // 线下支付不生成异步入口文件
D
devil_gong 已提交
725
            if(!in_array($payment, config('shopxo.under_line_list')))
D
v1.2.0  
devil_gong 已提交
726
            {
727
                @file_put_contents(self::$dir_root_path.'payment_'.$name.'_'.strtolower($payment).'_notify.php', $notify);
D
v1.2.0  
devil_gong 已提交
728 729 730 731 732 733 734 735 736 737 738 739 740 741
            }
        }

        return DataReturn('操作成功', 0);
    }

    /**
     * [PaymentEntranceDelete 入口文件删除]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2018-09-28T23:38:52+0800
     * @param    [string]        $payment [支付唯一标记]
     */
742
    private static function PaymentEntranceDelete($payment)
D
v1.2.0  
devil_gong 已提交
743 744
    {
        // 权限
745
        $ret = self::PowerCheck();
D
v1.2.0  
devil_gong 已提交
746 747 748 749 750 751
        if($ret['code'] != 0)
        {
            return $ret;
        }

        $payment = strtolower($payment);
752
        foreach(self::$payment_business_type_all as $v)
D
v1.2.0  
devil_gong 已提交
753 754
        {
            $name = strtolower($v['name']);
755
            if(file_exists(self::$dir_root_path.'payment_'.$name.'_'.$payment.'_notify.php'))
D
v1.2.0  
devil_gong 已提交
756
            {
757
                @unlink(self::$dir_root_path.'payment_'.$name.'_'.$payment.'_notify.php');
D
v1.2.0  
devil_gong 已提交
758
            }
759
            if(file_exists(self::$dir_root_path.'payment_'.$name.'_'.$payment.'_respond.php'))
D
v1.2.0  
devil_gong 已提交
760
            {
761
                @unlink(self::$dir_root_path.'payment_'.$name.'_'.$payment.'_respond.php');
D
v1.2.0  
devil_gong 已提交
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
            }
        }

        return DataReturn('操作成功', 0);
    }

    /**
     * 入库文件检查
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-12-26
     * @desc    description
     * @param   [string]          $payment [支付标记]
     * @param   [string]          $name    [支付业务方式名称]
     */
778
    public static function EntranceFileChecked($payment, $name)
D
v1.2.0  
devil_gong 已提交
779 780
    {
        // 同步返回文件
781
        if(!file_exists(self::$dir_root_path.'payment_'.strtolower($name).'_'.strtolower($payment).'_respond.php'))
D
v1.2.0  
devil_gong 已提交
782 783 784 785 786
        {
            return DataReturn('支付返回入口文件不存在,请联系管理员处理', -10);
        }

        // 线下支付不生成异步入口文件
D
devil_gong 已提交
787
        if(!in_array($payment, config('shopxo.under_line_list')))
D
v1.2.0  
devil_gong 已提交
788
        {
789
            if(!file_exists(self::$dir_root_path.'payment_'.strtolower($name).'_'.strtolower($payment).'_notify.php'))
D
v1.2.0  
devil_gong 已提交
790 791 792 793 794 795 796 797
            {
                return DataReturn('支付通知入口文件不存在,请联系管理员处理', -10);
            }
        }
        return DataReturn('校验成功', 0);
    }
}
?>