Examples of WeChat official account development and public development

Source: Internet
Author: User

Public ID development instance and public development instance

The Index. PHP file below is an example of a public number written based on PHP 5.6.30.

The Code is as follows:

 Valid ();} else {$ wechatObj-> responseMsg ();} class wechatCallbackapiTest {public function valid () {$ echoStr = $ _ GET ["echostr"]; if ($ this-> checkSignature () {header ('content-type: text'); echo $ echoStr; exit ;}} private function checkSignature () {$ signature = $ _ GET ["signature"]; $ timestamp = $ _ GET ["timestamp"]; $ nonce = $ _ GET ["nonce"]; $ token = TOKEN; $ tmpArr = array ($ token, $ timestamp, $ nonce); sort ($ TmpArr, SORT_STRING); $ tmpStr = implode ($ tmpArr); $ tmpStr = sha1 ($ tmpStr); if ($ tmpStr = $ signature) {return true ;} else {return false ;}} public function responseMsg () {// $ HTTP_RAW_POST_DATA is about to be canceled (already) in the release instructions of php in high version. Please switch to php: // declaration read from input // $ postStr = $ GLOBALS ["HTTP_RAW_POST_DATA"]; $ postStr = file_get_contents ('php: // input'); 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
                          
  
   
                          
  
   
                          
  
   
0
                          
 "; If ($ keyword = "? "| $ Keyword = "? ") {$ MsgType =" text "; // set the time zone date_default_timezone_set (" Asia/Shanghai "); $ contentStr = date (" Y-m-d H: I: s ", time (); $ resultStr = sprintf ($ textTpl, $ fromUsername, $ toUsername, $ time, $ msgType, $ contentStr); echo $ resultStr ;}} else {echo ""; exit ;}}}

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.