| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace app\common\service;
- use app\common\model\PayConfigModel;
- use utils\RedisCache;
- /**
- * 支付配置服务 by wes
- * Class PayConfigService
- * @package app\common\service
- */
- class PayConfigService
- {
- protected static $instance = null;
- protected $model = null;
- public function __construct()
- {
- $this->model = new PayConfigModel();
- }
- /**
- * 静态化入口
- * @return static|null
- */
- public static function make()
- {
- if(!self::$instance){
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 按渠道获取支付配置参数
- * @param $channel 渠道
- * @param string $field
- * @param bool $cache
- * @return array|mixed
- */
- public function getInfoByChannel($channel, $field='', $cache=true)
- {
- $cacheKey = "caches:temp:payConfig:channel_{$channel}".($field? '_'.md5($field):'');
- $data = RedisCache::get($cacheKey);
- if($data && $cache){
- return $data;
- }
- $field = $field? $field : 'app_id,private_key,public_key,app_cert_path,pay_root_cert,pay_cert_path,mchid';
- $data = $this->model->where(['channel'=> $channel,'status'=>1])->field($field)->findOrEmpty();
- $data = $data? $data->toArray() : [];
- if($data && $cache){
- RedisCache::set($cacheKey, $data, 7200);
- }
- return $data;
- }
- }
|