$store_id, 'type' => $from]); $config = [ 'app_id' => $wechat_config['sp_appid'], 'sub_appid' => $store_wechat->app_id, 'sub_mch_id' => $store_wechat->mch_id, 'response_type' => 'array' ]; // if ($navite == 1) { // $config['mch_id'] = $wechat_config['sp_mch_id']; // $config['sub_mch_id'] = $wechat_config['mch_id']; // $config['sub_appid'] = $wechat_config['sub_appid']; // } if ($is_platform) { $config['sub_appid'] = Option::get('platform_appid', 0, 'saas')['value']; } $self_mini = null; if ($store_id > 0) { $self_mini = \app\models\Option::get('self_mini', $store_id, 'store', 0)['value']; } if (\Yii::$app->prod_is_dandianpu() && !$self_mini && intval($from) === WechatConfig::TYPE_CONFIG_MINI) { $config['sub_appid'] = Option::get('one_store_wechat_appid', 0, 'saas', '')['value']; } if (\Yii::$app->prod_is_dandianpu() && intval($from) === WechatConfig::TYPE_CONFIG_MP) { $config['sub_appid'] = Option::get('one_store_wechat_official_appid', 0, 'saas', '')['value']; } // // // if($store_id>0){ // $storeInfo = Store::findOne($store_id); // if($storeInfo->business_model != 1){ // $config = Option::getBusinessWechat(); // $config['sub_mch_id'] = $store_wechat->mch_id; // } // } $storeInfo = Store::findOne($store_id); if($storeInfo->business_model != 1){ unset($config['sub_appid']); if ($from == WechatConfig::TYPE_CONFIG_APP) { $platform_appid = Option::get('platform_app_appid', 0, 'saas')['value']; } else { $platform_appid = Option::get('platform_appid', 0, 'saas')['value']; } $config['app_id'] = $platform_appid; $config['mch_id'] = $wechat_config['sp_mch_id']; } // 证书 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['key'] = $wechat_config['sp_key']; $config['mch_id'] = $wechat_config['sp_mch_id']; $config['cert_path'] = $cert_pem_file; $config['key_path'] = $key_pem_file; if(\Yii::$app->isSaas() && intval($from) === WechatConfig::TYPE_CONFIG_MP){ if (!\Yii::$app->prod_is_dandianpu()) { $config['sub_appid'] = $store_wechat->app_id; $config['sub_mch_id'] = $store_wechat->mch_id; } } if (\Yii::$app->prod_is_dandianpu() && intval($from) === WechatConfig::TYPE_CONFIG_H5){ unset($config['sub_appid']); } \Yii::error($config); self::$wechat_pay = Factory::payment($config); } /** * 初始化 * @param string $type * @param integer $from * @throws \Exception */ public static function initSaas($type = self::WECHAT_KIND_MINI) { if (!in_array($type, self::$validRequest)) { throw new \Exception('Input object type not available'); } $wechat_config = [ 'platform_appid' => Option::get('platform_appid', 0, 'saas')['value'], 'platform_mch_id' => Option::get('platform_mch_id', 0, 'saas')['value'], 'platform_key' => Option::get('platform_key', 0, 'saas')['value'], 'platform_apiclient_cert' => Option::get('platform_apiclient_cert', 0, 'saas')['value'], 'platform_apiclient_key' => Option::get('platform_apiclient_key', 0, 'saas')['value'], ]; $config = [ 'app_id' => $wechat_config['platform_appid'], 'secret' => $wechat_config['platform_key'], 'response_type' => 'array' ]; if ($type != self::WECHAT_KIND_PAY) { if ($type == self::WECHAT_KIND_MINI) { self::$wechat_mini = Factory::miniProgram($config); } else { self::$wechat_official = Factory::officialAccount($config); } } else { // 证书 if (!is_dir(\Yii::$app->runtimePath . '/saas/wechat/pem')) { mkdir(\Yii::$app->runtimePath . '/saas/wechat/pem'); file_put_contents(\Yii::$app->runtimePath . '/saas/wechat/pem/index.html', ''); } $cert_pem_file = null; if (!empty($wechat_config['platform_apiclient_cert'])) { $cert_pem_file = \Yii::$app->runtimePath . '/saas/wechat/pem/' . md5($wechat_config['platform_apiclient_cert']); if (!file_exists($cert_pem_file)) { file_put_contents($cert_pem_file, $wechat_config['platform_apiclient_cert']); } } $key_pem_file = null; if (!empty($wechat_config['platform_apiclient_key'])) { $key_pem_file = \Yii::$app->runtimePath . '/saas/wechat/pem/' . md5($wechat_config['platform_apiclient_key']); if (!file_exists($key_pem_file)) { file_put_contents($key_pem_file, $wechat_config['platform_apiclient_key']); } } $config['key'] = $wechat_config['platform_key']; $config['mch_id'] = $wechat_config['platform_mch_id']; $config['cert_path'] = $cert_pem_file; $config['key_path'] = $key_pem_file; \Yii::error($config); self::$wechat_pay = Factory::payment($config); } } /** * Undocumented function * * @Author LGL 24963@qq.com * @DateTime 2021-02-03 * @desc: 实例化支付类 * @return void */ public static function initBusiness ($_from = WechatConfig::TYPE_CONFIG_MINI) { $wechat_config = new WechatConfig(); $keys = [ 'sp_name', 'sp_appid', 'sp_mch_id', 'sp_key', 'sp_apiclient_cert', 'sp_apiclient_key', 'platform_api_key', 'platform_serial_no', 'platform_appid', 'platform_app_appid' ]; $data = Option::get($keys, 0, 'saas'); $data = array_column($data, 'value','name'); $wechat_config->app_id = $data['platform_appid']; $wechat_config->app_secret = $data['platform_serial_no']; $wechat_config->mch_id = $data['sp_mch_id']; $wechat_config->pay_key = $data['sp_key']; $wechat_config->cert_pem = $data['sp_apiclient_cert']; $wechat_config->key_pem = $data['sp_apiclient_key']; $config = [ 'app_id' => $data['sp_appid'], //'secret' => $wechat_config->app_secret, 'key' => $wechat_config->pay_key, 'mch_id' => $wechat_config->mch_id, 'response_type' => 'array' ]; if ($_from === WechatConfig::TYPE_CONFIG_APP) { $config['app_id'] = $data['platform_app_appid']; $config['app_secret'] = 'ec4cdee90d78680516eeef25f86b23a1'; } // 证书 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['cert_path'] = $cert_pem_file; $config['key_path'] = $key_pem_file; $config['sub_appid'] = $wechat_config->app_id; self::$wechat_pay = Factory::payment($config); } }