70 lines
1.7 KiB
PHP
70 lines
1.7 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->addHeader('Host', 'api.q.qq.com');
|
|
$this->request->setErrorField('errCode');
|
|
$this->request->setErrorMsgField('errMsg');
|
|
$this->request->setAgent('');
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|