<?php

namespace app\admin\library;

use think\Config;

class Wechat
{


    /**
     * 获取小程序配置
     * @param int $brand_id 品牌商id
     * @return array
     */
    public function getMiniConfig(){

        $addonConfig = get_addon_config('epay');
        $config =  $addonConfig['wechat'];

            $miniConfig = [
                'appid'          => config("site.wx_miniapp_id") ?? '',
                'appsecret'      => config("site.wx_miniapp_secret") ?? '',
                'encodingaeskey' => '',
                // 配置商户支付参数
                'mch_id'         => $config['mch_id'] ?? '',
                'mch_key'        => $config['key'] ?? '',
                'mch_key_v3'        => $config['key_v3'] ?? '',
                // 配置商户支付双向证书目录 （p12 | key,cert 二选一，两者都配置时p12优先）

                'ssl_key'       => '',
                'ssl_cer'       => '',
                // 配置缓存目录，需要拥有写权限
                'cache_path'     => RUNTIME_PATH.'wechat',
            ];


        if (isset($config['cert_client']) && substr($config['cert_client'], 0, 8) == '/addons/') {
            $miniConfig['ssl_cer'] = ROOT_PATH . str_replace('/', DS, substr($config['cert_client'], 1));
        }
        if (isset($config['cert_key']) && substr($config['cert_key'], 0, 8) == '/addons/') {
            $miniConfig['ssl_key'] = ROOT_PATH . str_replace('/', DS, substr($config['cert_key'], 1));
        }

            return $miniConfig;
    }

}