Files
kiri-wchat/wchat/qq/SecCheck.php
T
2020-08-24 11:50:17 +08:00

68 lines
1.6 KiB
PHP

<?php
namespace wchat\qq;
use wchat\common\Result;
/**
* Class SecCheck
* @package qq
*/
class SecCheck extends SmallProgram
{
private $_url = 'https://api.q.qq.com/api/json/security/ImgSecCheck?access_token=';
private $_msgUrl = '/api/json/security/MsgSecCheck?access_token=';
/**
* @param string $path
* @return array|Result|mixed
*/
public function image($path = '')
{
if (!file_exists($path)) {
return $this->sendError('文件不存在', 404);
}
$this->request->setUseSwoole(false);
$this->request->setHeader('Content-Type', 'multipart/form-data');
$this->request->setErrorField('errCode');
$this->request->setErrorMsgField('errMsg');
$real_path = new \CURLFile($path);
return $this->request->upload($this->_url . $this->config->getAccessToken(), [
'appid' => $this->config->getAppid(), 'media' => new \CURLFile($path)
, 'form-data[filename]' => $path, 'form-data[content-type]' => $real_path->getMimeType()
]);
}
/**
* @param $content
* @return array|Result|mixed
*/
public function text($content)
{
if (empty($content)) {
return $this->sendError('文件不存在', 404);
}
$this->request->setUseSwoole(true);
$this->request->addHeader('Content-Type', 'application/json');
$this->request->setErrorField('errCode');
$this->request->setErrorMsgField('errMsg');
$this->request->setData([
'appid' => $this->config->getAppid(),
'content' => $content
]);
$this->request->setHost('api.q.qq.com');
$this->request->setIsSSL(true);
$url = '/' . ltrim($this->_msgUrl, '/') . $this->config->getAccessToken();
return $this->request->post($url);
}
}