diff --git a/wchat/base/Subject.php b/wchat/base/Subject.php index d9cf73e..41335b5 100644 --- a/wchat/base/Subject.php +++ b/wchat/base/Subject.php @@ -162,7 +162,14 @@ abstract class Subject extends Multiprogramming $client = new Client($this->getHost(), 443, true); $client->withHeader(['Content-Type' => 'application/json; charset=utf-8']); - $client->post($this->getUrl() . '?access_token=' . $access_token, $params); + + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } + + $client->post($this->getUrl() . '?access_token=' . $access_token, $params); $client->close(); if (!in_array($client->getStatusCode(), [101, 200, 201])) { diff --git a/wchat/base/Template.php b/wchat/base/Template.php index 13fac61..2483a2f 100644 --- a/wchat/base/Template.php +++ b/wchat/base/Template.php @@ -133,7 +133,14 @@ abstract class Template extends Multiprogramming $client = new Client($this->getHost(), 443, true); $client->withHeader(['Content-Type' => 'application/json; charset=utf-8']); - $client->post($this->getUrl() . '?access_token=' . $access_token, $params); + + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } + + $client->post($this->getUrl() . '?access_token=' . $access_token, $params); $client->close(); if (!in_array($client->getStatusCode(), [101, 200, 201])) { diff --git a/wchat/common/Config.php b/wchat/common/Config.php index 533759f..221de52 100644 --- a/wchat/common/Config.php +++ b/wchat/common/Config.php @@ -7,534 +7,571 @@ namespace wchat\common; class Config { - /** - * @var string - * - * 小程序ID - */ - private string $appid = ''; - - - /** - * @var string - * - * 商户号ID - */ - private string $mch_id = ''; - - /** - * @var string - * - * 设备号 - */ - private string $device_info = 'WEB'; - - private string $token; - private string $encodingAesKey; - - private string $schema = 'WECHATPAY2-SHA256-RSA2048'; - - private string $serial_no = '33F00000E4248E2EB3C61FC8384E1E155ECBB1B2'; - - - /** - * @var string - * - * 随机字符串 - */ - private string $nonce_str = ''; - - /** - * @var string - * - * 商品简单描述 - */ - private string $body = '好友默契Pk充值!'; - - /** - * @var string - * - * 商户订单号 - */ - private string $out_trade_no = ""; - - /** - * @var int|float - * - * 金额 - */ - private float|int $total_fee = 0; - - /** - * @var string - * - * 终端IP - */ - private string $spbill_create_ip = ""; - - /** - * @var string - * - * 异步回调地址 - */ - private string $notify_url = ""; - - /** - * @var string - * - * 交易类型 - */ - private string $trade_type = 'JSAPI'; - - /** - * @var string - * - * 签名方式 - */ - private string $sign_type = 'MD5'; - - /** - * @var string - * - * 商户接口地址 - */ - private string $mch_host = 'https://api.mch.weixin.qq.com'; - - /** - * @var string - */ - private string $appsecret = ''; - - private string $remote_addr = '127.0.0.1'; - - private string $ssl_cert = ''; - private string $ssl_key = ''; - private string $ssl_ca = ''; - private int $port = 443; - - /** - * @var string - */ - private string $key = ''; - private string $access_token = ''; - private string $agent = ''; - private bool $usrSwoole = false; - - /** - * @return string - */ - public function getSchema(): string - { - return $this->schema; - } - - /** - * @param string $schema - */ - public function setSchema(string $schema): void - { - $this->schema = $schema; - } - - /** - * @return string - */ - public function getSerialNo(): string - { - return $this->serial_no; - } - - /** - * @param string $serial_no - */ - public function setSerialNo(string $serial_no): void - { - $this->serial_no = $serial_no; - } - - /** - * @return string - */ - public function getAppid(): string - { - return $this->appid; - } - - /** - * @param string $appid - */ - public function setAppid(string $appid): void - { - $this->appid = $appid; - } - - /** - * @return string - */ - public function getMchId(): string - { - return $this->mch_id; - } - - /** - * @param string $mch_id - */ - public function setMchId(string $mch_id): void - { - $this->mch_id = $mch_id; - } - - /** - * @return string - */ - public function getDeviceInfo(): string - { - return $this->device_info; - } - - /** - * @param string $device_info - */ - public function setDeviceInfo(string $device_info): void - { - $this->device_info = $device_info; - } - - /** - * @return string - */ - public function getToken(): string - { - return $this->token; - } - - /** - * @param string $token - */ - public function setToken(string $token): void - { - $this->token = $token; - } - - /** - * @return string - */ - public function getEncodingAesKey(): string - { - return $this->encodingAesKey; - } - - /** - * @param string $encodingAesKey - */ - public function setEncodingAesKey(string $encodingAesKey): void - { - $this->encodingAesKey = $encodingAesKey; - } - - /** - * @return string - */ - public function getNonceStr(): string - { - return $this->nonce_str; - } - - /** - * @param string $nonce_str - */ - public function setNonceStr(string $nonce_str): void - { - $this->nonce_str = $nonce_str; - } - - /** - * @return string - */ - public function getBody(): string - { - return $this->body; - } - - /** - * @param string $body - */ - public function setBody(string $body): void - { - $this->body = $body; - } - - /** - * @return string - */ - public function getOutTradeNo(): string - { - return $this->out_trade_no; - } - - /** - * @param string $out_trade_no - */ - public function setOutTradeNo(string $out_trade_no): void - { - $this->out_trade_no = $out_trade_no; - } - - /** - * @return int - */ - public function getTotalFee(): int|string - { - return $this->total_fee; - } - - /** - * @param int $total_fee - */ - public function setTotalFee(int|string $total_fee): void - { - $this->total_fee = $total_fee; - } - - /** - * @return string - */ - public function getSpbillCreateIp(): string - { - return $this->spbill_create_ip; - } - - /** - * @param string $spbill_create_ip - */ - public function setSpbillCreateIp(string $spbill_create_ip): void - { - $this->spbill_create_ip = $spbill_create_ip; - } - - /** - * @return string - */ - public function getNotifyUrl(): string - { - return $this->notify_url; - } - - /** - * @param string $notify_url - */ - public function setNotifyUrl(string $notify_url): void - { - $this->notify_url = $notify_url; - } - - /** - * @return string - */ - public function getTradeType(): string - { - return $this->trade_type; - } - - /** - * @param string $trade_type - */ - public function setTradeType(string $trade_type): void - { - $this->trade_type = $trade_type; - } - - /** - * @return string - */ - public function getSignType(): string - { - return $this->sign_type; - } - - /** - * @param string $sign_type - */ - public function setSignType(string $sign_type): void - { - $this->sign_type = $sign_type; - } - - /** - * @return string - */ - public function getMchHost(): string - { - return $this->mch_host; - } - - /** - * @param string $mch_host - */ - public function setMchHost(string $mch_host): void - { - $this->mch_host = $mch_host; - } - - /** - * @return string - */ - public function getAppsecret(): string - { - return $this->appsecret; - } - - /** - * @param string $appsecret - */ - public function setAppsecret(string $appsecret): void - { - $this->appsecret = $appsecret; - } - - /** - * @return string - */ - public function getRemoteAddr(): string - { - return $this->remote_addr; - } - - /** - * @param string $remote_addr - */ - public function setRemoteAddr(string $remote_addr): void - { - $this->remote_addr = $remote_addr; - } - - /** - * @return string - */ - public function getSslCert(): string - { - return $this->ssl_cert; - } - - /** - * @param string $ssl_cert - */ - public function setSslCert(string $ssl_cert): void - { - $this->ssl_cert = $ssl_cert; - } - - /** - * @return string - */ - public function getSslKey(): string - { - return $this->ssl_key; - } - - /** - * @param string $ssl_key - */ - public function setSslKey(string $ssl_key): void - { - $this->ssl_key = $ssl_key; - } - - /** - * @return string - */ - public function getSslCa(): string - { - return $this->ssl_ca; - } - - /** - * @param string $ssl_ca - */ - public function setSslCa(string $ssl_ca): void - { - $this->ssl_ca = $ssl_ca; - } - - /** - * @return string - */ - public function getPort(): string - { - return $this->port; - } - - /** - * @param string $port - */ - public function setPort(string $port): void - { - $this->port = $port; - } - - /** - * @return string - */ - public function getKey(): string - { - return $this->key; - } - - /** - * @param string $key - */ - public function setKey(string $key): void - { - $this->key = $key; - } - - /** - * @return string - */ - public function getAccessToken(): string - { - return $this->access_token; - } - - /** - * @param string $access_token - */ - public function setAccessToken(string $access_token): void - { - $this->access_token = $access_token; - } - - /** - * @return string - */ - public function getAgent(): string - { - return $this->agent; - } - - /** - * @param string $agent - */ - public function setAgent(string $agent): void - { - $this->agent = $agent; - } - - /** - * @return bool - */ - public function isUsrSwoole(): bool - { - return $this->usrSwoole; - } - - /** - * @param bool $usrSwoole - */ - public function setUsrSwoole(bool $usrSwoole): void - { - $this->usrSwoole = $usrSwoole; - } + /** + * @var string + * + * 小程序ID + */ + private string $appid = ''; + + + /** + * @var string + * + * 商户号ID + */ + private string $mch_id = ''; + + /** + * @var string + * + * 设备号 + */ + private string $device_info = 'WEB'; + + private string $token; + private string $encodingAesKey; + + private string $schema = 'WECHATPAY2-SHA256-RSA2048'; + + private string $serial_no = '33F00000E4248E2EB3C61FC8384E1E155ECBB1B2'; + + + /** + * @var string + * + * 随机字符串 + */ + private string $nonce_str = ''; + + /** + * @var string + * + * 商品简单描述 + */ + private string $body = '好友默契Pk充值!'; + + /** + * @var string + * + * 商户订单号 + */ + private string $out_trade_no = ""; + + /** + * @var int|float + * + * 金额 + */ + private float|int $total_fee = 0; + + /** + * @var string + * + * 终端IP + */ + private string $spbill_create_ip = ""; + + /** + * @var string + * + * 异步回调地址 + */ + private string $notify_url = ""; + + /** + * @var string + * + * 交易类型 + */ + private string $trade_type = 'JSAPI'; + + /** + * @var string + * + * 签名方式 + */ + private string $sign_type = 'MD5'; + + /** + * @var string + * + * 商户接口地址 + */ + private string $mch_host = 'https://api.mch.weixin.qq.com'; + + /** + * @var string + */ + private string $appsecret = ''; + + private string $remote_addr = '127.0.0.1'; + + + private string $proxyHost = ''; + private int $proxyPort = 0; + + private string $ssl_cert = ''; + private string $ssl_key = ''; + private string $ssl_ca = ''; + private int $port = 443; + + /** + * @var string + */ + private string $key = ''; + private string $access_token = ''; + private string $agent = ''; + private bool $usrSwoole = false; + + /** + * @return string + */ + public function getSchema(): string + { + return $this->schema; + } + + /** + * @param string $schema + */ + public function setSchema(string $schema): void + { + $this->schema = $schema; + } + + /** + * @return string + */ + public function getSerialNo(): string + { + return $this->serial_no; + } + + /** + * @param string $serial_no + */ + public function setSerialNo(string $serial_no): void + { + $this->serial_no = $serial_no; + } + + /** + * @param string $proxyHost + */ + public function setProxyHost(string $proxyHost): void + { + $this->proxyHost = $proxyHost; + } + + + /** + * @param int $proxyPort + */ + public function setProxyPort(int $proxyPort): void + { + $this->proxyPort = $proxyPort; + } + + /** + * @return string + */ + public function getProxyHost(): string + { + return $this->proxyHost; + } + + /** + * @return int + */ + public function getProxyPort(): int + { + return $this->proxyPort; + } + + /** + * @return string + */ + public function getAppid(): string + { + return $this->appid; + } + + /** + * @param string $appid + */ + public function setAppid(string $appid): void + { + $this->appid = $appid; + } + + /** + * @return string + */ + public function getMchId(): string + { + return $this->mch_id; + } + + /** + * @param string $mch_id + */ + public function setMchId(string $mch_id): void + { + $this->mch_id = $mch_id; + } + + /** + * @return string + */ + public function getDeviceInfo(): string + { + return $this->device_info; + } + + /** + * @param string $device_info + */ + public function setDeviceInfo(string $device_info): void + { + $this->device_info = $device_info; + } + + /** + * @return string + */ + public function getToken(): string + { + return $this->token; + } + + /** + * @param string $token + */ + public function setToken(string $token): void + { + $this->token = $token; + } + + /** + * @return string + */ + public function getEncodingAesKey(): string + { + return $this->encodingAesKey; + } + + /** + * @param string $encodingAesKey + */ + public function setEncodingAesKey(string $encodingAesKey): void + { + $this->encodingAesKey = $encodingAesKey; + } + + /** + * @return string + */ + public function getNonceStr(): string + { + return $this->nonce_str; + } + + /** + * @param string $nonce_str + */ + public function setNonceStr(string $nonce_str): void + { + $this->nonce_str = $nonce_str; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $body + */ + public function setBody(string $body): void + { + $this->body = $body; + } + + /** + * @return string + */ + public function getOutTradeNo(): string + { + return $this->out_trade_no; + } + + /** + * @param string $out_trade_no + */ + public function setOutTradeNo(string $out_trade_no): void + { + $this->out_trade_no = $out_trade_no; + } + + /** + * @return int + */ + public function getTotalFee(): int|string + { + return $this->total_fee; + } + + /** + * @param int $total_fee + */ + public function setTotalFee(int|string $total_fee): void + { + $this->total_fee = $total_fee; + } + + /** + * @return string + */ + public function getSpbillCreateIp(): string + { + return $this->spbill_create_ip; + } + + /** + * @param string $spbill_create_ip + */ + public function setSpbillCreateIp(string $spbill_create_ip): void + { + $this->spbill_create_ip = $spbill_create_ip; + } + + /** + * @return string + */ + public function getNotifyUrl(): string + { + return $this->notify_url; + } + + /** + * @param string $notify_url + */ + public function setNotifyUrl(string $notify_url): void + { + $this->notify_url = $notify_url; + } + + /** + * @return string + */ + public function getTradeType(): string + { + return $this->trade_type; + } + + /** + * @param string $trade_type + */ + public function setTradeType(string $trade_type): void + { + $this->trade_type = $trade_type; + } + + /** + * @return string + */ + public function getSignType(): string + { + return $this->sign_type; + } + + /** + * @param string $sign_type + */ + public function setSignType(string $sign_type): void + { + $this->sign_type = $sign_type; + } + + /** + * @return string + */ + public function getMchHost(): string + { + return $this->mch_host; + } + + /** + * @param string $mch_host + */ + public function setMchHost(string $mch_host): void + { + $this->mch_host = $mch_host; + } + + /** + * @return string + */ + public function getAppsecret(): string + { + return $this->appsecret; + } + + /** + * @param string $appsecret + */ + public function setAppsecret(string $appsecret): void + { + $this->appsecret = $appsecret; + } + + /** + * @return string + */ + public function getRemoteAddr(): string + { + return $this->remote_addr; + } + + /** + * @param string $remote_addr + */ + public function setRemoteAddr(string $remote_addr): void + { + $this->remote_addr = $remote_addr; + } + + /** + * @return string + */ + public function getSslCert(): string + { + return $this->ssl_cert; + } + + /** + * @param string $ssl_cert + */ + public function setSslCert(string $ssl_cert): void + { + $this->ssl_cert = $ssl_cert; + } + + /** + * @return string + */ + public function getSslKey(): string + { + return $this->ssl_key; + } + + /** + * @param string $ssl_key + */ + public function setSslKey(string $ssl_key): void + { + $this->ssl_key = $ssl_key; + } + + /** + * @return string + */ + public function getSslCa(): string + { + return $this->ssl_ca; + } + + /** + * @param string $ssl_ca + */ + public function setSslCa(string $ssl_ca): void + { + $this->ssl_ca = $ssl_ca; + } + + /** + * @return string + */ + public function getPort(): string + { + return $this->port; + } + + /** + * @param string $port + */ + public function setPort(string $port): void + { + $this->port = $port; + } + + /** + * @return string + */ + public function getKey(): string + { + return $this->key; + } + + /** + * @param string $key + */ + public function setKey(string $key): void + { + $this->key = $key; + } + + /** + * @return string + */ + public function getAccessToken(): string + { + return $this->access_token; + } + + /** + * @param string $access_token + */ + public function setAccessToken(string $access_token): void + { + $this->access_token = $access_token; + } + + /** + * @return string + */ + public function getAgent(): string + { + return $this->agent; + } + + /** + * @param string $agent + */ + public function setAgent(string $agent): void + { + $this->agent = $agent; + } + + /** + * @return bool + */ + public function isUsrSwoole(): bool + { + return $this->usrSwoole; + } + + /** + * @param bool $usrSwoole + */ + public function setUsrSwoole(bool $usrSwoole): void + { + $this->usrSwoole = $usrSwoole; + } /** @@ -546,25 +583,25 @@ class Config } /** - * @param array $configs - * @return $this - */ - protected function setConfigs(array $configs): static - { - if (empty($configs)) { - return $this; - } - foreach ($configs as $key => $val) { - if (empty($val) || is_array($val)) { - continue; - } - if (!property_exists($this, $key)) { - continue; - } + * @param array $configs + * @return $this + */ + protected function setConfigs(array $configs): static + { + if (empty($configs)) { + return $this; + } + foreach ($configs as $key => $val) { + if (empty($val) || is_array($val)) { + continue; + } + if (!property_exists($this, $key)) { + continue; + } - $this->$key = $val; - } - return $this; - } + $this->$key = $val; + } + return $this; + } } diff --git a/wchat/qq/Account.php b/wchat/qq/Account.php index 282ff77..a65bf05 100644 --- a/wchat/qq/Account.php +++ b/wchat/qq/Account.php @@ -27,7 +27,14 @@ class Account extends SmallProgram $client = new Client('api.q.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); - $client->get('sns/jscode2session', $param); + + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } + + $client->get('sns/jscode2session', $param); $client->close(); return Result::init($client); diff --git a/wchat/qq/Recharge.php b/wchat/qq/Recharge.php index ecd5158..c04ec32 100644 --- a/wchat/qq/Recharge.php +++ b/wchat/qq/Recharge.php @@ -52,6 +52,13 @@ class Recharge extends SmallProgram $client = new Client('qpay.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/xml']); $client->withBody($this->builder()); + + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } + $client->post($this->uniformer); $client->close(); diff --git a/wchat/qq/Redhat.php b/wchat/qq/Redhat.php index 99c2488..da8b036 100644 --- a/wchat/qq/Redhat.php +++ b/wchat/qq/Redhat.php @@ -303,6 +303,11 @@ class Redhat extends SmallProgram $client->withSslKeyFile($this->config->getSslKey()); $client->withSslCertFile($this->config->getSslCert()); $client->withCa($this->config->getSslCa()); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->post($this->sendUrl, http_build_query($this->generate())); $client->close(); if (!in_array($client->getStatusCode(), [101, 200, 201])) { @@ -336,6 +341,11 @@ class Redhat extends SmallProgram $requestParam['sign'] = $this->builderSign($requestParam); $client = new Client('qpay.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->post($this->searchUrl, $requestParam); $client->close(); if (!in_array($client->getStatusCode(), [101, 200, 201])) { diff --git a/wchat/qq/SecCheck.php b/wchat/qq/SecCheck.php index 7aa9515..b9a559e 100644 --- a/wchat/qq/SecCheck.php +++ b/wchat/qq/SecCheck.php @@ -37,6 +37,11 @@ class SecCheck extends SmallProgram ]; $client = new Client('api.q.qq.com', 443, true); $client->withHeader(['Content-Type' => 'multipart/form-data']); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->upload($path, $data); $client->close(); if (!in_array($client->getStatusCode(), [101, 200, 201])) { @@ -64,6 +69,11 @@ class SecCheck extends SmallProgram $client = new Client('api.q.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->post($url, ['appid' => $this->config->getAppid(), 'content' => $content]); $client->close(); diff --git a/wchat/qq/Token.php b/wchat/qq/Token.php index 018cb12..cb65c30 100644 --- a/wchat/qq/Token.php +++ b/wchat/qq/Token.php @@ -22,6 +22,11 @@ class Token extends SmallProgram ]; $client = new Client('api.q.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->get('/api/getToken', $query); $client->close(); if (!in_array($client->getStatusCode(), [101, 200, 201])) { diff --git a/wchat/qq/pay/Cash_Bonus.php b/wchat/qq/pay/Cash_Bonus.php index d6c123a..9ad4ff5 100644 --- a/wchat/qq/pay/Cash_Bonus.php +++ b/wchat/qq/pay/Cash_Bonus.php @@ -91,7 +91,14 @@ class Cash_Bonus extends SmallProgram $client->withSslCertFile($this->getConfig()->getSslCert()); $client->withSslKeyFile($this->getConfig()->getSslKey()); $client->withCa($this->getConfig()->getSslCa()); - $client->post($this->_cash, $this->orderConfig($mch_billno, $openId, $price)); + + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } + + $client->post($this->_cash, $this->orderConfig($mch_billno, $openId, $price)); $client->close(); if (!in_array($client->getStatusCode(), [101, 200, 201])) { return new Result(code: 505, message: $client->getBody()); diff --git a/wchat/qq/pay/Enterprise_payment.php b/wchat/qq/pay/Enterprise_payment.php index 6fadbf6..648e29a 100644 --- a/wchat/qq/pay/Enterprise_payment.php +++ b/wchat/qq/pay/Enterprise_payment.php @@ -77,7 +77,14 @@ class Enterprise_payment extends SmallProgram $client->withSslCertFile($this->getConfig()->getSslCert()); $client->withSslKeyFile($this->getConfig()->getSslKey()); $client->withCa($this->getConfig()->getSslCa()); - $client->post($this->_cash, $this->orderConfig($mch_billno, $openId, $price)); + + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } + + $client->post($this->_cash, $this->orderConfig($mch_billno, $openId, $price)); $client->close(); if (!in_array($client->getStatusCode(), [101, 200, 201])) { return new Result(code: 505, message: $client->getBody()); diff --git a/wchat/wx/Account.php b/wchat/wx/Account.php index 8ec19c1..0130e2d 100644 --- a/wchat/wx/Account.php +++ b/wchat/wx/Account.php @@ -30,6 +30,9 @@ class Account extends SmallProgram $client = new Client('api.weixin.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); + if (!empty($this->getConfig()->getProxyHost()) && $this->getConfig()->getProxyPort() > 0) { + $client->withProxyHost("192.168.0.57")->withProxyPort(12286); + } $client->get('sns/jscode2session', $param); $client->close(); @@ -59,6 +62,9 @@ class Account extends SmallProgram $client = new Client('api.weixin.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); + if (!empty($this->getConfig()->getProxyHost()) && $this->getConfig()->getProxyPort() > 0) { + $client->withProxyHost("192.168.0.57")->withProxyPort(12286); + } $client->get('cgi-bin/user/info', $query); $client->close(); @@ -112,6 +118,12 @@ class Account extends SmallProgram $sendBody['width'] = $width; $client = new Client('api.weixin.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); + + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->post($url . $this->getConfig()->getAccessToken(), $sendBody); $client->close(); if (!in_array($client->getStatusCode(), [101, 200, 201])) { diff --git a/wchat/wx/Message.php b/wchat/wx/Message.php index 5a6f138..7248e6e 100644 --- a/wchat/wx/Message.php +++ b/wchat/wx/Message.php @@ -261,6 +261,11 @@ class Message extends SmallProgram $client = new Client('api.weixin.qq.com', 443, true); $client->withHeader(['Content-Type' => 'multipart/form-data']); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->post($url, $data); $client->close(); @@ -297,6 +302,11 @@ class Message extends SmallProgram $client = new Client('api.weixin.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->post($url, $this->msgData); $client->close(); diff --git a/wchat/wx/PublicTemplate.php b/wchat/wx/PublicTemplate.php index 5174be4..d5e455d 100644 --- a/wchat/wx/PublicTemplate.php +++ b/wchat/wx/PublicTemplate.php @@ -148,6 +148,11 @@ class PublicTemplate extends SmallProgram $client = new Client('api.weixin.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->post($url, $default); $client->close(); diff --git a/wchat/wx/SecCheck.php b/wchat/wx/SecCheck.php index d7a7583..710b12d 100644 --- a/wchat/wx/SecCheck.php +++ b/wchat/wx/SecCheck.php @@ -36,6 +36,11 @@ class SecCheck extends SmallProgram $client = new Client('api.weixin.qq.com', 443, true); $client->withHeader(['Content-Type' => 'multipart/form-data']); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->upload($this->_url . '?access_token=' . $access_token, [ 'media' => new \CURLFile($path) ]); @@ -66,6 +71,11 @@ class SecCheck extends SmallProgram $requestUrl = $this->_mediaCheckAsync . $this->config->getAccessToken(); $client = new Client('api.weixin.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->post($requestUrl, ['media_url' => $url, 'media_type' => $type]); $client->close(); @@ -104,6 +114,11 @@ class SecCheck extends SmallProgram $client = new Client('api.weixin.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->post($requestUrl, ['content' => $content]); $client->close(); diff --git a/wchat/wx/Token.php b/wchat/wx/Token.php index 5c22302..d94effd 100644 --- a/wchat/wx/Token.php +++ b/wchat/wx/Token.php @@ -22,6 +22,11 @@ class Token extends SmallProgram ]; $client = new Client('api.weixin.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->get('cgi-bin/token', $query); $client->close(); if (!in_array($client->getStatusCode(), [101, 200, 201])) { diff --git a/wchat/wx/V2/WxV2AppPayment.php b/wchat/wx/V2/WxV2AppPayment.php index 3372407..bf8bc0f 100644 --- a/wchat/wx/V2/WxV2AppPayment.php +++ b/wchat/wx/V2/WxV2AppPayment.php @@ -34,6 +34,11 @@ class WxV2AppPayment extends SmallProgram $client = new Client('api.mch.weixin.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->withBody($this->sign($body)); $client->post($this->uniformed); $client->close(); diff --git a/wchat/wx/V2/WxV2PayJsApi.php b/wchat/wx/V2/WxV2PayJsApi.php index f292057..b901952 100644 --- a/wchat/wx/V2/WxV2PayJsApi.php +++ b/wchat/wx/V2/WxV2PayJsApi.php @@ -37,6 +37,11 @@ class WxV2PayJsApi extends SmallProgram $client = new Client('api.mch.weixin.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); $client->withBody($this->sign($body)); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->post($this->uniformed); $client->close(); @@ -83,6 +88,11 @@ class WxV2PayJsApi extends SmallProgram $client = new Client('api.mch.weixin.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); $client->withBody($this->sign($body)); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->post($this->uniformed); $client->close(); @@ -129,6 +139,11 @@ class WxV2PayJsApi extends SmallProgram $client = new Client('api.mch.weixin.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); $client->withBody($this->sign($body)); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->post($this->uniformed); $client->close(); @@ -175,6 +190,11 @@ class WxV2PayJsApi extends SmallProgram $client = new Client('api.mch.weixin.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); $client->withBody($this->sign($body)); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->post($this->uniformed); $client->close(); diff --git a/wchat/wx/V2/WxV2Withdrawal.php b/wchat/wx/V2/WxV2Withdrawal.php index 1c270f8..20031a1 100644 --- a/wchat/wx/V2/WxV2Withdrawal.php +++ b/wchat/wx/V2/WxV2Withdrawal.php @@ -40,6 +40,11 @@ class WxV2Withdrawal extends SmallProgram $client = new Client('api.mch.weixin.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); $client->withBody($body = Help::toXml($array)); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } $client->post($this->transfers); $client->close(); diff --git a/wchat/wx/V3/TransferBatches.php b/wchat/wx/V3/TransferBatches.php index 3c6d4fd..3b61271 100644 --- a/wchat/wx/V3/TransferBatches.php +++ b/wchat/wx/V3/TransferBatches.php @@ -32,8 +32,13 @@ class TransferBatches extends SmallProgram $client = new Client('api.mch.weixin.qq.com', 443, TRUE); $client->withAddedHeader('Authorization', $sign)->withContentType('application/json') - ->withAgent('application/json')->withBody($json) - ->post('/v3/transfer/batches'); + ->withAgent('application/json')->withBody($json)->withAddedHeader("Accept", "*/*"); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } + $client->post('/v3/transfer/batches'); $client->close(); return json_decode($client->getBody(), TRUE); diff --git a/wchat/wx/V3/WxV3AppPayment.php b/wchat/wx/V3/WxV3AppPayment.php index 866cb52..b8e7c3c 100644 --- a/wchat/wx/V3/WxV3AppPayment.php +++ b/wchat/wx/V3/WxV3AppPayment.php @@ -10,37 +10,42 @@ class WxV3AppPayment extends SmallProgram { - use WxV3PaymentTait; + use WxV3PaymentTait; - /** - * @param $orderNo - * @param int $total - * @param string|null $openId - * @param string $payer_client_ip - * @return array - * @throws Exception - */ - public function payment($orderNo, int $total, string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array - { - $body = $this->getInitCore($orderNo, $total); + /** + * @param $orderNo + * @param int $total + * @param string|null $openId + * @param string $payer_client_ip + * @return array + * @throws Exception + */ + public function payment($orderNo, int $total, string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array + { + $body = $this->getInitCore($orderNo, $total); - $body['scene_info'] = ['payer_client_ip' => $payer_client_ip]; + $body['scene_info'] = ['payer_client_ip' => $payer_client_ip]; - $sign = $this->signature('POST', '/v3/pay/transactions/components', $json = json_encode($body, JSON_UNESCAPED_UNICODE)); + $sign = $this->signature('POST', '/v3/pay/transactions/components', $json = json_encode($body, JSON_UNESCAPED_UNICODE)); - $client = new Client('api.mch.weixin.qq.com', 443, TRUE); - $client->withAddedHeader('Authorization', $sign)->withContentType('application/json') - ->withAgent('application/json')->withBody($json) - ->post('/v3/pay/transactions/components'); - $client->close(); + $client = new Client('api.mch.weixin.qq.com', 443, TRUE); + $client->withAddedHeader('Authorization', $sign)->withContentType('application/json') + ->withAgent('application/json')->withBody($json)->withAddedHeader("Accept", "*/*"); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } + $client->post('/v3/pay/transactions/components'); + $client->close(); - $json = json_decode($client->getBody(), TRUE); - if (!isset($json['prepay_id'])) { - throw new Exception('微信支付调用失败'); - } - return $this->createResponse($json, $body); - } + $json = json_decode($client->getBody(), TRUE); + if (!isset($json['prepay_id'])) { + throw new Exception('微信支付调用失败'); + } + return $this->createResponse($json, $body); + } } diff --git a/wchat/wx/V3/WxV3NativePayment.php b/wchat/wx/V3/WxV3NativePayment.php index 034122a..c58c574 100644 --- a/wchat/wx/V3/WxV3NativePayment.php +++ b/wchat/wx/V3/WxV3NativePayment.php @@ -31,8 +31,13 @@ class WxV3NativePayment extends SmallProgram $client = new Client('api.mch.weixin.qq.com', 443, TRUE); $client->withAddedHeader('Authorization', $sign)->withContentType('application/json') - ->withAgent('application/json')->withBody($json) - ->post('/v3/pay/transactions/native'); + ->withAgent('application/json')->withBody($json)->withAddedHeader("Accept", "*/*"); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } + $client->post('/v3/pay/transactions/native'); $client->close(); $json = json_decode($client->getBody(), TRUE); diff --git a/wchat/wx/V3/WxV3Payment.php b/wchat/wx/V3/WxV3Payment.php index 685bafe..386c7af 100644 --- a/wchat/wx/V3/WxV3Payment.php +++ b/wchat/wx/V3/WxV3Payment.php @@ -34,7 +34,13 @@ class WxV3Payment extends SmallProgram ->withContentType('application/json') ->withAddedHeader('User-Agent', 'application/json') ->withBody($json) - ->post('/v3/pay/transactions/jsapi'); + ->withAddedHeader("Accept", "*/*"); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } + $client->post('/v3/pay/transactions/jsapi'); $client->close(); $json = json_decode($client->getBody(), TRUE); diff --git a/wchat/wx/V3/WxV3Withdrawal.php b/wchat/wx/V3/WxV3Withdrawal.php index 6ac59ab..535127c 100644 --- a/wchat/wx/V3/WxV3Withdrawal.php +++ b/wchat/wx/V3/WxV3Withdrawal.php @@ -12,56 +12,62 @@ class WxV3Withdrawal extends SmallProgram { - use WxV3PaymentTait; + use WxV3PaymentTait; - /** - * @param $orderNo - * @param string $batch_name - * @param string $batch_remark - * @param TransferDetail[] $details - * @return array - * @throws Exception - */ - public function payment($orderNo, string $batch_name, string $batch_remark, array $details): array - { - $body = $this->create($orderNo, $batch_name, $batch_remark, $details); + /** + * @param $orderNo + * @param string $batch_name + * @param string $batch_remark + * @param TransferDetail[] $details + * @return array + * @throws Exception + */ + public function payment($orderNo, string $batch_name, string $batch_remark, array $details): array + { + $body = $this->create($orderNo, $batch_name, $batch_remark, $details); - $sign = $this->signature('POST', '/v3/pay/transactions/batches', $json = json_encode($body, JSON_UNESCAPED_UNICODE)); + $sign = $this->signature('POST', '/v3/pay/transactions/batches', $json = json_encode($body, JSON_UNESCAPED_UNICODE)); - $client = new Client('api.mch.weixin.qq.com', 443, TRUE); - $client->withAddedHeader('Authorization', $sign) - ->withContentType('application/json') - ->withAddedHeader('User-Agent', 'application/json') - ->withBody($json) - ->post('/v3/pay/transactions/batches'); - $client->close(); + $client = new Client('api.mch.weixin.qq.com', 443, TRUE); + $client->withAddedHeader('Authorization', $sign) + ->withContentType('application/json') + ->withAddedHeader('User-Agent', 'application/json') + ->withBody($json) + ->withAddedHeader("Accept", "*/*"); + $proxyHost = $this->getConfig()->getProxyHost(); + $proxyPort = $this->getConfig()->getProxyPort(); + if (!empty($proxyHost) && $proxyPort > 0) { + $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); + } + $client->post('/v3/pay/transactions/batches'); + $client->close(); - $json = json_decode($client->getBody(), TRUE); - if (!isset($json['prepay_id'])) { - throw new Exception('微信支付调用失败'); - } + $json = json_decode($client->getBody(), TRUE); + if (!isset($json['prepay_id'])) { + throw new Exception('微信支付调用失败'); + } - return $this->createResponse($json, $body); - } + return $this->createResponse($json, $body); + } - #[ArrayShape(['transfer_detail_list' => "array", 'total_amount' => "int", 'total_num' => "int", 'batch_remark' => "string", 'batch_name' => "string", 'out_batch_no' => ""])] - private function create($orderNo, string $batch_name, string $batch_remark, array $details): array - { - $total = 0; - $body = ['transfer_detail_list' => []]; - $body['out_batch_no'] = $orderNo; - $body['batch_name'] = $batch_name; - $body['batch_remark'] = $batch_remark; - $body['total_num'] = count($details); - foreach ($details as $detail) { - $total += $detail->transfer_amount; - $body['transfer_detail_list'][] = $detail->toArray(); - } - $body['total_amount'] = $total; - return $body; - } + #[ArrayShape(['transfer_detail_list' => "array", 'total_amount' => "int", 'total_num' => "int", 'batch_remark' => "string", 'batch_name' => "string", 'out_batch_no' => ""])] + private function create($orderNo, string $batch_name, string $batch_remark, array $details): array + { + $total = 0; + $body = ['transfer_detail_list' => []]; + $body['out_batch_no'] = $orderNo; + $body['batch_name'] = $batch_name; + $body['batch_remark'] = $batch_remark; + $body['total_num'] = count($details); + foreach ($details as $detail) { + $total += $detail->transfer_amount; + $body['transfer_detail_list'][] = $detail->toArray(); + } + $body['total_amount'] = $total; + return $body; + } }