欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

关于微信开发模式的PHP代码,该怎么解决

程序员文章站 2022-06-06 20:17:58
...
关于微信开发模式的PHP代码
/**
* wechat php test
*/

//define your token
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
//$wechatObj->valid();
$wechatObj->responseMsg();
class wechatCallbackapiTest
{
public function valid()
{
$echoStr = $_GET["echostr"];

//valid signature , option
if($this->checkSignature()){
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;
$type =$postObj->MsgType;
$customevent = $postObj->Event;
$latitude =$postObj->Location_X;
$longitude =$postObj->Location_Y;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "


%s


0
";
switch($type)
{
case "event";
if($customevent == "subscribe")
{$contentStr = "感谢关注"}
break;
case "image"
$contentStr ="图片很棒";
break;
case "location";
$contentStr ="{$latitude},{longitude}";
break;
case "text";
switch($keyword)
{case "1"
$contentStr="1"
break;
case "2"
$contentStr ="2"
break;
default;
$contentStr= "hi";}
break;
}
$msgType = "text";
$resultStr = sprintf($textTpl,$fromUsername,$toUsername,$time,$msgType,$contentStr);
echo $resultStr;
}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);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );

if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
}

?>

代码检查了N遍但是功能一个都不能实现 !球大神帮帮~另外怎么也做不出来微信调用百度地图来实现导航如果能一起帮助就更好了
------解决方案--------------------
public function valid()
{
$echoStr = $_GET["echostr"];

//valid signature , option
if($this->checkSignature()){
echo $echoStr;
exit;
}
}
这代码是为了填写url 通过验证, 通过之后 ,可以把这个代码改了。如改成
public function valid()
{
关于微信开发模式的PHP代码,该怎么解决

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频