導航:首頁 > 編程語言 > php獲取微信素材

php獲取微信素材

發布時間:2022-05-12 07:12:42

Ⅰ 如何用 php 抓取微信文章正文

一、 頁面使用ajax

具體的WdatePicker.js可以在網上找一個。

資料來自:http://www.cnblogs.com/xiaonannan/p/6836494.html

Ⅱ 使用php如何獲取微信文章

可以嘗試使用DOM操作庫simple-html-dom.php,快速獲取HTML結構的內容:
<?php
require dirname(__FILE__).'/simple_html_dom.php';
$html = file_get_html('http://php.net/');
$articles = array();
foreach($html->find('article.newsentry') as $article) {
$item['time'] = trim($article->find('time', 0)->plaintext);
$item['title'] = trim($article->find('h2.newstitle', 0)->plaintext);
$item['content'] = trim($article->find('div.newscontent', 0)->plaintext);
$articles[] = $item;
}
print_r($articles);
可以把抓取到的內容寫入置於內存上的SQLite(/run/shm/php/crawler.db3),避免頻繁的磁碟IO.

Ⅲ 微信公眾發ticket取得二維碼圖並發微信素材獲得media_id..求PHP代碼

private function receiveEvent($object)
{
$contentStr = "";
switch ($object->Event)
{
case "subscribe":
$contentStr = "歡迎 ";
if (isset($object->EventKey)){
$contentStr = "關注二維碼場景 ".$object->EventKey;
}
break;
case "SCAN":
$contentStr = "掃描 ".$object->EventKey;
//要實現統計分析,則需要掃描事件寫入資料庫,這里可以記錄 EventKey及用戶OpenID,掃描時間
break;
default:
break;

}
$resultStr = $this->transmitText($object, $contentStr);
return $resultStr;

Ⅳ PHP 微信上傳永久素材

http請求方式: POST/FORM
http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE
調用示例(使用curl命令,用FORM表單方式上傳一個多媒體文件):
curl -F [email protected] "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE"

你這種情況屬於使用curl命令的方式傳值,幫助文檔:http://linux.51yip.com/search/curl

正確情況下的返回JSON數據包結果如下:{"type":"TYPE","media_id":"MEDIA_ID","created_at":123456789}
錯誤情況下的返回JSON數據包示例如下(示例為無效媒體類型錯誤):{"errcode":40004,"errmsg":"invalid media type"}
另外全局返回碼說明:https://mp.weixin.qq.com/wiki/17/.html

Ⅳ php怎麼模擬GET與POST向微信介面提交及獲取數據的方法

用curl

GET方法:

//初始化
$ch=curl_init();
//設置選項,包括URL
curl_setopt($ch,CURLOPT_URL,"http://www..com");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_HEADER,0);
//執行並獲取HTML文檔內容
$output=curl_exec($ch);
//釋放curl句柄
curl_close($ch);
//列印獲得的數據
print_r($output);

POST方法:

$url="http://localhost/web_services.php";
$post_data=array("username"=>"bob","key"=>"12345");
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
//post數據
curl_setopt($ch,CURLOPT_POST,1);
//post的變數
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);
$output=curl_exec($ch);
curl_close($ch);
//列印獲得的數據
print_r($output);

Ⅵ php使用curl 上傳微信公共平台素材文件

你是認證公眾號嗎?否則無許可權的。

另外你可以用
公眾平台介面調試工具
看看

Ⅶ php如何採集微信文章的同時獲取其中圖片的地址並下載本地化

給個簡單的例子,僅僅是獲取了遠程圖片哦

