Files
kiri-wchat/wchat/common/Config.php
T

571 lines
8.0 KiB
PHP
Raw Normal View History

2019-07-17 17:17:37 +08:00
<?php
2020-03-05 12:41:49 +08:00
namespace wchat\common;
2019-07-17 17:17:37 +08:00
class Config
{
/**
* @var string
*
* 小程序ID
*/
2022-09-09 16:42:55 +08:00
private string $appid = '';
2019-07-17 17:17:37 +08:00
/**
* @var string
*
* 商户号ID
*/
2022-09-09 16:42:55 +08:00
private string $mch_id = '';
2019-07-17 17:17:37 +08:00
/**
* @var string
*
* 设备号
*/
2022-09-09 16:42:55 +08:00
private string $device_info = 'WEB';
private string $token;
private string $encodingAesKey;
private string $schema = 'WECHATPAY2-SHA256-RSA2048';
private string $serial_no = '33F00000E4248E2EB3C61FC8384E1E155ECBB1B2';
2019-07-17 17:17:37 +08:00
2019-11-11 18:14:47 +08:00
2019-07-17 17:17:37 +08:00
/**
* @var string
*
* 随机字符串
*/
2022-09-09 16:42:55 +08:00
private string $nonce_str = '';
2019-07-17 17:17:37 +08:00
/**
* @var string
*
* 商品简单描述
*/
2022-09-09 16:42:55 +08:00
private string $body = '好友默契Pk充值!';
2019-07-17 17:17:37 +08:00
/**
* @var string
*
* 商户订单号
*/
2022-09-09 16:42:55 +08:00
private string $out_trade_no = "";
2019-07-17 17:17:37 +08:00
/**
2022-09-09 16:42:55 +08:00
* @var int|float
2019-07-17 17:17:37 +08:00
*
* 金额
*/
2022-09-09 16:42:55 +08:00
private float|int $total_fee = 0;
2019-07-17 17:17:37 +08:00
/**
* @var string
*
* 终端IP
*/
2022-09-09 16:42:55 +08:00
private string $spbill_create_ip = "";
2019-07-17 17:17:37 +08:00
/**
* @var string
*
* 异步回调地址
*/
2022-09-09 16:42:55 +08:00
private string $notify_url = "";
2019-07-17 17:17:37 +08:00
/**
* @var string
*
* 交易类型
*/
2022-09-09 16:42:55 +08:00
private string $trade_type = 'JSAPI';
2019-07-17 17:17:37 +08:00
/**
* @var string
*
* 签名方式
*/
2022-09-09 16:42:55 +08:00
private string $sign_type = 'MD5';
2019-07-17 17:17:37 +08:00
/**
* @var string
*
* 商户接口地址
*/
2022-09-09 16:42:55 +08:00
private string $mch_host = 'https://api.mch.weixin.qq.com';
2019-07-17 17:17:37 +08:00
/**
* @var string
*/
2022-09-09 16:42:55 +08:00
private string $appsecret = '';
2019-07-17 17:17:37 +08:00
2022-09-09 16:42:55 +08:00
private string $remote_addr = '127.0.0.1';
2019-07-17 17:17:37 +08:00
2022-09-09 16:42:55 +08:00
private string $ssl_cert = '';
private string $ssl_key = '';
private string $ssl_ca = '';
private int $port = 443;
2019-07-17 17:17:37 +08:00
/**
* @var string
*/
2022-09-09 16:42:55 +08:00
private string $key = '';
private string $access_token = '';
private string $agent = '';
private bool $usrSwoole = false;
2020-01-07 11:44:45 +08:00
2020-04-03 17:18:21 +08:00
/**
* @return string
*/
2022-09-09 16:42:55 +08:00
public function getSchema(): string
2020-04-03 17:18:21 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->schema;
2020-04-03 17:18:21 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $schema
2020-04-03 17:18:21 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setSchema(string $schema): void
2020-04-03 17:18:21 +08:00
{
2022-09-09 16:42:55 +08:00
$this->schema = $schema;
2020-04-03 17:18:21 +08:00
}
/**
* @return string
*/
2022-09-09 16:42:55 +08:00
public function getSerialNo(): string
2020-04-03 17:18:21 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->serial_no;
2020-04-03 17:18:21 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $serial_no
2020-04-03 17:18:21 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setSerialNo(string $serial_no): void
2020-04-03 17:18:21 +08:00
{
2022-09-09 16:42:55 +08:00
$this->serial_no = $serial_no;
2020-04-03 17:18:21 +08:00
}
2020-01-07 11:44:45 +08:00
/**
2022-09-09 16:42:55 +08:00
* @return string
2020-01-07 11:44:45 +08:00
*/
2022-09-09 16:42:55 +08:00
public function getAppid(): string
2020-01-07 11:44:45 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->appid;
2020-01-07 11:44:45 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $appid
2020-01-07 11:44:45 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setAppid(string $appid): void
2020-01-07 11:44:45 +08:00
{
2022-09-09 16:42:55 +08:00
$this->appid = $appid;
2020-01-07 11:44:45 +08:00
}
2019-09-19 18:58:46 +08:00
/**
* @return string
*/
2022-09-09 16:42:55 +08:00
public function getMchId(): string
2019-09-19 18:58:46 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->mch_id;
2019-09-19 18:58:46 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $mch_id
2019-09-19 18:58:46 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setMchId(string $mch_id): void
2019-09-19 18:58:46 +08:00
{
2022-09-09 16:42:55 +08:00
$this->mch_id = $mch_id;
}
/**
* @return string
*/
public function getDeviceInfo(): string
{
return $this->device_info;
2019-09-19 18:58:46 +08:00
}
2019-11-11 18:14:47 +08:00
/**
2022-09-09 16:42:55 +08:00
* @param string $device_info
*/
public function setDeviceInfo(string $device_info): void
{
$this->device_info = $device_info;
}
/**
* @return string
2019-11-11 18:14:47 +08:00
*/
2022-09-09 16:42:55 +08:00
public function getToken(): string
2019-11-11 18:14:47 +08:00
{
return $this->token;
}
/**
2022-09-09 16:42:55 +08:00
* @param string $token
2019-11-11 18:14:47 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setToken(string $token): void
2019-11-11 18:14:47 +08:00
{
$this->token = $token;
}
2019-09-19 18:58:46 +08:00
2019-11-11 18:14:47 +08:00
/**
2022-09-09 16:42:55 +08:00
* @return string
2019-11-11 18:14:47 +08:00
*/
2022-09-09 16:42:55 +08:00
public function getEncodingAesKey(): string
2019-11-11 18:14:47 +08:00
{
return $this->encodingAesKey;
}
/**
2022-09-09 16:42:55 +08:00
* @param string $encodingAesKey
2019-11-11 18:14:47 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setEncodingAesKey(string $encodingAesKey): void
2019-11-11 18:14:47 +08:00
{
$this->encodingAesKey = $encodingAesKey;
}
2019-07-17 17:27:31 +08:00
/**
* @return string
*/
2022-09-09 16:42:55 +08:00
public function getNonceStr(): string
2019-07-17 17:27:31 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->nonce_str;
2019-07-17 17:27:31 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $nonce_str
2019-07-17 17:27:31 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setNonceStr(string $nonce_str): void
2019-07-17 17:27:31 +08:00
{
2022-09-09 16:42:55 +08:00
$this->nonce_str = $nonce_str;
2019-07-17 17:27:31 +08:00
}
2019-07-17 17:17:37 +08:00
/**
2022-09-09 16:42:55 +08:00
* @return string
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function getBody(): string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->body;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $body
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setBody(string $body): void
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
$this->body = $body;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @return string
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function getOutTradeNo(): string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->out_trade_no;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $out_trade_no
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setOutTradeNo(string $out_trade_no): void
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
$this->out_trade_no = $out_trade_no;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @return int
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function getTotalFee(): int|string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->total_fee;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param int $total_fee
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setTotalFee(int|string $total_fee): void
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
$this->total_fee = $total_fee;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @return string
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function getSpbillCreateIp(): string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->spbill_create_ip;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $spbill_create_ip
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setSpbillCreateIp(string $spbill_create_ip): void
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
$this->spbill_create_ip = $spbill_create_ip;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @return string
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function getNotifyUrl(): string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->notify_url;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $notify_url
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setNotifyUrl(string $notify_url): void
2019-07-17 17:17:37 +08:00
{
$this->notify_url = $notify_url;
}
/**
2022-09-09 16:42:55 +08:00
* @return string
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function getTradeType(): string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->trade_type;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $trade_type
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setTradeType(string $trade_type): void
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
$this->trade_type = $trade_type;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @return string
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function getSignType(): string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->sign_type;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $sign_type
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setSignType(string $sign_type): void
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
$this->sign_type = $sign_type;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @return string
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function getMchHost(): string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->mch_host;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $mch_host
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setMchHost(string $mch_host): void
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
$this->mch_host = $mch_host;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @return string
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function getAppsecret(): string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->appsecret;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $appsecret
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setAppsecret(string $appsecret): void
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
$this->appsecret = $appsecret;
2019-07-17 17:17:37 +08:00
}
/**
* @return string
*/
2022-09-09 16:42:55 +08:00
public function getRemoteAddr(): string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->remote_addr;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $remote_addr
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setRemoteAddr(string $remote_addr): void
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
$this->remote_addr = $remote_addr;
2019-07-17 17:17:37 +08:00
}
/**
* @return string
*/
2022-09-09 16:42:55 +08:00
public function getSslCert(): string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->ssl_cert;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $ssl_cert
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setSslCert(string $ssl_cert): void
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
$this->ssl_cert = $ssl_cert;
2019-07-17 17:17:37 +08:00
}
/**
* @return string
*/
2022-09-09 16:42:55 +08:00
public function getSslKey(): string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->ssl_key;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $ssl_key
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setSslKey(string $ssl_key): void
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
$this->ssl_key = $ssl_key;
2019-07-17 17:17:37 +08:00
}
/**
* @return string
*/
2022-09-09 16:42:55 +08:00
public function getSslCa(): string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->ssl_ca;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $ssl_ca
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setSslCa(string $ssl_ca): void
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
$this->ssl_ca = $ssl_ca;
2019-07-17 17:17:37 +08:00
}
/**
* @return string
*/
2022-09-09 16:42:55 +08:00
public function getPort(): string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->port;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $port
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setPort(string $port): void
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
$this->port = $port;
2019-07-17 17:17:37 +08:00
}
/**
* @return string
*/
2022-09-09 16:42:55 +08:00
public function getKey(): string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->key;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $key
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setKey(string $key): void
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
$this->key = $key;
2019-07-17 17:17:37 +08:00
}
/**
* @return string
*/
2022-09-09 16:42:55 +08:00
public function getAccessToken(): string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->access_token;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $access_token
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setAccessToken(string $access_token): void
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
$this->access_token = $access_token;
2019-07-17 17:17:37 +08:00
}
/**
* @return string
*/
2022-09-09 16:42:55 +08:00
public function getAgent(): string
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
return $this->agent;
2019-07-17 17:17:37 +08:00
}
/**
2022-09-09 16:42:55 +08:00
* @param string $agent
2019-07-17 17:17:37 +08:00
*/
2022-09-09 16:42:55 +08:00
public function setAgent(string $agent): void
2019-07-17 17:17:37 +08:00
{
2022-09-09 16:42:55 +08:00
$this->agent = $agent;
2019-07-17 17:17:37 +08:00
}
2022-09-09 16:42:55 +08:00
/**
* @return bool
*/
public function isUsrSwoole(): bool
{
return $this->usrSwoole;
}
/**
* @param bool $usrSwoole
*/
public function setUsrSwoole(bool $usrSwoole): void
{
$this->usrSwoole = $usrSwoole;
}
2019-07-19 18:09:42 +08:00
2023-07-18 00:19:13 +08:00
/**
* @param array $configs
*/
public function __construct(array $configs)
{
$this->setConfigs($configs);
}
/**
2019-07-19 18:09:42 +08:00
* @param array $configs
* @return $this
*/
2023-07-18 00:24:58 +08:00
protected function setConfigs(array $configs): static
2019-07-19 18:09:42 +08:00
{
2019-07-19 18:09:58 +08:00
if (empty($configs)) {
return $this;
}
2019-07-19 18:09:42 +08:00
foreach ($configs as $key => $val) {
if (empty($val) || is_array($val)) {
continue;
}
if (!property_exists($this, $key)) {
continue;
}
$this->$key = $val;
}
return $this;
}
2019-07-17 17:17:37 +08:00
}