mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-08-07 22:29:44 +08:00
修改接口配置
This commit is contained in:
parent
863f9bb5fe
commit
770061605c
@ -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',
|
||||
];
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\data\service;
|
||||
|
||||
use think\admin\Exception;
|
||||
use think\admin\Service;
|
||||
use think\admin\storage\LocalStorage;
|
||||
|
||||
/**
|
||||
* 基础数据服务
|
||||
* Class DataService
|
||||
* @package app\agent\service
|
||||
*/
|
||||
class DataService extends Service
|
||||
{
|
||||
/**
|
||||
* 获取支付配置
|
||||
* @return array|void
|
||||
* @throws Exception
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user