<?php
$url='';這是你的微信網址
$con=file_get_contents("$url");
$pattern="/<[img|IMG].*?src=['|"](.*?(?:[.gif|.jpg|.png]))['|"].*?[/]?>/";
preg_match_all($pattern,$con,$match);
for($i=0;$<count($match[1]);$i++){
$pic=file_get_content($match[1][$i]);
$name_arr=explode('/',$pic);
$n=count($name_arr);
file_put_content($name_arr[$n],$pic);
}

沒做測試,你測試一下吧

Ⅷ ueditor 中php讀取的微信公眾平台的圖片,勾選之後怎麼樣放入編輯框內

<?php
echo ' web-root = '.$_SERVER['DOCUMENT_ROOT'].'<br>';
echo ' current-file = '.__FILE__.'<br>';
echo ' current-dir = '.dirname(__FILE__).'<br>';

echo ' http-root = '.$_SERVER['HTTP_HOST'].'<br>';
echo ' web-position = '.$_SERVER['PHP_SELF'].'<br>';

$file='c:/webroot/index.php';
echo ' file-position = '.$file.'<br>';

$fileWebAddress='http://'.str_replace($_SERVER['DOCUMENT_ROOT'],$_SERVER['HTTP_HOST'],$file);
echo ' file-web-position = '.$fileWebAddress.'<br>';

?>

Ⅸ php微信上傳永久圖片素材求代碼

您好,這樣的:
//素材
const MEDIA_FOREVER_UPLOAD_URL = '/material/add_material?';
const MEDIA_FOREVER_NEWS_UPLOAD_URL = '/material/add_news?';
const MEDIA_FOREVER_NEWS_UPDATE_URL = '/material/update_news?';
const MEDIA_FOREVER_GET_URL = '/material/get_material?';
const MEDIA_FOREVER_DEL_URL = '/material/del_material?';
const MEDIA_FOREVER_COUNT_URL = '/material/get_materialcount?';
const MEDIA_FOREVER_BATCHGET_URL = '/material/batchget_material?';

/**
* 上傳臨時素材,有效期為3天(認證後的訂閱號可用)
* 注意:上傳大文件時可能需要先調用 set_time_limit(0) 避免超時
* 注意:數組的鍵值任意,但文件名前必須加@,使用單引號以避免本地路徑斜杠被轉義
* 注意:臨時素材的media_id是可復用的!
* @param array $data {"media":'@Path\filename.jpg'}
* @param type 類型:圖片:image 語音:voice 視頻:video 縮略圖:thumb
* @return boolean|array
*/
public function uploadMedia($data, $type){
if (!$this->access_token && !$this->checkAuth()) return false;
//原先的上傳多媒體文件介面使用 self::UPLOAD_MEDIA_URL 前綴
$result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_UPLOAD_URL.'access_token='.$this->access_token.'&type='.$type,$data,true);
if ($result)
{
$json = json_decode($result,true);
if (!$json || !empty($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
return $json;
}
return false;
}

/**
* 獲取臨時素材(認證後的訂閱號可用)
* @param string $media_id 媒體文件id
* @param boolean $is_video 是否為視頻文件,默認為否
* @return raw data
*/
public function getMedia($media_id,$is_video=false){
if (!$this->access_token && !$this->checkAuth()) return false;
//原先的上傳多媒體文件介面使用 self::UPLOAD_MEDIA_URL 前綴
//如果要獲取的素材是視頻文件時,不能使用https協議,必須更換成http協議
$url_prefix = $is_video?str_replace('https','http',self::API_URL_PREFIX):self::API_URL_PREFIX;
$result = $this->http_get($url_prefix.self::MEDIA_GET_URL.'access_token='.$this->access_token.'&media_id='.$media_id);
if ($result)
{
if (is_string($result)) {
$json = json_decode($result,true);
if (isset($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
}
return $result;
}
return false;
}

/**
* 上傳永久素材(認證後的訂閱號可用)
* 新增的永久素材也可以在公眾平台官網素材管理模塊中看到
* 注意:上傳大文件時可能需要先調用 set_time_limit(0) 避免超時
* 注意:數組的鍵值任意,但文件名前必須加@,使用單引號以避免本地路徑斜杠被轉義
* @param array $data {"media":'@Path\filename.jpg'}
* @param type 類型:圖片:image 語音:voice 視頻:video 縮略圖:thumb
* @param boolean $is_video 是否為視頻文件,默認為否
* @param array $video_info 視頻信息數組,非視頻素材不需要提供 array('title'=>'視頻標題','introction'=>'描述')
* @return boolean|array
*/
public function uploadForeverMedia($data, $type,$is_video=false,$video_info=array()){
if (!$this->access_token && !$this->checkAuth()) return false;
//#TODO 暫不確定此介面是否需要讓視頻文件走http協議
//如果要獲取的素材是視頻文件時,不能使用https協議,必須更換成http協議
//$url_prefix = $is_video?str_replace('https','http',self::API_URL_PREFIX):self::API_URL_PREFIX;
//當上傳視頻文件時,附加視頻文件信息
if ($is_video) $data['description'] = self::json_encode($video_info);
$result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_UPLOAD_URL.'access_token='.$this->access_token.'&type='.$type,$data,true);
if ($result)
{
$json = json_decode($result,true);
if (!$json || !empty($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
return $json;
}
return false;
}

/**
* 上傳永久圖文素材(認證後的訂閱號可用)
* 新增的永久素材也可以在公眾平台官網素材管理模塊中看到
* @param array $data 消息結構{"articles":[{...}]}
* @return boolean|array
*/
public function uploadForeverArticles($data){
if (!$this->access_token && !$this->checkAuth()) return false;
$result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_NEWS_UPLOAD_URL.'access_token='.$this->access_token,self::json_encode($data));
if ($result)
{
$json = json_decode($result,true);
if (!$json || !empty($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
return $json;
}
return false;
}

/**
* 修改永久圖文素材(認證後的訂閱號可用)
* 永久素材也可以在公眾平台官網素材管理模塊中看到
* @param string $media_id 圖文素材id
* @param array $data 消息結構{"articles":[{...}]}
* @param int $index 更新的文章在圖文素材的位置,第一篇為0,僅多圖文使用
* @return boolean|array
*/
public function updateForeverArticles($media_id,$data,$index=0){
if (!$this->access_token && !$this->checkAuth()) return false;
if (!isset($data['media_id'])) $data['media_id'] = $media_id;
if (!isset($data['index'])) $data['index'] = $index;
$result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_NEWS_UPDATE_URL.'access_token='.$this->access_token,self::json_encode($data));
if ($result)
{
$json = json_decode($result,true);
if (!$json || !empty($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
return $json;
}
return false;
}

/**
* 獲取永久素材(認證後的訂閱號可用)
* 返回圖文消息數組或二進制數據,失敗返回false
* @param string $media_id 媒體文件id
* @param boolean $is_video 是否為視頻文件,默認為否
* @return boolean|array|raw data
*/
public function getForeverMedia($media_id,$is_video=false){
if (!$this->access_token && !$this->checkAuth()) return false;
$data = array('media_id' => $media_id);
//#TODO 暫不確定此介面是否需要讓視頻文件走http協議
//如果要獲取的素材是視頻文件時,不能使用https協議,必須更換成http協議
//$url_prefix = $is_video?str_replace('https','http',self::API_URL_PREFIX):self::API_URL_PREFIX;
$result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_GET_URL.'access_token='.$this->access_token,self::json_encode($data));
if ($result)
{
if (is_string($result)) {
$json = json_decode($result,true);
if (isset($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
return $json;
}
return $result;
}
return false;
}

/**
* 刪除永久素材(認證後的訂閱號可用)
* @param string $media_id 媒體文件id
* @return boolean
*/
public function delForeverMedia($media_id){
if (!$this->access_token && !$this->checkAuth()) return false;
$data = array('media_id' => $media_id);
$result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_DEL_URL.'access_token='.$this->access_token,self::json_encode($data));
if ($result)
{
$json = json_decode($result,true);
if (!$json || !empty($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
return true;
}
return false;
}

/**
* 獲取永久素材列表(認證後的訂閱號可用)
* @param string $type 素材的類型,圖片(image)、視頻(video)、語音 (voice)、圖文(news)
* @param int $offset 全部素材的偏移位置,0表示從第一個素材
* @param int $count 返回素材的數量,取值在1到20之間
* @return boolean|array
* 返回數組格式:
* array(
* 'total_count'=>0, //該類型的素材的總數
* 'item_count'=>0, //本次調用獲取的素材的數量
* 'item'=>array() //素材列表數組,內容定義請參考官方文檔
* )
*/
public function getForeverList($type,$offset,$count){
if (!$this->access_token && !$this->checkAuth()) return false;
$data = array(
'type' => $type,
'offset' => $offset,
'count' => $count,
);
$result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_BATCHGET_URL.'access_token='.$this->access_token,self::json_encode($data));
if ($result)
{
$json = json_decode($result,true);
if (isset($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
return $json;
}
return false;
}

/**
* 獲取永久素材總數(認證後的訂閱號可用)
* @return boolean|array
* 返回數組格式:
* array(
* 'voice_count'=>0, //語音總數量
* 'video_count'=>0, //視頻總數量
* 'image_count'=>0, //圖片總數量
* 'news_count'=>0 //圖文總數量
* )
*/
public function getForeverCount(){
if (!$this->access_token && !$this->checkAuth()) return false;
$result = $this->http_get(self::API_URL_PREFIX.self::MEDIA_FOREVER_COUNT_URL.'access_token='.$this->access_token);
if ($result)
{
$json = json_decode($result,true);
if (isset($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
return $json;
}
return false;
}

Ⅹ 請問未認證的微信訂閱號用php怎樣上傳圖文素材,素材管理介面需要微信認證後才能獲得。

素材管理不需要認證即可使用、
A消息素材
B圖片素材
C語音視頻素材

閱讀全文

與php獲取微信素材相關的資料

熱點內容
手機號碼如何加密 瀏覽:424
沈陽程序員培訓學校 瀏覽:538
一般伺服器如何配置 瀏覽:895
圖片怎樣加密發郵件 瀏覽:619
萬虹電腦文件夾密碼忘記了怎麼辦 瀏覽:631
rc108單片機 瀏覽:867
戰雷如何改變伺服器 瀏覽:674
mactelnet命令 瀏覽:51
壓縮袋壓縮了拿出來 瀏覽:401
安卓手機相機怎麼設置許可權 瀏覽:121
美女程序員轉行做主播 瀏覽:671
辦理解壓房產 瀏覽:575
道路工程概論pdf 瀏覽:388
超棒數學速演算法大全 瀏覽:937
小米易語言登錄源碼 瀏覽:31
磚牆內加密鋼筋 瀏覽:992
鄉關何處pdf 瀏覽:84
小豬領贊小程序源碼 瀏覽:336
python曲線如何原路返回 瀏覽:431
pdf快速看圖破解版 瀏覽:294