1 Commits

Author SHA1 Message Date
as2252258@163.com 8eb5922d10 add clear 2019-11-04 14:39:59 +08:00
2 changed files with 15 additions and 9 deletions
+9 -3
View File
@@ -14,7 +14,7 @@ abstract class Miniprogarampage
/** @var Config */ /** @var Config */
protected $config; protected $config;
/** @var mixed $instance */ /** @var Miniprogarampage $instance */
protected static $instance = null; protected static $instance = null;
/** @var WxClient */ /** @var WxClient */
@@ -40,6 +40,12 @@ abstract class Miniprogarampage
} }
static::$instance->config = $config; static::$instance->config = $config;
static::$instance->request->setAgent($config->getAgent()); static::$instance->request->setAgent($config->getAgent());
$request = static::$instance->request;
if ($request->getIsSSL()) {
$request->addHeader('ssl_cert_file', $config->getSslCert());
$request->addHeader('ssl_key_file', $config->getSslKey());
}
return static::$instance; return static::$instance;
} }
@@ -57,8 +63,8 @@ abstract class Miniprogarampage
$this->request->setMethod(WxClient::GET); $this->request->setMethod(WxClient::GET);
$data = $this->request->get('/cgi-bin/token', [ $data = $this->request->get('/cgi-bin/token', [
'grant_type' => 'client_credential', 'grant_type' => 'client_credential',
'appid' => $this->config->getAppid(), 'appid' => $this->config->getAppid(),
'secret' => $this->config->getAppsecret(), 'secret' => $this->config->getAppsecret(),
]); ]);
if (!$data->isResultsOK()) { if (!$data->isResultsOK()) {
throw new \Exception($data->getMessage()); throw new \Exception($data->getMessage());
+6 -6
View File
@@ -100,11 +100,11 @@ class WxClient
public function setIsSSL(bool $isSSL) public function setIsSSL(bool $isSSL)
{ {
$this->isSSL = $isSSL; $this->isSSL = $isSSL;
if ($this->isSSL) { }
$ssl = Wx::getMiniProGaRamPage()->getConfig();
$this->header['ssl_cert_file'] = $ssl->getSslCert(); public function getIsSSL()
$this->header['ssl_key_file'] = $ssl->getSslKey(); {
} return $this->isSSL;
} }
@@ -263,7 +263,7 @@ class WxClient
curl_setopt($ch, CURLOPT_SSLKEY, $this->header['ssl_key_file']); curl_setopt($ch, CURLOPT_SSLKEY, $this->header['ssl_key_file']);
} }
curl_setopt($ch, CURLOPT_NOBODY, FALSE); curl_setopt($ch, CURLOPT_NOBODY, FALSE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);// 超时设置 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); // 超时设置
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//返回内容 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//返回内容
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);// 跟踪重定向 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);// 跟踪重定向
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');