dedecms增加微信公众号平台发布插件

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

  1. 把以下代码保存为winxin.PHP放到dede程序的plus目录下.

代码如下   

PHP
 
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 = "%s]]>%s
                             搜索!";//自定义欢迎回复;
                 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
        '
        discription>discription>
            
			

相关文章

网页授权获取用户信息的方法
报错config:invalid signature的解决方案
微信开发百思不得姐实战教程
详解微信开发input输入框
教你libco是如何支撑巨大数据信息量的
微信二次开发之文本消息请求与发送