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 ']; $explains 2 = $message [' Basic '] [' explains '] [' 1 ']; $explains 3 = $message [' Basic '] [' explains '] [' 2 ']; $trans = $message [' translation '][0];return "haha". " \ n ". $trans." \ n ". $phonetic." \ n ". $explains 1;} 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 = "
%s
%s
%s
%s
%s
0
"; 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 = "Welcome"; $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; }}}?>
Code as above, but the reply in Chinese will show garbled, what is the problem ah
This issue has been closed due to:
Reply content:
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 ']; $explains 2 = $message [' Basic '] [' explains '] [' 1 ']; $explains 3 = $message [' Basic '] [' explains '] [' 2 ']; $trans = $message [' translation '][0];return "haha". " \ n ". $trans." \ n ". $phonetic." \ n ". $explains 1;} 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 = "
%s
%s
%s
%s
%s
0
"; 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 = "Welcome"; $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; }}}?>
Code as above, but the reply in Chinese will show garbled, what is the problem ah