request->header(); // $this->brand_key = $this->request->server('BRAND_KEY', $this->request->request('brand-key', $header['brand-key'] ?? '')); // if (empty($this->brand_key)) { // $this->error('品牌key不能为空'); // } $this->brand_key = '2463650725715848382644224'; $brandModel = new \addons\xilufitness\model\Brand; $brand_id = $brandModel->where(['brand_key' => $this->brand_key])->value('id'); if (empty($brand_id)) { $this->error('品牌key无效'); } $this->brand_id = empty($brand_id) ? 1 : $brand_id; $this->miniConfig = (new Wechat())->getMiniConfig(); } /** * 支付签名 * sign 生成 * @param string $order_id 订单id * @param int $order_type 订单类型 * @param int $timestamp 时间戳 */ protected function paySign(string $order_id,int $order_type,int $timestamp){ return strtoupper(md5($order_id.$this->pay_key.$order_type.$timestamp)); } /** * 获取小程序配置 * @param int $brand_id 品牌商id * @return array */ protected function getMiniConfig(int $brand_id){ $brandConfig = Config::get('xilubrand')[$brand_id] ?? []; if(!empty($brandConfig)){ $this->miniConfig = [ 'appid' => $brandConfig['mini_appid'] ?? '', 'appsecret' => $brandConfig['mini_appsecret'] ?? '', 'encodingaeskey' => '', // 配置商户支付参数 'mch_id' => $brandConfig['mini_mch_id'] ?? '', 'mch_key' => $brandConfig['mini_mch_key'] ?? '', // 配置商户支付双向证书目录 (p12 | key,cert 二选一,两者都配置时p12优先) 'ssl_p12' => ROOT_PATH.'public'.$brandConfig['mini_mch_p12'] ?? '', 'ssl_key' => ROOT_PATH.'public'.$brandConfig['mini_mch_pem_key'] ?? '', 'ssl_cer' => ROOT_PATH.'public'.$brandConfig['mini_mch_pem_cert'] ?? '', // 配置缓存目录,需要拥有写权限 'cache_path' => RUNTIME_PATH.'wechat', ]; return $this->miniConfig; } return $brandConfig; } }