WeChat public Platform interface reply Chinese garbled

Source: Internet
Author: User
Tags cdata sha1
 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

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.