Auth::class, 'except' => ['login'], ], // 暂时去掉后台操作日志 // [ // 'class' => ActionLog::class, // ] ], parent::behaviors()); } /** * 初始化操作 */ // public function beforeAction($action) // { // $this->initWX(); // $this->initWXPay(); // parent::beforeAction($action); // } // public function initWX() // { // // TODO: 小程序为例 // // 获取微信配置进行初始化 // $this->wechat_config = WechatConfig::findOne(['store_id' => get_store_id(), 'type' => 1]); // \Yii::error('store_id => ' . \get_store_id()); // if ($this->wechat_config) { // $config = [ // 'app_id' => $this->wechat_config->app_id, // 'secret' => $this->wechat_config->app_secret, // 'response_type' => 'array' // ]; // $this->wechat = Factory::miniProgram($config); // } // } /** * Undocumented function * * @Author LGL 24963@qq.com * @DateTime 2021-02-03 * @desc: 实例化支付类 * @return void */ // protected function initWXPay () // { // if (!$this->wechat_config) { // return false; // } // // 证书 // if (!is_dir(\Yii::$app->runtimePath . '/pem')) { // mkdir(\Yii::$app->runtimePath . '/pem'); // file_put_contents(\Yii::$app->runtimePath . '/pem/index.html', ''); // } // $cert_pem_file = null; // if ($this->wechat_config->cert_pem) { // $cert_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($this->wechat_config->cert_pem); // if (!file_exists($cert_pem_file)) { // file_put_contents($cert_pem_file, $this->wechat_config->cert_pem); // } // } // $key_pem_file = null; // if ($this->wechat_config->key_pem) { // $key_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($this->wechat_config->key_pem); // if (!file_exists($key_pem_file)) { // file_put_contents($key_pem_file, $this->wechat_config->key_pem); // } // } // $config = [ // 'app_id' => $this->wechat_config->app_id, // 'secret' => $this->wechat_config->app_secret, // 'key' => $this->wechat_config->pay_key, // 'mch_id' => $this->wechat_config->mch_id, // 'cert_path' => $cert_pem_file, // 'key_path' => $key_pem_file, // 'response_type' => 'array' // ]; // $this->wechatPay = Factory::payment($config); // $this->wechatMini = Factory::miniProgram($config); // // return Factory::payment($config); // } /** * 支付宝初始化操作 */ public function initAlipay() { $config_cache = \Yii::$app->cache->get('alipay_config_cache_' . get_store_id()); if ($config_cache) { $this->alipay_config = Json::decode($config_cache); } else { $this->alipay_config = Json::decode(Option::get(Option::OPTOPN_KEY, get_store_id(), 'alipay')['value']); } $config = [ 'app_id' => $this->alipay_config['app_id'], 'notify_url' => 'www.baidu.com', 'return_url' => '', 'ali_public_key' => $this->alipay_config['alipay_public_key'], 'private_key' => preg_replace('# #', '', $this->alipay_config['app_private_key']), // 'log' => [ // optional // 'file' => '~/var/logs/alipay.log', // 'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug // 'type' => 'single', // optional, 可选 daily. // 'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天 // ], 'http' => [ 'timeout' => 5.0, 'connect_timeout' => 5.0, ], // 'mode' => 'dev', // optional,设置此参数,将进入沙箱模式 ]; $this->aliPay = Pay::alipay($config); } }