You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace ali\alipay;
use Alipay\EasySDK\Kernel\Config;
class Base
{
protected $config; //支付宝配置
/**
* 构造函数
* @date 2021-01-19
*/
public function __construct(array $data = [])
{
$this->config = $data;
}
/**
* 设置参数
* @param string $notify_url 支付宝服务器主动通知商户服务器里指定的页面http/https路径。
* @date 2021-10-25
*/
public function getOptions($notify_url = '')
{
$options = new Config();
$options->protocol = 'https';
$options->gatewayHost = 'openapi.alipay.com';
$options->signType = 'RSA2';
$options->appId = $this->config['app_id'];
// 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
$options->merchantPrivateKey = $this->config['app_private_key'];
if ($this->config['sign_type'] == 2) { //公钥证书
$options->alipayCertPath = $this->config['alipay_cert_path'];
$options->alipayRootCertPath = $this->config['alipay_root_cert_path'];
$options->merchantCertPath = $this->config['merchant_cert_path'];
} else if ($this->config['sign_type'] == 1) { //普通公钥
//注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
$options->alipayPublicKey = $this->config['ali_pay_public_key'];
}
//可设置异步通知接收服务地址(可选)
if (!empty($notify_url)) {
$options->notifyUrl = $notify_url;
}
//可设置AES密钥调用AES加解密相关接口时需要可选
if($this->config['encrypt_key']){
$options->encryptKey = $this->config['encrypt_key'];
}
return $options;
}
}