add clear

This commit is contained in:
as2252258@163.com
2019-12-19 15:00:25 +08:00
parent 3d16592366
commit 5fcbf18271
3 changed files with 281 additions and 0 deletions
+86
View File
@@ -0,0 +1,86 @@
<?php
namespace wchat;
use common\Result;
/**
* Class SecCheck
* @package wchat
*/
class SecCheck extends SmallProgram
{
private $_url = 'https://api.weixin.qq.com/wxa/img_sec_check?access_token=';
private $_msgUrl = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=';
private $_mediaCheckAsync = 'https://api.weixin.qq.com/wxa/media_check_async?access_token=';
const MEDIA_VIDEO = 1;
const MEDIA_IMAGE = 1;
/**
* @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']);
return $this->request->post($this->_url, ['media' => new \CURLFile($path)]);
}
/**
* @param string $url
* @param int $type
* @return mixed
* @throws
*/
public function mediaAsync(string $url, $type = SecCheck::MEDIA_IMAGE)
{
if (!in_array($type, [self::MEDIA_IMAGE, self::MEDIA_VIDEO])) {
throw new \Exception('暂不支持的文件类型');
}
$this->request->setHeader(['Content-Type' => 'application/json']);
$response = $this->request->post($this->_mediaCheckAsync, [
'media_url' => $url,
'media_type' => $type
]);
if (!$response->isResultsOK()) {
throw new \Exception($response->getMessage());
}
return $response->getData('trace_id');
}
/**
* @param $params
* @return ContentAsyncCheck|null
*/
public function readByEvent($params)
{
return ContentAsyncCheck::instance($params);
}
/**
* @param $content
* @return array|Result|mixed
*/
public function text($content)
{
if (empty($content)) {
return $this->sendError('文件不存在', 404);
}
$this->request->setHeader(['Content-Type' => 'application/json']);
return $this->request->post($this->_msgUrl, ['content' => $content]);
}
}