最新活动:电脑PC端+手机端+微网站+自适应网页多模板选择-建站388元起价!!!
当前位置:主页 > 网站建设 > 让dedecms增加微信公众平台插件,dedecms

让dedecms增加微信公众平台插件,dedecms

时间:2023-07-19 12:07:19 阅读: 文章分类: 网站建设 作者: dede开发者

导读:dedecmsdedecms现在使用微信的朋友越来越多了,下面我来介绍怎么让dedecms增加微信公众平台吧,有需要的朋友可参考。dede织梦模板dede网站模板。

dede织梦模板dede网站模板放到dede程序的plus目录下即可.

接口配置信息 按下面说明填写, URL http://你的域名/plus/weixin.php Token weixin (和文件中保持一致)

代码如下

 代码如下

<?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 = "<xml>        <ToUserName><![CDATA[".$fromUsername."]]></ToUserName>        <FromUserName><![CDATA[".$toUsername."]]></FromUserName>        <CreateTime>".$time."</CreateTime>        <MsgType><![CDATA[text]]></MsgType>        <Content><![CDATA[%s]]></Content>        <FuncFlag>0</FuncFlag>        </xml>";                     $picTpl = "<xml>                              <ToUserName><![CDATA[".$fromUsername."]]></ToUserName>                              <FromUserName><![CDATA[".$toUsername."]]></FromUserName>                              <CreateTime>".$time."</CreateTime>                              <MsgType><![CDATA[news]]></MsgType>                              <Content><![CDATA[]]></Content>                              <ArticleCount>%d</ArticleCount>                              <Articles>                              %s                              </Articledede网站模板s>                              <FuncFlag>1</FuncFlag>                             </xml>";                 if($this->keyword == 'hi' || $this->keyword == '您好'  || $this->keyword == '你好' ||$this->keyword == 'hello2bizuser' ){                  $contentStr = "输入关键字开始搜索!";//自定义欢迎回复;                  echo sprintf($textTpl, $contentStr);                 }else if( !empty( $this->dede商城模板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         '         <item>             <Title><![CDATA['.$title.']]></Title>             <Discription><![CDATA['.$description.']]></Discription>             <PicUrl><![CDATA[http://'.$_SERVER['HTTP_HOST'].$picUrl.']]></PicUrl>             <Url><![CDATA[http://'.$_SERVER['HTTP_HOST'].$url.']]></Url>         </item>         ';     }       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{         &nbsdede后台模板p;   return false;         }     } }

关键词标签: dedecms 插件 公众

声明: 本文由我的SEOUC技术文章主页发布于:2023-07-19 ,文章让dedecms增加微信公众平台插件,dedecms主要讲述插件,公众,dedecms网站建设源码以及服务器配置搭建相关技术文章。转载请保留链接: https://www.seouc.com/article/web_31088.html

我的IDC 网站建设技术SEOUC.COM
专注网站建设,SEO优化,小程序设计制作搭建开发定制网站等,数千家网站定制开发案例,网站推广技术服务。
  • 5000+合作客服
  • 8年从业经验
  • 150+覆盖行业
  • 最新热门源码技术文章