本篇文章主要讲述了如何对微信公众号进行基本的配置,具有一定的参考价值,想要搭建微信公众号的朋友可以了解一下,希望对你有所帮助。
这个是微信公众平台上的配置。
这边的url值要直接点到文件上,不然不会成功.
然后后台的设置
<?phpnamespace app\weixin\controller;use think\controller;define("token", "******");//这里要输入你的token值// $wechatobj = new wechatcallbackapitest();// $wechatobj->valid();class wx2 extends controller { public function index() { $echostr = $_get["echostr"]; //valid signature , option if($this->checksignature()){ ob_clean(); //丢弃缓存中的内容 echo $echostr; 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; $keyword = trim($postobj->content); $time = time(); $texttpl = "<xml> <tousername><![cdata[%s]]></tousername> <fromusername><![cdata[%s]]></fromusername> <createtime>%s</createtime> <msgtype><![cdata[%s]]></msgtype> <content><![cdata[%s]]></content> <funcflag>0</funcflag> </xml>"; if(!empty( $keyword )) { $msgtype = "text"; $contentstr = "welcome to wechat world!"; $resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr); echo $resultstr; }else{ echo "input something..."; } }else { echo ""; exit; } } private function checksignature() { $signature = $_get["signature"]; $timestamp = $_get["timestamp"]; $nonce = $_get["nonce"]; $token = token; $tmparr = array($token, $timestamp, $nonce); sort($tmparr,sort_string); 72 $tmpstr = implode( $tmparr ); $tmpstr = sha1( $tmpstr ); if( $tmpstr == $signature ){ return true; }else{ return false; } }}
相关教程:微信公众平台开发视频教程
以上就是如何对微信公众号基本配置的详细内容。