123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace app\data\service;
- use think\admin\Exception;
- use think\admin\Service;
- use think\admin\storage\LocalStorage;
- class DataService extends Service
- {
-
- public function payment(): array
- {
- try {
- $map = ['type' => 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());
- }
- }
- }
|