目前网上有很多这方面教程,关于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;
就可以大功告成了哈!为了懒人需求,把修改好的微信接口提供下载,大家可以直接点击下载哈。
新闻热点
疑难解答