eee
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user