| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 | <?phpnamespace app\common\util\wechat;use app\common\model\Config;class WxAccountConfig{    /**     * 获取小程序接口配置参数     * @return array     * @throws \think\db\exception\DataNotFoundException     * @throws \think\db\exception\DbException     * @throws \think\db\exception\ModelNotFoundException     */    public static function getMiniProgramConfig()    {        $wxconfig = Config::getSettingModel("onlineRetailers");        $config = [            'app_id' => $wxconfig["appId"],            'secret' => $wxconfig["appSecret"],            'response_type' => "array",            'log' => [                'default' => 'dev', // 默认使用的 channel,生产环境可以改为下面的 prod                'channels' => [                    // 测试环境                    'dev' => [                        'driver' => 'daily',                        'path' => RUNTIME_PATH . '/easywechat_log/mini_program.log',                        'level' => 'debug',                    ],                    // 生产环境                    'prod' => [                        'driver' => 'daily',                        'path' => RUNTIME_PATH . '/easywechat_log/mini_program.log',                        'level' => 'info',                    ],                ],            ],        ];        return $config;    }    /**     * 获取公众号口配置参数     * @return array     * @throws \think\db\exception\DataNotFoundException     * @throws \think\db\exception\DbException     * @throws \think\db\exception\ModelNotFoundException     */    public static function getMpConfig()    {        $wxconfig = Config::getSettingModel("destination");        $config = [            'app_id' => $wxconfig["appId"],            'secret' => $wxconfig["appSecret"],            'response_type' => "array",            'log' => [                'default' => 'dev', // 默认使用的 channel,生产环境可以改为下面的 prod                'channels' => [                    // 测试环境                    'dev' => [                        'driver' => 'daily',                        'path' => RUNTIME_PATH . '/easywechat_log/mp.log',                        'level' => 'debug',                    ],                    // 生产环境                    'prod' => [                        'driver' => 'daily',                        'path' => RUNTIME_PATH . '/easywechat_log/mp.log',                        'level' => 'info',                    ],                ],            ],        ];        return $config;    }    /**     * 获取公众号口配置参数     * @return array     * @throws \think\db\exception\DataNotFoundException     * @throws \think\db\exception\DbException     * @throws \think\db\exception\ModelNotFoundException     */    public static function getWechatPayConfig()    {        $wxconfig = Config::getSettingModel("wechatPayment");        $config = [            'app_id' => $wxconfig["appId"],            'mch_id' => $wxconfig["merchantNumber"],            'key' => $wxconfig["merchantKey"],            'cert_path' => $wxconfig['certificate'] . "apiclient_cert.pem", // XXX: 绝对路径!!!!            'key_path' => $wxconfig['certificate'] . "apiclient_key.pem",      // XXX: 绝对路径!!!!            'response_type' => "array",            'log' => [                'default' => 'dev', // 默认使用的 channel,生产环境可以改为下面的 prod                'channels' => [                    // 测试环境                    'dev' => [                        'driver' => 'daily',                        'path' => RUNTIME_PATH . '/easywechat_log/mp.log',                        'level' => 'debug',                    ],                    // 生产环境                    'prod' => [                        'driver' => 'daily',                        'path' => RUNTIME_PATH . '/easywechat_log/mp.log',                        'level' => 'info',                    ],                ],            ],        ];        return $config;    }    public function getFullConfigExample()    {        return [            /**             * 账号基本信息,请从微信公众平台/开放平台获取             */            'app_id' => 'your-app-id',         // AppID            'secret' => 'your-app-secret',     // AppSecret            'token' => 'your-token',          // Token            'aes_key' => '',                    // EncodingAESKey,兼容与安全模式下请一定要填写!!!            /**             * 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名             * 使用自定义类名时,构造函数将会接收一个 `EasyWeChat\Kernel\Http\Response` 实例             */            'response_type' => 'array',            /**             * 日志配置             *             * level: 日志级别, 可选为:             *         debug/info/notice/warning/error/critical/alert/emergency             * path:日志文件位置(绝对路径!!!),要求可写权限             */            'log' => [                'default' => 'dev', // 默认使用的 channel,生产环境可以改为下面的 prod                'channels' => [                    // 测试环境                    'dev' => [                        'driver' => 'single',                        'path' => '/tmp/easywechat.log',                        'level' => 'debug',                    ],                    // 生产环境                    'prod' => [                        'driver' => 'daily',                        'path' => '/tmp/easywechat.log',                        'level' => 'info',                    ],                ],            ],            /**             * 接口请求相关配置,超时时间等,具体可用参数请参考:             * http://docs.guzzlephp.org/en/stable/request-config.html             *             * - retries: 重试次数,默认 1,指定当 http 请求失败时重试的次数。             * - retry_delay: 重试延迟间隔(单位:ms),默认 500             * - log_template: 指定 HTTP 日志模板,请参考:https://github.com/guzzle/guzzle/blob/master/src/MessageFormatter.php             */            'http' => [                'max_retries' => 1,                'retry_delay' => 500,                'timeout' => 5.0,                // 'base_uri' => 'https://api.weixin.qq.com/', // 如果你在国外想要覆盖默认的 url 的时候才使用,根据不同的模块配置不同的 uri            ],            /**             * OAuth 配置             *             * scopes:公众平台(snsapi_userinfo / snsapi_base),开放平台:snsapi_login             * callback:OAuth授权完成后的回调页地址             */            'oauth' => [                'scopes' => ['snsapi_userinfo'],                'callback' => '/examples/oauth_callback.php',            ],        ];    }}
 |