Message Interface development on WeChat public platform

Source: Internet
Author: User
Yesterday, the message interface of the public platform was connected to a blog, which enables users to display messages directly in the blog when sending messages to the public account. Yesterday, the message interface of the public platform was connected to a blog, which enables users to display messages directly in the blog when sending messages to the public account.

In fact, the development of the Message Interface function of the public platform can achieve many functions. this is just a very simple application, such as inputting specific characters in many public accounts to return the corresponding data, querying weather, and translating Chinese and English.

Next I will post the PHP SDK provided by the public platform:


 valid(); 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 dataif (!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 ))                {              $msgType = "text";                $contentStr = "Welcome to wechat world!";                $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);                echo $resultStr;                }else{                echo "Input something...";                }         }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;}}} ?>

Specific can view the public platform Message Interface Guide: http://mp.weixin.qq.com/wiki/index.php? Title = % E6 % B6 % 88% E6 % 81% AF % E6 % 8E % A5 % E5 % 8F % A3 % E6 % 8C % 87% E5 % 8D % 97

This SDK provides two simple operations: public platform information submission and verification, and user message reply. we can implement different requirements based on different message interfaces provided in the interface guide.

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.