微信公众号url服务器在哪里,微信公众号url认证(服务器认证)
把下面的代碼復制
路由需指定到wx方法
namespace App\Http\Controllers\Wx;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class WxController extends Controller
{
public function Wx(){
//valid signature , option
if($this->checkSignature()){
$echoStr = $_GET["echostr"];
echo $echoStr;
exit;
}
}
public function responseMsg()
{
//get post data, May be due to the different environments
// $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
$postStr = file_get_contents("php://input");
//extract post data
if (!empty($postStr)){
/* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,
the best way is to check the validity of xml by yourself */
libxml_disable_entity_loader(true);
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$keyword = trim($postObj->Content);
$msgType=$postObj->MsgType;
$event=$postObj->Event; //接收事件類型
$time = time();
$textTpl = "
%s
0
";
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;
}
if($msgType=="event"){
if($event=="subscribe"){
$msgType = "text";
$contentStr = "Welcome to wechat world-----subscribe!";
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
header("Location:http://case.jujiaoweb.com/index/index/sub");
}
}
}
private function checkSignature(){
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = 'weixin2019';//服務器配置的令牌token
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
}
總結
以上是生活随笔為你收集整理的微信公众号url服务器在哪里,微信公众号url认证(服务器认证)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html设置数字显示位数,数字万用表的显
- 下一篇: python 数据库连接池_【转】Pyt