星联网络专注帝国CMS二次功能插件开发-精品网站模板站长代码素材

  • 最近更新
  • 模板:33
  • 记录:12641|
  • 插件:52|
  • 工具:4|
  • 代码:8|
  • 评论:0

dedecms织梦增加微信公众号平台发布插件的教程

前言

本文主要讲解《dedecms织梦增加微信公众号平台发布插件的教程》的详细内容

现在微信公众号很火,基本是个网站都会再运营一个公众号,因此我们用DEDECMS建站也需要与时俱进对接进入公众号功能,在公众号发布文章,提高用户粘度

  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 = "输入关键字开始搜索!";//自定义欢迎回复;

echo sprintf($textTpl, $contentStr);

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

$this->search();

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

$contentStr = "抱歉,没有找到与【{$this->keyword}】相关的文章,要不你更换一下关键字,可能就有结果了哦 :-) ";

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;

本网刊登的文章均仅代表作者个人观点,并不代表本网立场。文中的论述和观点,敬请读者注意判断。

本文地址:http://www.xlkjgs.com/notes/web/10034.html

以上内容由本站整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!

星联网络

星联网络是中国最具实战的互联网创业者的知识服务商,这里有互联网行业动态,网络推广,SEO优化,SEM优化,ESC配置,行业经验分型,互联网项目,微信营销、淘宝客赚钱、新媒体营销、京东运营、跨境电商等众多互联网营销知识分享

站长运营站长必备网站运营之道才能长久发展