| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\models\v1;
- use app\models\Option;
- use app\models\WechatConfig;
- use app\utils\Wechat\WechatProfit;
- use EasyWeChat\Factory;
- class NewMerchantMiniPayForm extends WechatProfit
- {
- public function getConfig($store_id = 0){
- $store_id = $store_id > 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);
- }
- }
|