花魁直播高品质美女在线视频互动社区 - 花魁直播官方版

 歡迎來到素材無憂網(wǎng),按 + 收藏我們
登錄 注冊 退出 找回密碼

dedecms織夢增加微信公眾號平臺發(fā)布插件的教程

時間: 2018-11-30 10:13 閱讀: 作者:素材無憂網(wǎng)

現(xiàn)在微信公眾號很火,基本是個網(wǎng)站都會再運營一個公眾號,因此我們用DEDECMS建站也需要與時俱進(jìn)對接進(jìn)入公眾號功能,在公眾號發(fā)布文章,提高用戶粘度

  1. 把以下代碼保存為winxin.php放到dede程序的plus目錄下.

代碼如下

查看源碼   打印代碼幫助
   
 
 
define("TOKEN", "weixin");

require_once(dirname(__FILE__)."/..//common.inc.php");

$dsql = new DedeSql(false);

$wechatObj = new wechatCallback();

$wechatObj->valid();



class wechatCallback

{

private $items = '';

private $articleCount = 0;

private $key = '';



public function valid()

{

$echoStr = $_GET["echostr"];



//valid signature , option

if($this->checkSignature()){

echo $echoStr;

$this->responseMsg();



exit;

}

}



public function responseMsg()

{

//get post data, May be due to the different environments

$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];



//extract post data

if (!empty($postStr)){



$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);

$fromUsername = $postObj->FromUserName;

$toUsername = $postObj->ToUserName;

$this->keyword = strtolower(trim(("UTF-8","gb2312",$postObj->Content)));



$time = time();

$textTpl = "

".$fromUsername."]]>

".$toUsername."]]>

".$time."



0

";

$picTpl = "

".$fromUsername."]]>

".$toUsername."]]>

".$time."



%d


%s



1

";

if($this->keyword == 'hi' || $this->keyword == '您好' || $this->keyword == '你好' ||$this->keyword == 'hello2bizuser' ){

$contentStr = "輸入關(guān)鍵字開始搜索!";//自定義歡迎回復(fù);

echo sprintf($textTpl, $contentStr);

}else if( !empty( $this->keyword )){

$this->search();

if($this->articleCount == 0){

$contentStr = "抱歉,沒有找到與【{$this->keyword}】相關(guān)的文章,要不你更換一下關(guān)鍵字,可能就有結(jié)果了哦 :-) ";

echo sprintf($textTpl, $contentStr);

}else{

echo sprintf($picTpl,$this->articleCount,$this->items);

}

}



}else {

echo "";

exit;

}

}



private function search(){

global $dsql;

$weixin_posts = $dsql->SetQuery("Select * From `dede_archives` where title like '%".$this->keyword."%' order by id desc LIMIT 0, 5");

$items = '';

$dsql->Execute();



while($weixin_post=$dsql->GetObject()){

$title =$weixin_post->title;

$excerpt = $weixin_post->description ;//獲取摘要

$thumb = $weixin_post->litpic ;//獲取;

$link = '/plus/view.php?aid='.$weixin_post->id;

$items = $items . $this->get_item($title, $excerpt, $thumb, $link);

$this->articleCount++;

}

if($this->articleCount > 5) $this->articleCount = 5;



$this->items = $items;

}



private function get_item($title, $description, $picUrl, $url){

if(!$description) $description = $title;



return

'




'.$description.']]>

'.$_SERVER['HTTP_HOST'].$picUrl.']]>

'.$_SERVER['HTTP_HOST'].$url.']]>



';

}



private function checkSignature()

{

$signature = $_GET["signature"];

$timestamp = $_GET["timestamp"];

$nonce = $_GET["nonce"];



$token = TOKEN;

$tmpArr = array($token, $timestamp, $nonce);

sort($tmpArr);

$tmpStr = implode( $tmpArr );

$tmpStr = sha1( $tmpStr );



if( $tmpStr == $signature ){

return true;

}else{

return false;

版權(quán)聲明: 本站資源均來自互聯(lián)網(wǎng)或會員發(fā)布,如果侵犯了您的權(quán)益請與我們聯(lián)系,我們將在24小時內(nèi)刪除!謝謝!

轉(zhuǎn)載請注明: dedecms織夢增加微信公眾號平臺發(fā)布插件的教程

標(biāo)簽:  
模板推薦