diff --git a/app/data/command/UserTransfer.php b/app/data/command/UserTransfer.php index f38c44a5a..0ed26ebf3 100644 --- a/app/data/command/UserTransfer.php +++ b/app/data/command/UserTransfer.php @@ -4,6 +4,8 @@ namespace app\data\command; use app\data\service\DataService; use think\admin\Command; +use think\admin\Exception; +use think\admin\storage\LocalStorage; use think\console\Input; use think\console\Output; use WePay\Transfers; @@ -31,7 +33,7 @@ class UserTransfer extends Command { $map = ['type' => 1, 'status' => 3]; foreach ($this->app->db->name('DataUserTransfer')->where($map)->cursor() as $vo) try { - $wechat = Transfers::instance(DataService::instance()->payment()); + $wechat = Transfers::instance($this->getPayment()); $result = $wechat->create([ 'openid' => $vo['openid'], 'amount' => $vo['amount'] * 100, @@ -60,4 +62,28 @@ class UserTransfer extends Command ]); } } + + /** + * 获取微信提现参数 + * @return array + * @throws Exception + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + protected function getPayment(): array + { + $data = sysdata('TransferWxpay'); + if (empty($data)) throw new Exception('未配置微信提现商户'); + $key1 = LocalStorage::instance()->set("{$data['wechat_mch_id']}_key.pem", $data['wechat_mch_key_text'], true); + $key2 = LocalStorage::instance()->set("{$data['wechat_mch_id']}_cert.pem", $data['wechat_mch_cert_text'], true); + return [ + 'appid' => $data['wechat_appid'], + 'mch_id' => $data['wechat_mch_id'], + 'mch_key' => $data['wechat_mch_key'], + 'ssl_key' => $key1['file'], + 'ssl_cer' => $key2['file'], + 'cache_path' => $this->app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR . 'wechat', + ]; + } } \ No newline at end of file diff --git a/app/data/service/DataService.php b/app/data/service/DataService.php deleted file mode 100644 index 352e428e9..000000000 --- a/app/data/service/DataService.php +++ /dev/null @@ -1,48 +0,0 @@ - PaymentService::PAYMENT_WECHAT_GZH, 'status' => 1, 'deleted' => 0]; - $payment = $this->app->db->name('ShopPayment')->where($map)->order('sort desc,id desc')->find(); - if (empty($payment)) throw new Exception('读取有效的支付参数失败'); - // 解析服务号支付参数 - [, , $params] = PaymentService::config('', $payment); - if (empty($params)) throw new Exception('读取有效的支付参数失败'); - if (empty($params['wechat_mch_key_text']) || empty($params['wechat_mch_cert_text'])) { - throw new Exception('微信商户支付证书内容不能为空'); - } - $k1 = LocalStorage::instance()->set("{$params['code']}_key.pem", $params['wechat_mch_key_text'], true); - $k2 = LocalStorage::instance()->set("{$params['code']}_cert.pem", $params['wechat_mch_cert_text'], true); - return [ - 'appid' => $params['wechat_appid'], - 'mch_id' => $params['wechat_mch_id'], - 'mch_key' => $params['wechat_mch_key'], - 'ssl_key' => $k1['file'], - 'ssl_cer' => $k2['file'], - 'cache_path' => $this->app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR . 'wechat', - ]; - } catch (\Exception $exception) { - throw new Exception($exception->getMessage()); - } - } - -} \ No newline at end of file