Because the link to change the URL has changed,Dedecms to wordpress detailed version, success version, classic version
Some time ago, I started dedecms, and the Weixin Official Accounts was so popular that I wanted to integrate it. Baidu searched for a lot of tutorials, and they were all about the same. The result was that it didn't work after using it. After replying to keywords in the public account, it was garbled, garbled, garbled. Some tutorial codes were posted and did not reply directly. No matter how you sent them, they would not reply to you. It's a pain. Here, I post the code that was successfully tested in 18 years. As for how to register the Weixin Official Accounts, I won't post it and I won't post it on my own. Just save the code as weixin.php and put it in plus
<?php define("TOKEN", "你的token名字"); 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 = trim($postObj->Content);
$time = time();
$textTpl = "
重要第一点
$this->keyword = trim($postObj->Content);这段代码解决的乱码问题。我的是 utf-8 版本的。
重要第二点
sort($tmpArr, SORT_STRING);
这段代码是解决的有时收到信息有时收不到信息,这个在 14 年的时候微信升级,对排序算法进行了修改,原有的 sort($tmpArr)修改为 sort($tmpArr, SORT_STRING),网上教程都说 14 年之前没升级的教程,所以很多朋友用了后有时收到信息有时收不到信息。
重要第三点
$link = ‘/m/view.php?aid=’.$weixin_post->id;
如果在微信里打开,肯定打开的是手机版,所以如果你的手机版是在更目录下的 m 文件夹就要如上填写,这个跳转到手机版根据不同的情况修改。