<commit_before><?php
/**
 * @author: helei
 * @createTime: 2016-07-20 16:21
 * @description: 支付宝回调通知
 *
 * @link      https://github.com/helei112g/payment/tree/paymentv2
 * @link      https://helei112g.github.io/
 */

namespace Payment\Notify;

use Payment\Common\AliConfig;
use Payment\Common\PayException;
use Payment\Config;
use Payment\Utils\ArrayUtil;
use Payment\Utils\Rsa2Encrypt;
use Payment\Utils\RsaEncrypt;

class AliNotify extends NotifyStrategy
{
    /**
     * AliNotify constructor.
     * @param array $config
     * @throws PayException
     */
    public function __construct(array $config)
    {
        parent::__construct($config);

        try {
            $this->config = new AliConfig($config);
        } catch (PayException $e) {
            throw $e;
        }
    }

    protected function getOldAliPublicKey()
    {
        $filePath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR .'CacertFile/old_alipay_public_key.pem';

        return @file_get_contents($filePath);
    }

    /**
     * 获取移除通知的数据  并进行简单处理（如：格式化为数组）
     *
     * 如果获取数据失败，返回false
     *
     * @return array|boolean
     * @author helei
     */
    public function getNotifyData()
    {
        $data = empty($_POST) ? $_GET : $_POST;
        if (empty($data) || ! is_array($data)) {
            return false;
        }

        return $data;
    }

    /**
     * 检查异步通知的数据是否合法
     *
     * 如果检查失败，返回false
     *
     * @param array $data  由 $this->getNotifyData() 返回的数据
     * @return boolean
     * @author helei
     */
    public function checkNotifyData(array $data)
    {
        $status = $this->getTradeStatus($data['trade_status']);
        if ($status !== Config::TRADE_STATUS_SUCC) {
            // 如果不是交易成功状态，直接返回错误，
            return false;
        }

        // 主要是为了即时到账的签名
        if (! isset($data['version'])) {
            $this->config->rsaAliPubKey = $this->getOldAliPublicKey();
        }

        // 检查签名
        $flag = $this->verifySign($data);

        return $flag;
    }

    /**
     * 向客户端返回必要的数据
     * @param array $data 回调机构返回的回调通知数据
     * @return array|false
     * @author helei
     */
    protected function getRetData(array $data)
    {
        if ($this->config->returnRaw) {
            $data['channel'] = Config::ALI_CHARGE;
            return $data;
        }

        $retData = [
            'amount'   => $data['total_amount'],
            'buyer_id'   => $data['buyer_id'],
            'transaction_id'   => $data['trade_no'],
            'body'   => $data['body'],
            'notify_time'   => $data['notify_time'],
            'subject'   => $data['subject'],
            'buyer_account' => isset($data['buyer_logon_id']) ? $data['buyer_logon_id'] : '',
            'auth_app_id' => $data['auth_app_id'],
            'notify_type' => $data['notify_type'],
            'invoice_amount' => $data['invoice_amount'],
            'order_no'   => $data['out_trade_no'],
            'trade_state'   => $this->getTradeStatus($data['trade_status']),
            'pay_time'   => $data['gmt_payment'],// 交易付款时间
            'point_amount' => $data['point_amount'],// 使用集分宝支付的金额
            'trade_create_time' => $data['gmt_create'],// 交易创建时间
            'pay_amount' => $data['buyer_pay_amount'],// 用户在交易中支付的金额
            'receipt_amount' => $data['receipt_amount'],// 商家在交易中实际收到的款项，单位为元
            'fund_bill_list' => $data['fund_bill_list'],// 支付成功的各个渠道金额信息
            'app_id' => $data['app_id'],
            'seller_id' => $data['seller_id'],
            'seller_email' => $data['seller_email'],
            'channel'   => Config::ALI_CHARGE,
        ];

        // 检查是否存在用户自定义参数
        if (isset($data['passback_params']) && ! empty($data['passback_params'])) {
            $retData['return_param'] = $data['passback_params'];
        }

        return $retData;
    }

