搜索
您的当前位置:首页易信公众平台demo代码php(含验证接口)

易信公众平台demo代码php(含验证接口)

来源:智榕旅游
//易信公众平台地址https://plus.yixin.im/login,复制后后缀改为.php define(\"TOKEN\

$wechatObj = new wechatCallbackapiTest(); if (isset($_GET['echostr'])) { $wechatObj->valid(); }else{

$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 = \"感谢你的关注\\n回复1查看账号简介\\n回复2查看联系方式\\n回复3查看法律文书\";} break; case \"image\"; $contentStr = \"你的图片很棒!\"; break; case \"location\"; $contentStr = \"你的纬度是{$latitude},经度是{$longitude},我已经锁定!\"; break; case \"text\"; switch($keyword) {

case \"1\"; $contentStr = \"易伟律师,擅长交通事故、保险纠纷、医疗损害\"; break; case \"2\"; $contentStr = \"联系方式:汕头市金平区华乾大厦703,1341702551,email:30090032@qq.com。\"; break; case \"3\"; $contentStr = \"31离婚协议\\n32租房合同\\n33交通事故协议书\"; break; default; $contentStr =\"hi\"; } break; default; $contentStr =\"此项功能尚未开发\"; } $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); $tmpStr = implode( $tmpArr ); $tmpStr = sha1( $tmpStr ); if( $tmpStr == $signature ){ return true; }else{ return false; } } } ?>

因篇幅问题不能全部显示,请点此查看更多更全内容

Top