This commit is contained in:
xl
2023-11-14 01:08:06 +08:00
parent 0d8ddfef54
commit a6a2a0f472
11 changed files with 691 additions and 762 deletions
+13 -7
View File
@@ -22,6 +22,9 @@ abstract class Multiprogramming implements Progaram
protected string $errorMsg = '';
protected string $host = 'api.weixin.qq.com';
/**
* @var AppConfig
*/
@@ -136,11 +139,12 @@ abstract class Multiprogramming implements Progaram
/**
* @param string $requestUrl
* @param mixed $body
* @param string $contentType
* @return Result
*/
protected function post(string $requestUrl, mixed $body): Result
protected function post(string $requestUrl, mixed $body, string $contentType = 'application/application'): Result
{
return $this->request('post', $requestUrl, $body);
return $this->request('post', $requestUrl, $body, $contentType);
}
@@ -149,9 +153,9 @@ abstract class Multiprogramming implements Progaram
* @param mixed $body
* @return Result
*/
protected function get(string $requestUrl, mixed $body): Result
protected function get(string $requestUrl, mixed $body, string $contentType = 'application/application'): Result
{
return $this->request('get', $requestUrl, $body);
return $this->request('get', $requestUrl, $body, $contentType);
}
@@ -170,22 +174,24 @@ abstract class Multiprogramming implements Progaram
* @param string $method
* @param string $requestUrl
* @param $body
* @param string $contentType
* @return Result
*/
private function request(string $method, string $requestUrl, $body): Result
private function request(string $method, string $requestUrl, $body, string $contentType = 'application/application'): Result
{
$client = new Client('api.weixin.qq.com', 443, true);
$client->withHeader(['Content-Type' => 'application/json']);
$client = new Client($this->host, 443, true);
$proxyHost = $this->getConfig()->getProxyHost();
$proxyPort = $this->getConfig()->getProxyPort();
if (!empty($proxyHost) && $proxyPort > 0) {
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
}
if ($method == 'post') {
$client->withHeader(['Content-Type' => $contentType]);
$client->post($requestUrl, $body);
} else if ($method == 'upload') {
$client->upload($requestUrl, $body);
} else {
$client->withHeader(['Content-Type' => $contentType]);
$client->get($requestUrl, $body);
}
$client->close();