像微信大转盘、刮刮卡这样的抽奖,最重要最核心的就是如何设置中奖的概率。本文综合了网上多个微信大转盘、刮刮卡的代码
无论大转盘也好,或者是刮刮卡都是抽奖都可以利用同样的方法来计算中奖的概率和控制奖池的数量,本文为大家分享了php微信刮刮卡实例代码,php微信刮刮卡+接口,可直接调用,自带微信接口,供大家学习。
效果图:
prize.php
<?php
$rand = rand(1,100);
if($rand<10){
$prize = '苹果1个';
}else if($rand<30){
$prize = '苹果2个';
}else if($rand<60){
$prize = '苹果3个';
}else{
$prize = '谢谢参与';
}
?>
<!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>
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, 'simplexmlelement', libxml_nocdata);
$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]]></msgtype>
<content><![cdata[%s]]></content>
<funcflag>0</funcflag>
</xml>";
$msgtype = 'text';
$contentstr = "你输入了:1";
$resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr);
echo $resultstr;
}else if($postobj->content == '抽奖'){
$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 = "请输入:'1‘或者‘抽奖'";
$resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr);
echo $resultstr;
}else{
$msgtype = "text";
$contentstr = "谢谢你关注sxxybbs博客,后续有精彩的内容会第一时间发送给您!回复:'1‘或者‘抽奖'得到对应的服务";
$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;
}
}
}
?>
【相关推荐】
1. 特别推荐:“php程序员工具箱”v0.1版本下载
2. 微信小程序完整下载
3. 微信小程序demo:阳淘
以上就是php开发小程序之刮刮卡功能的代码实例的详细内容。