add clear

This commit is contained in:
as2252258@163.com
2019-11-11 18:14:47 +08:00
parent 62a2326e23
commit 7f138ef255
47 changed files with 2440 additions and 1100 deletions
+100
View File
@@ -0,0 +1,100 @@
<?php
namespace officialaccount;
use common\HttpClient;
use common\Result;
class SourceMaterial extends AfficialAccount
{
private $uploadUrl = 'https://api.weixin.qq.com/cgi-bin/media/upload?';
private $getUploadUrl = 'https://api.weixin.qq.com/cgi-bin/media/get';
/**
* @param $file
* @return bool|mixed|Result
*/
public function ImageUpload($file)
{
if (!file_exists($file)) {
return $this->sendError('文件不存在.', 404);
}
return $this->upload($file, 'image');
}
/**
* @param $file
* @return bool|mixed|Result
*/
public function VoiceUpload($file)
{
if (!file_exists($file)) {
return $this->sendError('文件不存在.', 404);
}
return $this->upload($file, 'voice');
}
/**
* @param $file
* @return bool|mixed|Result
*/
public function VideoUpload($file)
{
if (!file_exists($file)) {
return $this->sendError('文件不存在.', 404);
}
return $this->upload($file, 'video');
}
/**
* @param $file
* @return bool|mixed|Result
*/
public function ThumbUpload($file)
{
if (!file_exists($file)) {
return $this->sendError('文件不存在.', 404);
}
return $this->upload($file, 'thumb');
}
/**
* @param $media_id
* @return array|mixed|Result
*/
public function MediaGet($media_id)
{
$client = HttpClient::NewRequest();
$accessToken = $this->config->getAccessToken();
return $client->get($this->getUploadUrl, ['access_token' => $accessToken, 'media_id' => $media_id]);
}
/**
* @param $file
* @param $type
* @return bool|mixed
*/
private function upload($file, $type)
{
$uploadInfo['media'] = new \CURLFile($file);
$uploadInfo['form-data[filename]'] = $uploadInfo['media']->getFilename();
$uploadInfo['form-data[content-type]'] = $uploadInfo['media']->getMimeType();
$accessToken = $this->config->getAccessToken();
$url = $this->uploadUrl . 'access_token=' . $accessToken . '&type=' . $type;
$result = $this->request->post($url, $uploadInfo);
if (!$result->isResultsOK()) {
return false;
}
return $result->getData();
}
}