add clear
This commit is contained in:
@@ -15,6 +15,10 @@ class Help extends Miniprogarampage
|
|||||||
{
|
{
|
||||||
$xml = "<xml>";
|
$xml = "<xml>";
|
||||||
foreach ($data as $key => $val) {
|
foreach ($data as $key => $val) {
|
||||||
|
if (is_array($val)) {
|
||||||
|
$xml .= static::xmlChild($val);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (is_numeric($val)) {
|
if (is_numeric($val)) {
|
||||||
$xml .= "<" . $key . ">" . $val . "</" . $key . ">";
|
$xml .= "<" . $key . ">" . $val . "</" . $key . ">";
|
||||||
} else {
|
} else {
|
||||||
@@ -26,6 +30,29 @@ class Help extends Miniprogarampage
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $array
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private static function xmlChild(array $array)
|
||||||
|
{
|
||||||
|
$string = '';
|
||||||
|
foreach ($array as $key => $value) {
|
||||||
|
if (is_array($value)) {
|
||||||
|
$string .= static::xmlChild($value);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_numeric($value)) {
|
||||||
|
$string .= "<" . $key . ">" . $value . "</" . $key . ">";
|
||||||
|
} else {
|
||||||
|
$string .= "<" . $key . "><![CDATA[" . $value . "]]></" . $key . ">";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $xml
|
* @param $xml
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
|||||||
@@ -0,0 +1,250 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace wchat\officialaccount;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Material
|
||||||
|
* @package wchat\officialaccount
|
||||||
|
*/
|
||||||
|
class Material extends AfficialAccount
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $filePath
|
||||||
|
* @param $type
|
||||||
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function addMedia($filePath, $type)
|
||||||
|
{
|
||||||
|
$curlFile = new \CURLFile(realpath($filePath));
|
||||||
|
$data = [
|
||||||
|
"media" => $curlFile,
|
||||||
|
'form-data[filename]' => $curlFile->getFilename(),
|
||||||
|
'form-data[content-type]' => $curlFile->getMimeType()
|
||||||
|
];
|
||||||
|
$this->request->setHost('api.weixin.qq.com');
|
||||||
|
$this->request->setErrorField('errcode');
|
||||||
|
$this->request->setErrorMsgField('errmsg');
|
||||||
|
$this->request->addHeader('Content-Type', 'application/json');
|
||||||
|
$data = $this->request->upload('/cgi-bin/media/upload?access_token=' . $this->config->getAccessToken() . '&type=' . $type, $data);
|
||||||
|
if (!$data->isResultsOK()) {
|
||||||
|
throw new Exception($data->getMessage());
|
||||||
|
}
|
||||||
|
return $data->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $filePath
|
||||||
|
* @param $type
|
||||||
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function addMaterial($filePath, $type)
|
||||||
|
{
|
||||||
|
$curlFile = new \CURLFile(realpath($filePath));
|
||||||
|
$data = [
|
||||||
|
"media" => $curlFile,
|
||||||
|
'form-data[filename]' => $curlFile->getFilename(),
|
||||||
|
'form-data[content-type]' => $curlFile->getMimeType()
|
||||||
|
];
|
||||||
|
$this->request->setHost('api.weixin.qq.com');
|
||||||
|
$this->request->setErrorField('errcode');
|
||||||
|
$this->request->setErrorMsgField('errmsg');
|
||||||
|
$this->request->addHeader('Content-Type', 'application/json');
|
||||||
|
$data = $this->request->upload('/cgi-bin/material/add_material?access_token=' . $this->config->getAccessToken() . '&type=' . $type, $data);
|
||||||
|
if (!$data->isResultsOK()) {
|
||||||
|
throw new Exception($data->getMessage());
|
||||||
|
}
|
||||||
|
return $data->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $articles
|
||||||
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function addNewsMaterial(array $articles)
|
||||||
|
{
|
||||||
|
$array['articles'] = [];
|
||||||
|
foreach ($articles as $article) {
|
||||||
|
$array['articles'][] = [
|
||||||
|
'title' => $article['title'],
|
||||||
|
'thumb_media_id' => $article['thumb_media_id'],
|
||||||
|
'author' => $article['author'],
|
||||||
|
'digest' => $article['digest'],
|
||||||
|
'show_cover_pic' => $article['show_cover_pic'],
|
||||||
|
'content' => $article['content'],
|
||||||
|
'content_source_url' => $article['content_source_url'],
|
||||||
|
'need_open_comment' => $article['need_open_comment'],
|
||||||
|
'only_fans_can_comment' => $article['only_fans_can_comment']
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$this->request->setHost('api.weixin.qq.com');
|
||||||
|
$this->request->setErrorField('errcode');
|
||||||
|
$this->request->setErrorMsgField('errmsg');
|
||||||
|
$this->request->addHeader('Content-Type', 'application/json');
|
||||||
|
$data = $this->request->post('/cgi-bin/material/add_news?access_token=' . $this->config->getAccessToken(), $array);
|
||||||
|
if (!$data->isResultsOK()) {
|
||||||
|
throw new Exception($data->getMessage());
|
||||||
|
}
|
||||||
|
return $data->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $filePath
|
||||||
|
* @param $type
|
||||||
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function addNewsMaterialImage($filePath, $type)
|
||||||
|
{
|
||||||
|
$curlFile = new \CURLFile(realpath($filePath));
|
||||||
|
$data = [
|
||||||
|
"media" => $curlFile,
|
||||||
|
'form-data[filename]' => $curlFile->getFilename(),
|
||||||
|
'form-data[content-type]' => $curlFile->getMimeType()
|
||||||
|
];
|
||||||
|
$this->request->setHost('api.weixin.qq.com');
|
||||||
|
$this->request->setErrorField('errcode');
|
||||||
|
$this->request->setErrorMsgField('errmsg');
|
||||||
|
$this->request->addHeader('Content-Type', 'application/json');
|
||||||
|
$data = $this->request->upload('/cgi-bin/material/add_material?access_token=' . $this->config->getAccessToken() . '&type=' . $type, $data);
|
||||||
|
if (!$data->isResultsOK()) {
|
||||||
|
throw new Exception($data->getMessage());
|
||||||
|
}
|
||||||
|
return $data->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* declare
|
||||||
|
* @param $media_id
|
||||||
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function getMaterial(string $media_id)
|
||||||
|
{
|
||||||
|
$this->request->setHost('api.weixin.qq.com');
|
||||||
|
$this->request->setErrorField('errcode');
|
||||||
|
$this->request->setErrorMsgField('errmsg');
|
||||||
|
$this->request->addHeader('Content-Type', 'application/json');
|
||||||
|
$data = $this->request->post('/cgi-bin/material/get_material?access_token=' . $this->config->getAccessToken(), [
|
||||||
|
'media_id' => $media_id
|
||||||
|
]);
|
||||||
|
if (!$data->isResultsOK()) {
|
||||||
|
throw new Exception($data->getMessage());
|
||||||
|
}
|
||||||
|
return $data->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* declare
|
||||||
|
* @param $media_id
|
||||||
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function delMaterial(string $media_id)
|
||||||
|
{
|
||||||
|
$this->request->setHost('api.weixin.qq.com');
|
||||||
|
$this->request->setErrorField('errcode');
|
||||||
|
$this->request->setErrorMsgField('errmsg');
|
||||||
|
$this->request->addHeader('Content-Type', 'application/json');
|
||||||
|
$data = $this->request->post('/cgi-bin/material/del_material?access_token=' . $this->config->getAccessToken(), [
|
||||||
|
'media_id' => $media_id
|
||||||
|
]);
|
||||||
|
if (!$data->isResultsOK()) {
|
||||||
|
throw new Exception($data->getMessage());
|
||||||
|
}
|
||||||
|
return $data->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* declare
|
||||||
|
* @param string $media_id
|
||||||
|
* @param int $index
|
||||||
|
* @param array $articles
|
||||||
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function modifyNewsMaterial(string $media_id, int $index, array $articles)
|
||||||
|
{
|
||||||
|
$this->request->setHost('api.weixin.qq.com');
|
||||||
|
$this->request->setErrorField('errcode');
|
||||||
|
$this->request->setErrorMsgField('errmsg');
|
||||||
|
$this->request->addHeader('Content-Type', 'application/json');
|
||||||
|
$data = $this->request->post('/cgi-bin/material/del_material?access_token=' . $this->config->getAccessToken(), [
|
||||||
|
'media_id' => $media_id,
|
||||||
|
'index' => $index,
|
||||||
|
'articles' => [
|
||||||
|
'title' => $articles['title'],
|
||||||
|
'thumb_media_id' => $articles['thumb_media_id'],
|
||||||
|
'author' => $articles['author'],
|
||||||
|
'digest' => $articles['digest'],
|
||||||
|
'show_cover_pic' => $articles['show_cover_pic'],
|
||||||
|
'content' => $articles['content'],
|
||||||
|
'content_source_url' => $articles['content_source_url']
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
if (!$data->isResultsOK()) {
|
||||||
|
throw new Exception($data->getMessage());
|
||||||
|
}
|
||||||
|
return $data->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* declare
|
||||||
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function getMaterialCount()
|
||||||
|
{
|
||||||
|
$this->request->setHost('api.weixin.qq.com');
|
||||||
|
$this->request->setErrorField('errcode');
|
||||||
|
$this->request->setErrorMsgField('errmsg');
|
||||||
|
$this->request->addHeader('Content-Type', 'application/json');
|
||||||
|
$data = $this->request->get('/cgi-bin/material/get_materialcount?access_token=' . $this->config->getAccessToken());
|
||||||
|
if (!$data->isResultsOK()) {
|
||||||
|
throw new Exception($data->getMessage());
|
||||||
|
}
|
||||||
|
return $data->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* declare
|
||||||
|
* @param int $offset
|
||||||
|
* @param int $size
|
||||||
|
* @param string $type
|
||||||
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function getMaterialList(int $offset, int $size, string $type)
|
||||||
|
{
|
||||||
|
$this->request->setHost('api.weixin.qq.com');
|
||||||
|
$this->request->setErrorField('errcode');
|
||||||
|
$this->request->setErrorMsgField('errmsg');
|
||||||
|
$this->request->addHeader('Content-Type', 'application/json');
|
||||||
|
$data = $this->request->post('/cgi-bin/material/batchget_material?access_token=' . $this->config->getAccessToken(), [
|
||||||
|
'type' => $type,
|
||||||
|
'offset' => $offset,
|
||||||
|
'count' => $size
|
||||||
|
]);
|
||||||
|
if (!$data->isResultsOK()) {
|
||||||
|
throw new Exception($data->getMessage());
|
||||||
|
}
|
||||||
|
return $data->getData();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user