现在微信公众号很火,基本是个网站都会再运营一个公众号,因此我们用DEDECMS建站也需要与时俱进对接进入公众号功能,在公众号发布文章,提高用户粘度
-
把以下代码保存为winxin.php放到dede程序的plus目录下.
代码如下
| |
define("TOKEN", "weixin"); |
| |
require_once(dirname(__FILE__)."/..//common.inc.php"); |
| |
$dsql = new DedeSql(false); |
| |
$wechatObj = new wechatCallback(); |
| |
private $articleCount = 0; |
| |
$echoStr = $_GET["echostr"]; |
| |
//valid signature , option |
| |
if($this->checkSignature()){ |
| |
public function responseMsg() |
| |
//get post data, May be due to the different environments |
| |
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; |
| |
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); |
| |
$fromUsername = $postObj->FromUserName; |
| |
$toUsername = $postObj->ToUserName; |
| |
$this->keyword = strtolower(trim(("UTF-8","gb2312",$postObj->Content))); |
| |
if($this->keyword == 'hi' || $this->keyword == '您好' || $this->keyword == '你好' ||$this->keyword == 'hello2bizuser' ){ |
| |
$contentStr = "输入关键字开始搜索!";//自定义欢迎回复; |
| |
echo sprintf($textTpl, $contentStr); |
| |
}else if( !empty( $this->keyword )){ |
| |
if($this->articleCount == 0){ |
| |
$contentStr = "抱歉,没有找到与【{$this->keyword}】相关的文章,要不你更换一下关键字,可能就有结果了哦 :-) "; |
| |
echo sprintf($textTpl, $contentStr); |
| |
echo sprintf($picTpl,$this->articleCount,$this->items); |
| |
private function search(){ |
| |
$weixin_posts = $dsql->SetQuery("Select * From `dede_archives` where title like '%".$this->keyword."%' order by id desc LIMIT 0, 5"); |
| |
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); |
| |
if($this->articleCount > 5) $this->articleCount = 5; |
| |
private function get_item($title, $description, $picUrl, $url){ |
| |
if(!$description) $description = $title; |
| |
'.$_SERVER['HTTP_HOST'].$picUrl.']]> |
| |
'.$_SERVER['HTTP_HOST'].$url.']]> |
| |
private function checkSignature() |
| |
$signature = $_GET["signature"]; |
| |
$timestamp = $_GET["timestamp"]; |
| |
$tmpArr = array($token, $timestamp, $nonce); |
| |
$tmpStr = implode( $tmpArr ); |
| |
$tmpStr = sha1( $tmpStr ); |
| |
if( $tmpStr == $signature ){ |
|
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《dedecms织梦增加微信公众号平台发布插件的教程》
文章链接:
https://www.ibytx.com/708.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。