Code example of scratch card function for PHP development applet

Y2J
Release: 2017-05-13 16:06:10
Original
3134 people have browsed it

The most important and core thing about lottery draws such as WeChat Wheel and Scratch Card is how to set the probability of winning. This article combines the codes of multiple WeChat carousels and scratch cards on the Internet

Whether it is a carousel, a scratch card or a lottery, the same method can be used to calculate the probability of winning and control the prize pool. Quantity, this article shares with you the PHP WeChat scratch card example code, PHP WeChat scratch card +interface, which can be called directly and comes with a WeChat interface for everyone to learn.

Rendering:

##prize.php

<?php
$rand = rand(1,100);
if($rand<10){
 $prize = &#39;苹果1个&#39;;
}else if($rand<30){
 $prize = &#39;苹果2个&#39;;
}else if($rand<60){
 $prize = &#39;苹果3个&#39;;
}else{
 $prize = &#39;谢谢参与&#39;;
}

?>

<!DOCTYPE html>
<html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
 <meta name="apple-mobile-web-app-capable" content="yes">
 <meta name="apple-mobile-web-app-status-bar-style" content="black">
 <meta name="format-detection" content="telephone=no">
 <title>刮刮卡</title>
 <link href="index/activity-style.css" rel="stylesheet" type="text/css">
 </head>
 
 </head>
 <body data-role="page" class="activity-scratch-card-winning">
 <script src="index/jquery.js" type="text/javascript"></script>
 <script src="index/wScratchPad.js" type="text/javascript"></script>
 <p class="main">
 <p class="cover">
 <img src="index/activity-scratch-card-bannerbg.png"> 
 <p id="prize"><?php echo $prize;?></p>
  <p id="scratchpad"></p>  
 </p>
 
 <p class="boxcontent boxwhite">
 <p class="box">
 <p class="title-brown">
 <span>
 奖项设置:
 </span>
 </p>
 <p class="Detail">
 <p>
 一等奖: iphone 5S 奖品数量:60
 </p>
 <p>
 二等奖: ipad mini2 奖品数量:100
 </p>
 <p>
 三等奖: 金士顿16G手机卡 奖品数量:2000
 </p>
 </p>
 </p>
 </p>
 
 <p class="boxcontent boxwhite">
 <p class="box">
 <p class="title-brown">
 活动说明:
 </p>
 <p class="Detail">
 <p class="red">
 中奖用户请准确将收货地址发送给我,我们将以货到付款的方式邮寄给你!
 </p>
 <p>
 亲,祝您好运哦!<a href="http://2311156115.44c.pw/prize.php">再来一次</a>
 </p>
 </p>
 </p>
 </p>
 </p>
 <p style="clear:both;">
 </p>
 </p>
 
 <script type="text/javascript">
 window.sncode = "null";
 $(function() {
 $("#scratchpad").wScratchPad({
 width: 150,
 height: 40,
 color: "#a9a9a7",
 
 });
 });
 </script>
 
 </body>

</html>
Copy after login

sxxybbs_wx.php

<?php
/**
 * wechat php test
 */

//define your token
define("TOKEN", "wwwsxxybbscom");
$wechatObj = new wechatCallbackapiTest();
//$wechatObj->valid();
$wechatObj->responseMsg();
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 data
 if (!empty($postStr)){
  
  $postObj = simplexml_load_string($postStr, &#39;SimpleXMLElement&#39;, LIBXML_NOCDATA);
 $fromUsername = $postObj->FromUserName;
  $toUsername = $postObj->ToUserName;
 $time = time();
 
 if($postObj->Content == &#39;1&#39;){
 $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>"; 
 $msgType = &#39;text&#39;;
 $contentStr = "你输入了:1";
 $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
   echo $resultStr;
 
 }else if($postObj->Content == &#39;抽奖&#39;){
 $newsTpl ="<xml>
  <ToUserName><![CDATA[%s]]></ToUserName>
  <FromUserName><![CDATA[%s]]></FromUserName>
  <CreateTime>%s</CreateTime>
  <MsgType><![CDATA[news]]></MsgType>
  <ArticleCount>1</ArticleCount>
  <Articles>
  <item>
  <Title><![CDATA[刮刮乐翻天]]></Title> 
  <Description><![CDATA[我就要去刮刮乐,抽奖去!]]></Description>
  <PicUrl><![CDATA[http://special.sxcq.cn/cj/weixin/ggk/ggk.jpg]]></PicUrl>
  <Url><![CDATA[%s]]></Url>
  </item>
  </Articles>
  <FuncFlag>0</FuncFlag>
  </xml>";
  
 $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 = "请输入:&#39;1‘或者‘抽奖&#39;";
   $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
   echo $resultStr;
  }else{
   $msgType = "text";
   $contentStr = "谢谢你关注sxxybbs博客,后续有精彩的内容会第一时间发送给您!回复:&#39;1‘或者‘抽奖&#39;得到对应的服务";
   $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;
 }
 }
}

?>
Copy after login

【Related Recommendations】

1.

Special Recommendation: "php Programmer Toolbox" V0.1 version download

2.

Complete download of WeChat mini program

3.

WeChat mini program demo: Yangtao

The above is the detailed content of Code example of scratch card function for PHP development applet. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template