PHP micro-Credit Development platform development Small test

Source: Internet
Author: User
Tags define exit cdata empty php code return valid
The open platform of micro-letters and accompanying micro-letters has recently been a fire. Always want to do a micro-letter platform to try, recently had a good idea, want to realize it as soon as possible, but the micro-letter does not need any UI and so on the design, just to show the logic out. In fact, micro-trust public platform, if only as a platform for publishing information, that is, "edit mode" is actually no need to knock code. Only in developer mode, developers need to design a certain logic and code to achieve specific functions, and then say the start of development:   1. Development of micro-credit public platform must first have server resources, of course, the editing mode does not count. The so-called editorial model is the kind of simple public account that pushes a message every day. Server resources All kinds of cloud servers are available, recommended bae/sae/nuts/Ali, and so on, each has its advantages, and because of competition? There will be some free resources to give away, to practice practicing is enough. A. Apply for BAE account, create the application, if it is the test words to the micro-trust public platform to download the test PHP code, just change the token to their own token can. For example, the following PHP test code, the logic of the code is very clear, that is, a verification process, can also define a part of the logical operation. Upload this file and create your own application version 1:    
<?php/** * WeChat PHP Test///define Your token ("define", "token"); the Weixin of your micro-credit public platform is token $WEC  
Hatobj = new Wechatcallbackapitest ();  
$WECHATOBJ->valid ();  
Class Wechatcallbackapitest {public function valid () {$echoStr = $_get["Echostr"];  
Valid signature, option if ($this->checksignature ()) {echo $echoStr;  
Exit The Public Function responsemsg () {//get post data, May is due to the different environments $postStr = $GLOBAL  
s["Http_raw_post_data"]; Extract post Data if (!empty ($POSTSTR)) {$POSTOBJ = simplexml_load_string ($postStr, ' simplexmlelement ', LIBXML_NOCDA  
TA);  
$fromUsername = $POSTOBJ->fromusername;  
$toUsername = $POSTOBJ->tousername;  
$keyword = Trim ($postObj->content);  
$time = time (); $TEXTTPL = "<xml> <tousername><! [cdata[%s]]></tousername> <fromusername><! [cdata[%s]]></fromusername> <CreateTime>%s</CreateTime> <msgtype> <! [cdata[%s]]></msgtype> <content><!  
[cdata[%s]]></content> <FuncFlag>0</FuncFlag> </xml> "; if (!empty ($keyword)) {$msgType = "text"; PS: ^_^ Good PHP Learning Exchange Group: 276167802, Validation: CSL, if you are interested can join in the discussion) $contentStr = "Welc  
ome to WeChat world! ";  
$RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $CONTENTSTR);  
Echo $resultStr;  
}else{echo "Input something ...";  
}}else {echo "";  
Exit  
The 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;  
 }}}?>


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.