data = $data; $this->config = \Yii::$app->services->setting->mall->get($data['mall_id'], 'alipay_mini'); $this->alipayFactory = AlipayFactory::setOptions($this->getOptions()); } /** * @return Config */ private function getOptions(): Config { $options = new Config(); $options->protocol = 'https'; $options->gatewayHost = 'openapi.alipay.com'; // $options->gatewayHost = 'openapi.alipaydev.com'; // 测试环境 $options->signType = 'RSA2'; $options->appId = $this->config['app_id']; // 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中 $options->merchantPrivateKey = $this->config['merchantPrivateKey']; //$options->alipayCertPath = dirname(Yii::$app->basePath).'/'.$this->config['alipayCertPath']; //$options->alipayRootCertPath = dirname(Yii::$app->basePath).'/'.$this->config['alipayCertPath']; //$options->merchantCertPath = dirname(Yii::$app->basePath).'/'.$this->config['merchantCertPath']; //注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可 $options->alipayPublicKey = file_get_contents(dirname(Yii::$app->basePath).'/'.$this->config['alipayCertPath']); //可设置异步通知接收服务地址(可选) $options->notifyUrl = ''; //可设置AES密钥,调用AES加解密相关接口时需要(可选) $options->encryptKey = $this->config['encryptKey']; return $options; } }