Files
kiri-wchat/wx/SecCheck.php
T

82 lines
2.0 KiB
PHP
Raw Normal View History

2019-12-19 15:00:25 +08:00
<?php
2020-03-05 12:41:49 +08:00
namespace wchat\wx;
2019-12-19 15:00:25 +08:00
2022-09-09 16:42:55 +08:00
use Kiri\Client;
2020-03-05 12:41:49 +08:00
use wchat\common\Result;
2019-12-19 15:00:25 +08:00
/**
* Class SecCheck
* @package wchat
*/
class SecCheck extends SmallProgram
{
2023-11-14 00:45:54 +08:00
private string $_url = '/wxa/img_sec_check?access_token=';
private string $_msgUrl = '/wxa/msg_sec_check?access_token=';
private string $_mediaCheckAsync = '/wxa/media_check_async?access_token=';
const MEDIA_VIDEO = 1;
const MEDIA_IMAGE = 1;
/**
* @param string $path
* @return Result
*/
public function image(string $path = ''): Result
{
if (!file_exists($path)) {
return $this->sendError('文件不存在', 404);
2023-11-07 15:13:11 +08:00
}
2023-11-14 00:45:54 +08:00
$access_token = $this->payConfig->getAccessToken();
2023-11-14 12:39:28 +08:00
return $this->upload('api.weixin.qq.com', $this->_url . '?access_token=' . $access_token, [
2023-11-14 00:45:54 +08:00
'media' => new \CURLFile($path)
]);
}
/**
* @param string $url
* @param int $type
* @return mixed
* @throws
*/
public function mediaAsync(string $url, int $type = SecCheck::MEDIA_IMAGE): Result
{
if (!in_array($type, [self::MEDIA_IMAGE, self::MEDIA_VIDEO])) {
throw new \Exception('暂不支持的文件类型');
2023-11-07 15:13:11 +08:00
}
2023-11-14 00:45:54 +08:00
$requestUrl = $this->_mediaCheckAsync . $this->payConfig->getAccessToken();
2023-11-14 12:39:28 +08:00
return $this->post('api.weixin.qq.com', $requestUrl, ['media_url' => $url, 'media_type' => $type]);
2023-11-14 00:45:54 +08:00
}
/**
* @param $params
* @return ContentAsyncCheck|null
*/
public function readByEvent($params): ?ContentAsyncCheck
{
return ContentAsyncCheck::instance($params);
}
/**
* @param $content
* @return Result
*/
public function text($content): Result
{
if (empty($content)) {
return $this->sendError('文件不存在', 404);
2023-11-07 15:13:11 +08:00
}
2023-11-14 00:45:54 +08:00
$requestUrl = $this->_msgUrl . $this->payConfig->getAccessToken();
2023-11-14 12:39:28 +08:00
return $this->post('api.weixin.qq.com', $requestUrl, ['content' => $content]);
2023-11-14 00:45:54 +08:00
}
2019-12-19 15:00:25 +08:00
}