<?php

namespace BYDAuto\Foundation;

use Alipay\EasySDK\Kernel\Config;
use Alipay\EasySDK\Kernel\Factory;

class AlipayEasySDKFactory
{
    public function __construct()
    {
        Factory::setOptions($this->getOptions());
    }

    public function execute($method, $textParams, $bizParams)
    {
        return Factory::util()->generic()->execute($method, $textParams, $bizParams);
    }

    protected function getOptions()
    {
        $options = new Config();
        $options->protocol = 'https';
        $options->gatewayHost = 'openapi.alipay.com';
        $options->signType = 'RSA2';
        $options->appId = config('bydauto.alipay.app_id');
        $merchantPrivateKey = file_get_contents(storage_path(config('bydauto.alipay.merchant_private_key')));
        $options->merchantPrivateKey = $merchantPrivateKey;
        $alipayPublicKey = file_get_contents(storage_path(config('bydauto.alipay.alipay_public_key')));
        $options->alipayPublicKey = $alipayPublicKey;
        return $options;
    }
}
