最新公告
  • 欢迎您光临牛气网,本站秉承“用心服务,做好服务”致力为站长提供优质的售后服务!立即加入我们
  • dedecms织梦增加微信公众号平台发布插件的教程

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

    把以下代码保存为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;

    1、本站所有资源皆来源于网络和用户自行上传,因此不包括售后和技术,敬请谅解!
    2、本站不保证所提供的源码的准确性、安全性和功能完善性,资源仅用于学习用!
    3、您下载的资源,请务必在24小时内删除,资源仅提供本地测试,请勿商用或者非法用途都与本站无关,一切后果自负!
    4、如发现资源下载不了,或者侵权请及时联系客服或者邮箱admin#niuqi.net,#改为@!
    牛气网 » dedecms织梦增加微信公众号平台发布插件的教程

    发表评论

    • 72会员总数(位)
    • 4096资源总数(个)
    • 0本周发布(个)
    • 0 今日发布(个)
    • 207稳定运行(天)

    牛气网NIUQI.NET站长源码平台

    开通SVIP会员 了解详情