HEX
Server: nginx/1.22.1
System: Linux VM-4-16-centos 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64
User: www (1001)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: /www/wwwroot/wen.haoynn.cn/wp-content/themes/ripro/shop/alipay/notify2.php
<?php
/**
 * RiPro是一个优秀的主题,首页拖拽布局,高级筛选,自带会员生态系统,超全支付接口,你喜欢的样子我都有!
 * 正版唯一购买地址,全自动授权下载使用:http://www.a8ku.cn/
 * 作者唯一QQ:570830288 (Mr.Hcx)
 * 承蒙您对本主题的喜爱,我们愿向小三一样,做大哥的女人,做大哥网站中最想日的一个。
 * 能理解使用盗版的人,但是不能接受传播盗版,本身主题没几个钱,主题自有支付体系和会员体系,盗版风险太高,鬼知道那些人乱动什么代码,无利不起早。
 * 开发者不易,感谢支持,更好的更用心的等你来调教
 */


/**
 * 支付宝异步通知 openapp
 */

header('Content-type:text/html; Charset=utf-8');
date_default_timezone_set('Asia/Shanghai');
ob_start();
require_once dirname(__FILE__) . "../../../../../../wp-load.php";
ob_end_clean();

if (empty($_POST)) {
    echo '非法请求';exit();
}

// 获取后台支付宝配置
$aliPayConfig = _cao('alipay');

$aliPay = new AlipayServiceCheck($aliPayConfig['publicKey']);
//验证签名
$_verify = $aliPay->rsaCheck($_POST, $_POST['sign_type']);
if ($_verify === true) {
    // 通知验证成功,可以通过POST参数来获取支付宝回传的参数
    $this_verify = true;
} else {
    $this_verify = false;
 	echo 'success';exit();
}

// $content = var_export($_POST, true) . PHP_EOL . 'verify:' . var_export($_verify, true);
// file_put_contents(__DIR__ . '/notify_result.txt', $content);


//商户本地订单号
$out_trade_no = $_POST['out_trade_no'];
//支付宝交易号
$trade_no = $_POST['trade_no'];


// 处理本地业务逻辑
if ($this_verify && $_POST['trade_status'] == 'TRADE_SUCCESS') {
   //发送支付成功回调用
    $RiProPay = new RiProPay;
    $RiProPay->send_order_trade_success($out_trade_no,$trade_no,'ripropaysucc');
    echo 'success';exit();
} else {
    // 输出错误日志 可以在生产环境关闭 注释即可
    echo "error";exit();
}
exit();


// 调用其他类 AlipayServiceCheck
class AlipayServiceCheck
{
    //支付宝公钥
    protected $alipayPublicKey;
    protected $charset;

    public function __construct($alipayPublicKey)
    {
        $this->charset         = 'utf8';
        $this->alipayPublicKey = $alipayPublicKey;
    }

    public function rsaCheck($params)
    {
        $sign     = $params['sign'];
        $signType = $params['sign_type'];
        unset($params['sign_type']);
        unset($params['sign']);
        return $this->verify($this->getSignContent($params), $sign, $signType);
    }

    public function verify($data, $sign, $signType = 'RSA')
    {
        $pubKey = $this->alipayPublicKey;
        $res    = "-----BEGIN PUBLIC KEY-----\n" .
        wordwrap($pubKey, 64, "\n", true) .
            "\n-----END PUBLIC KEY-----";
        ($res) or die('支付宝RSA公钥错误。请检查公钥文件格式是否正确');

        //调用openssl内置方法验签,返回bool值
        if ("RSA2" == $signType) {
            $result = (bool) openssl_verify($data, base64_decode($sign), $res, version_compare(PHP_VERSION, '5.4.0', '<') ? SHA256 : OPENSSL_ALGO_SHA256);
        } else {
            $result = (bool) openssl_verify($data, base64_decode($sign), $res);
        }
        return $result;
    }

    protected function checkEmpty($value)
    {
        if (!isset($value)) {
            return true;
        }

        if ($value === null) {
            return true;
        }

        if (trim($value) === "") {
            return true;
        }

        return false;
    }

    public function getSignContent($params)
    {
        ksort($params);
        $stringToBeSigned = "";
        $i                = 0;
        foreach ($params as $k => $v) {

            if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) {

                // 修复转义导致签名失败
                $v = stripslashes($v);

                // 转换成目标字符集
                $v = $this->characet($v, $this->charset);

                if ($i == 0) {
                    $stringToBeSigned .= "$k" . "=" . "$v";
                } else {

                    $stringToBeSigned .= "&" . "$k" . "=" . "$v";
                }

                $i++;

            }
        }

        unset($k, $v);
        return $stringToBeSigned;
    }
    public function characet($data, $targetCharset)
    {
        if (!empty($data)) {
            $fileType = $this->charset;
            if (strcasecmp($fileType, $targetCharset) != 0) {
                $data = mb_convert_encoding($data, $targetCharset, $fileType);
                //$data = iconv($fileType, $targetCharset.'//IGNORE', $data);
            }
        }
        return $data;
    }
}