PHP micro-letter scraping card with micro-letter Interface _php Example

Source: Internet
Author: User
Tags cdata rand sprintf

Whether a big turntable or a scraping card is a lottery, you can use the same method to calculate the probability of winning and the number of control prize pools, this article for you to share the PHP micro-letter Scraping card instance code, PHP micro-letter Scraping card + interface, can be directly invoked, with a micro-letter interface for everyone to learn.

Effect Chart:

prize.php

<?php $rand = rand (1,100); if ($rand <10) {$prize = ' Apple 1 ';} else if ($rand <30) {$prize = ' Apple 2 ';} else if ($rand <60) {$prize = ' Apple 3 ';}

else{$prize = ' Thank you for participating ';} ?> <! DOCTYPE html>  

sxxybbs_wx.php

<?php/** * WeChat PHP Test * *//define Your token ("define", "token");
$WECHATOBJ = new Wechatcallbackapitest ();
$WECHATOBJ->valid ();
$WECHATOBJ->responsemsg ();

 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 = $GLOBALS ["H

 Ttp_raw_post_data "]; Extract post Data if (!empty ($POSTSTR)) {$POSTOBJ = simplexml_load_string ($postStr, ' simplexmlelement ', Libxml_noc
 DATA);
  $fromUsername = $POSTOBJ->fromusername;
 $toUsername = $POSTOBJ->tousername;
 
 $time = time (); if ($postObj->content = = ' 1 ') {$textTpl = ' <xml> <tousername><![ Cdata[%s]]></tousername> <fromusername><! [cdata[%s]]></fromusername> <CreateTime>%s</CreateTime> <msgtype><! [CDATA[%S]]&GT;</msgtype> <content><! 
 [cdata[%s]]></content> <FuncFlag>0</FuncFlag> </xml> ";
 $msgType = ' text ';
 $CONTENTSTR = "One entered: 1";
   $RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $CONTENTSTR);
 
 Echo $resultStr; }else if ($postObj->content = = ' Draw ') {$newsTpl = "<xml> <tousername><![ Cdata[%s]]></tousername> <fromusername><! [cdata[%s]]></fromusername> <CreateTime>%s</CreateTime> <msgtype><! [cdata[news]]></msgtype> <ArticleCount>1</ArticleCount> <Articles> <item> <tit le><! [cdata[Scraping]]></title> <description><! [Cdata[I'm going to scratch the lottery! ]]></description> <picurl><! [cdata[http://special.sxcq.cn/cj/weixin/ggk/ggk.jpg]]></picurl> <url><! [cdata[%s]]></url> </item> </Articles> <FuncFlag>0</FuncFlag> &LT;/XML&Gt; ";
   $url = "http://2311156115.44c.pw/prize.php";
   $RESULTSTR = sprintf ($NEWSTPL, $fromUsername, $toUsername, $time, $url);
 
 Echo $resultStr;
  }else{$keyword = Trim ($postObj->content); $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";
   $CONTENTSTR = "Please enter: ' 1 ' or ' Draw '";
   $RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $CONTENTSTR);
  Echo $resultStr;
   }else{$msgType = "text"; $CONTENTSTR = "Thank you for your concern Sxxybbs blog, the following has wonderful content will be the first time sent to you!"
   Reply: ' 1 ' or ' lottery ' gets the corresponding service;
   $RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $CONTENTSTR);
  Echo $resultStr;
  }}}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;
 }}}?>

SOURCE Download: Scraping card

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.