    /**
     * 支付宝，成功返回 ‘success’   失败，返回 ‘fail’
     * @param boolean $flag 每次返回的bool值
     * @param string $msg 错误原因  后期考虑记录日志
     * @return string
     * @author helei
     */
    protected function replyNotify($flag, $msg = '')
    {
        if ($flag) {
            return 'success';
        } else {
            return 'fail';
        }<commit_msg>seller_email not exist.<commit_after><?php
/**
 * @author: helei
 * @createTime: 2016-07-20 16:21
 * @description: 支付宝回调通知
 *
 * @link      https://github.com/helei112g/payment/tree/paymentv2
 * @link      https://helei112g.github.io/
 */

namespace Payment\Notify;

use Payment\Common\AliConfig;
use Payment\Common\PayException;
use Payment\Config;
use Payment\Utils\ArrayUtil;
use Payment\Utils\Rsa2Encrypt;
use Payment\Utils\RsaEncrypt;

class AliNotify extends NotifyStrategy
{
    /**
     * AliNotify constructor.
     * @param array $config
     * @throws PayException
     */
    public function __construct(array $config)
    {
        parent::__construct($config);

        try {
            $this->config = new AliConfig($config);
        } catch (PayException $e) {
            throw $e;
        }
    }

    protected function getOldAliPublicKey()
    {
        $filePath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR .'CacertFile/old_alipay_public_key.pem';

        return @file_get_contents($filePath);
    }

    /**
     * 获取移除通知的数据  并进行简单处理（如：格式化为数组）
     *
     * 如果获取数据失败，返回false
     *
     * @return array|boolean
     * @author helei
     */
    public function getNotifyData()
    {
        $data = empty($_POST) ? $_GET : $_POST;
        if (empty($data) || ! is_array($data)) {
            return false;
        }

        return $data;
    }

    /**
     * 检查异步通知的数据是否合法
     *
     * 如果检查失败，返回false
     *
     * @param array $data  由 $this->getNotifyData() 返回的数据
     * @return boolean
     * @author helei
     */
    public function checkNotifyData(array $data)
    {
        $status = $this->getTradeStatus($data['trade_status']);
        if ($status !== Config::TRADE_STATUS_SUCC) {
            // 如果不是交易成功状态，直接返回错误，
            return false;
        }

        // 主要是为了即时到账的签名
        if (! isset($data['version'])) {
            $this->config->rsaAliPubKey = $this->getOldAliPublicKey();
        }

        // 检查签名
        $flag = $this->verifySign($data);

        return $flag;
    }

    /**
     * 向客户端返回必要的数据
     * @param array $data 回调机构返回的回调通知数据
     * @return array|false
     * @author helei
     */
    protected function getRetData(array $data)
    {
        if ($this->config->returnRaw) {
            $data['channel'] = Config::ALI_CHARGE;
            return $data;
        }

        $retData = [
            'amount'   => $data['total_amount'],
            'buyer_id'   => $data['buyer_id'],
            'transaction_id'   => $data['trade_no'],
            'body'   => $data['body'],
            'notify_time'   => $data['notify_time'],
            'subject'   => $data['subject'],
            'buyer_account' => isset($data['buyer_logon_id']) ? $data['buyer_logon_id'] : '',
            'auth_app_id' => $data['auth_app_id'],
            'notify_type' => $data['notify_type'],
            'invoice_amount' => $data['invoice_amount'],
            'order_no'   => $data['out_trade_no'],
            'trade_state'   => $this->getTradeStatus($data['trade_status']),
            'pay_time'   => $data['gmt_payment'],// 交易付款时间
            'point_amount' => $data['point_amount'],// 使用集分宝支付的金额
            'trade_create_time' => $data['gmt_create'],// 交易创建时间
            'pay_amount' => $data['buyer_pay_amount'],// 用户在交易中支付的金额
            'receipt_amount' => $data['receipt_amount'],// 商家在交易中实际收到的款项，单位为元
            'fund_bill_list' => $data['fund_bill_list'],// 支付成功的各个渠道金额信息
            'app_id' => $data['app_id'],
            'seller_id' => $data['seller_id'],
            'seller_email' => isset($data['seller_email']) ? $data['seller_email'] : '',
            'channel'   => Config::ALI_CHARGE,
        ];

        // 检查是否存在用户自定义参数
        if (isset($data['passback_params']) && ! empty($data['passback_params'])) {
            $retData['return_param'] = $data['passback_params'];
        }

        return $retData;
    }

    /**
     * 支付宝，成功返回 ‘success’   失败，返回 ‘fail’
     * @param boolean $flag 每次返回的bool值
     * @param string $msg 错误原因  后期考虑记录日志
     * @return string
     * @author helei
     */
    protected function replyNotify($flag, $msg = '')
    {
        if ($flag) {
            return 'success';
        } else {
            return 'fail';
        }
{'fraction_non_alphanumeric': 0.1527117031398668, 'fraction_numerical': 0.004757373929590866, 'mean_word_length': 2.1029520295202953, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1970262', 'n_tokens_mistral': 3066, 'n_tokens_neox': 3099, 'n_words': 447}