0 ? $store_id : get_store_id(); if (is_profit_pay('wx', $store_id)) { $wechat_config = Option::getSaasWechat(); // 证书 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 ($wechat_config['sp_apiclient_cert']) { $cert_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($wechat_config['sp_apiclient_cert']); if (!file_exists($cert_pem_file)) { file_put_contents($cert_pem_file, $wechat_config['sp_apiclient_cert']); } } $key_pem_file = null; if ($wechat_config['sp_apiclient_key']) { $key_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($wechat_config['sp_apiclient_key']); if (!file_exists($key_pem_file)) { file_put_contents($key_pem_file, $wechat_config['sp_apiclient_key']); } } $config = [ // 必要配置 'app_id' => $wechat_config['sp_appid'], 'mch_id' => $wechat_config['sp_mch_id'], 'key' => $wechat_config['sp_key'], // API 密钥 // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书) 'cert_path' => $cert_pem_file, // XXX: 绝对路径!!!! 'key_path' => $key_pem_file, // XXX: 绝对路径!!!! 'notify_url' => '', // 你也可以在下单时单独设置来想覆盖它 ]; } else { $wechat_config = WechatConfig::findOne(['store_id' => $store_id, 'type' => 1]); // 证书 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 ($wechat_config->cert_pem) { $cert_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($wechat_config->cert_pem); if (!file_exists($cert_pem_file)) { file_put_contents($cert_pem_file, $wechat_config->cert_pem); } } $key_pem_file = null; if ($wechat_config->key_pem) { $key_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($wechat_config->key_pem); if (!file_exists($key_pem_file)) { file_put_contents($key_pem_file, $wechat_config->key_pem); } } $config = [ 'app_id' => $wechat_config->app_id, 'secret' => $wechat_config->app_secret, 'key' => $wechat_config->pay_key, 'mch_id' => $wechat_config->mch_id, 'cert_path' => $cert_pem_file, 'key_path' => $key_pem_file, 'response_type' => 'array' ]; } return Factory::payment($config); } }