WeChat keyword Auto-reply code

Source: Internet
Author: User
Tags cdata
/** WeChat php Test*///define your Tokendefine ("TOKEN", "Weixin"); $wechatObj =new wechatcallbackapitest (); $WECHATOBJ-& Gt;valid (); $wechatObj->responsemsg (); class Wechatcallbackapitest{public function valid () {$echoStr = $_get[' Echostr '];//valid signature, optionif ($this->checksignature ()) {echo $echoStr; exit;}} Public Function responsemsg () {//get post data, May is 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; $tpUsername = $postObj->tousername; $keyword =trim ($ postobj->content); $time =time (); $TEXTTPL = "
 
   
    
    %s 0 
    %s 
 
    
    %s 
 
    
    %s 
 
    
    %s 
 
    
 
 
 
 
 
 

  
 "If (!empty ($keyword)) {$msgType =" text "; $contentStr =" 1 Phone mailbox 2.QQ Information 3 address information "; if ($keyword = =" 1 ") {//keyword 1 o'clock reply $contentstr = "Tel: 15057190640 email:2323178881@qq.com!";} if ($keyword = = "2") {//Keyword 2 o'clock reply $contentstr = "My QQ is 2323178881!";} if ($keyword = = "3") {//Keyword 3 o'clock reply $contentstr = "Zha nong Kou Jie Dao, Jianggan District, Hangzhou city, Zhejiang province";} $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;}}}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the keyword Auto-response code, including the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.