valid();$wechatobj->responsemsg(); function youdaofanyi($keyword){ $url = 'http://fanyi.youdao.com/openapi.do?keyfrom=coolrand&key=545706258&type=data&doctype=json&version=1.1&q='.$keyword; $f = new saefetchurl(); $output = $f->fetch($url); $message = json_decode($output,true); $errorcode = $message['errorcode']; $phonetic = $message['basic']['$phonetic']; $explains1 = $message['basic']['explains']['0']; $explains2 = $message['basic']['explains']['1']; $explains3 = $message['basic']['explains']['2']; $trans = $message['translation'][0]; return 哈哈.\n.$trans.\n.$phonetic.\n.$explains1;}class wechatcallbackapitest{ public function valid() { $echostr = $_get[echostr]; if($this->checksignature()){ echo $echostr; exit; } } public function responsemsg() { $poststr = $globals[http_raw_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 = %s0; if(!empty( $keyword )) { if((eregi(a,$keyword))){ $msgtype = text; $contentstr = youdaofanyi($keyword); $resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr); echo $resultstr; } else{ $msgtype = text; $contentstr = 欢迎; $resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr); echo $resultstr; } }else{ echo asd; } }else { echo mess; 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; } }} ?>
代码如上,可是回复中的中文会显示乱码,到底出什么问题了啊
这个问题已被关闭,原因:
回复内容: valid();$wechatobj->responsemsg(); function youdaofanyi($keyword){ $url = 'http://fanyi.youdao.com/openapi.do?keyfrom=coolrand&key=545706258&type=data&doctype=json&version=1.1&q='.$keyword; $f = new saefetchurl(); $output = $f->fetch($url); $message = json_decode($output,true); $errorcode = $message['errorcode']; $phonetic = $message['basic']['$phonetic']; $explains1 = $message['basic']['explains']['0']; $explains2 = $message['basic']['explains']['1']; $explains3 = $message['basic']['explains']['2']; $trans = $message['translation'][0]; return 哈哈.\n.$trans.\n.$phonetic.\n.$explains1;}class wechatcallbackapitest{ public function valid() { $echostr = $_get[echostr]; if($this->checksignature()){ echo $echostr; exit; } } public function responsemsg() { $poststr = $globals[http_raw_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 = %s0; if(!empty( $keyword )) { if((eregi(a,$keyword))){ $msgtype = text; $contentstr = youdaofanyi($keyword); $resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr); echo $resultstr; } else{ $msgtype = text; $contentstr = 欢迎; $resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr); echo $resultstr; } }else{ echo asd; } }else { echo mess; 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; } }} ?>
代码如上,可是回复中的中文会显示乱码,到底出什么问题了啊