Files
kiri-wchat/wx/SecCheck.php
T

95 lines
2.4 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
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=';
2023-12-12 15:35:37 +08:00
const int MEDIA_VIDEO = 1;
const int MEDIA_IMAGE = 1;
2023-11-14 00:45:54 +08:00
/**
* @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
}
/**
2023-11-14 14:10:36 +08:00
* @param array $params
2023-11-14 00:45:54 +08:00
* @return ContentAsyncCheck|null
*/
2023-11-14 14:10:36 +08:00
public function readByEvent(array $params): ?ContentAsyncCheck
2023-11-14 00:45:54 +08:00
{
return ContentAsyncCheck::instance($params);
}
2024-05-07 14:38:47 +08:00
const SCENE_INFO = 1;
const SCENE_REPLY = 2;
const SCENE_DISCAZ = 3;
const SCENE_SHEJIAO = 4;
2023-11-14 00:45:54 +08:00
/**
2023-11-14 14:10:36 +08:00
* @param string $content
2024-05-07 14:38:47 +08:00
* @param int $scene
* @param string $openId
2023-11-14 00:45:54 +08:00
* @return Result
*/
2024-05-07 14:38:47 +08:00
public function text(string $content, int $scene, string $openId): Result
2023-11-14 00:45:54 +08:00
{
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();
2024-05-07 14:38:47 +08:00
return $this->post('api.weixin.qq.com', $requestUrl, json_encode([
'content' => $content,
'version' => 2,
'scene' => $scene,
'openid' => $openId
], JSON_UNESCAPED_UNICODE),'application/json');
2023-11-14 00:45:54 +08:00
}
2019-12-19 15:00:25 +08:00
}