目前網上有很多這方面教程,關于dedecms微信插件,寫的很詳細,但是都是微信跳轉的是PC網頁,很難看,排版就亂了,今天南宮在這里介紹,如何跳轉到dedecms織夢自帶wap端,也就是跳到同內容的手機端。
微信公眾號越來越火,再不弄一個就out了,弄了微信公眾號但是沒弄公眾平臺的功能就更out了,所以我也來試了試
dedecms集成微信公眾平臺的教程有很多了,但是因為我dedecms是GBK版本,無法使用其他人給的教程,然后我就稍微改了下,不然就會亂碼.
我再重復下步驟:
1、將weixin.php上傳至/plus;
2、在微信公眾平臺注冊公眾賬號,注冊地址:
3、注冊后,點擊“高級功能”,有兩種模式,分別為:編輯模式和開發模式,
將“編輯模式”關閉,才能開啟“開發模式”,進入“開發模式”,或者開發者中心,接口配置信息里 URL :http://您的網址/plus/weixin.php
Token : weixin ,
如我網站的為:URL: / Token : weixin
備注:Token :可在weixin.php或者wxjk.php里更改,在define(“TOKEN”, “weixin”); 可改成你自己想要的。
然后啟動就好了.
里面有兩個文件,weixin.php是織夢版本為utf-8的 這個是我下載別人的
wxjk.php是織夢版本gbk的,修正了亂碼的問題
現在這個微信公眾號插件確實可以用,但是功能不全,今后我將在此開發新的功能,然后再分享給大家
這是我自媒體平臺的一個公眾號,歡迎大家關注,里面只分享干貨!
安裝dedecms微信插件效果:在線下載地址:鏈接: https://pan.baidu.com/s/1apdk95yaBXKNlokOh1WmlQ 密碼: 9mu4
安裝方法:放到dede程序的plus目錄下即可.(其實放在哪里都可以)
接口配置信息按下面說明填寫,
URL http://你的域名/plus/weixin.php
微信高級接口配置:Token weixin (和文件中保持一致)
以上都不是重點,重點是如何跳轉到dede自帶手機端,我們先看下微信接口文件。
<?php
define("TOKEN", "weixin");
require_once(dirname(__FILE__)."/../include/common.inc.php");
$dsql = new DedeSql(false);
$wechatObj = new wechatCallback();
$wechatObj->valid();
class wechatCallback
{
private $items = '';
private $articleCount = 0;
private $keyword = '';
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(iconv("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
</Articles>
<FuncFlag>1</FuncFlag>
</xml>";
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 `lanren_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{
return false;
}
}
}
在以上代碼,大家仔細看到。紅色地方,就是文章點擊后的跳轉鏈接,目前是鏈接PC端。
我們在看下官網這個兩個網址區別:
PC端:http://www.cuoXin.com/plus/view.php?aid=16565
wap端:http://www.cuoXin.com/wap.php?action=article&id=16565
通過上網網址對比,我們就知道,微信接口代碼該如何修改了。
$link = '/plus/view.php?aid='.$weixin_post->id;
改為
$link = '/wap.php?action=article&id='.$weixin_post->id;
就可以大功告成了哈!為了懶人需求,把修改好的微信接口提供下載,大家可以直接點擊下載哈。
新聞熱點
疑難解答