HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/crm.jmfdbn.com/application/pay/controller/Api.php
<?php
// +----------------------------------------------------------------------
// | Yzncms [ 御宅男工作室 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://yzncms.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 御宅男 <530765310@qq.com>
// +----------------------------------------------------------------------

// +----------------------------------------------------------------------
// | 支付API接口控制器
// +----------------------------------------------------------------------
namespace app\pay\controller;

use app\common\controller\Homebase;
use app\pay\library\Service;
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\QrCode;
use think\facade\Session;
use think\Response;
use Yansongda\Pay\Pay;

class Api extends HomeBase
{
    /**
     * 微信支付
     * @return string
     */
    public function wechat()
    {
        $config    = Service::getConfig('wechat');
        $isWechat  = stripos($this->request->server('HTTP_USER_AGENT'), 'MicroMessenger') !== false;
        $orderData = Session::get("wechatorderdata");
        if ($isWechat) {
            $type = 'jsapi';
            $this->assign("orderData", $orderData);
        } else {
            //发起PC支付(Native支付)
            $data = [
                'body'         => $orderData['body'],
                'code_url'     => $orderData['code_url'],
                'out_trade_no' => $orderData['out_trade_no'],
                'return_url'   => $orderData['return_url'],
                'total_fee'    => $orderData['total_fee'],
            ];
            //检测订单状态
            if ($this->request->isPost()) {
                $pay    = Pay::wechat($config);
                $result = $pay->find($orderData['out_trade_no']);
                if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
                    $this->success('', url('pay/index/pay_list'), ['trade_state' => $result['trade_state']]);
                } else {
                    $this->error("查询失败");
                }
            }
            $type = 'pc';
            $this->assign("data", $data);
        }
        $this->assign("type", $type);
        return $this->fetch('/wechat');
    }

    /**
     * 支付宝支付
     * @return string
     */
    public function alipay()
    {
        $config    = Service::getConfig('alipay');
        $orderData = Session::get("alipayorderdata");
        $data      = [
            'body'         => $orderData['body'],
            'qr_code'      => $orderData['qr_code'],
            'out_trade_no' => $orderData['out_trade_no'],
            'return_url'   => $orderData['return_url'],
            'total_fee'    => $orderData['total_fee'],
        ];
        //检测订单状态
        if ($this->request->isPost()) {
            $pay    = Pay::alipay($config);
            $result = $pay->find($orderData['out_trade_no']);
            if (in_array($result['trade_status'], ['TRADE_SUCCESS', 'TRADE_FINISHED'])) {
                $this->success('', url('pay/index/pay_list'), ['trade_status' => $result['trade_status']]);
            } else {
                $this->error("查询失败");
            }
        }
        $this->assign("data", $data);
        return $this->fetch('/alipay');
    }

    /**
     * 生成二维码
     * @return Response
     */
    public function qrcode()
    {
        $text   = $this->request->get('text', 'hello world');
        $qrCode = new QrCode($text);
        $rs     = $qrCode
            ->setWriterByName('png')
            ->setMargin(10)
            ->setEncoding('UTF-8')
            ->setSize(250)
            /*->setLogoPath(__DIR__ . '/../assets/symfony.png')
        ->setLogoWidth(150)*/
            ->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH) //纠错级别
            ->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0])
            ->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255])
            ->setValidateResult(false);
        return new Response($qrCode->writeString(), 200, ['Content-Type' => $qrCode->getContentType()]);
    }

}