作者:Zhengweiwei313 | 来源:互联网 | 2017-05-11 01:14
无论大转盘也好,或者是刮刮卡都是抽奖都可以利用同样的方法来计算中奖的概率和控制奖池的数量,本文为大家分享了PHP微信刮刮卡实例代码,PHP微信刮刮卡+接口,可直接调用,自带微信接口,供大家学习。
效果图:
prize.php
奖项设置:
一等奖: iphone 5S 奖品数量:60
二等奖: ipad mini2 奖品数量:100
三等奖: 金士顿16G手机卡 奖品数量:2000
活动说明:
中奖用户请准确将收货地址发送给我,我们将以货到付款的方式邮寄给你!
亲,祝您好运哦!再来一次
sxxybbs_wx.php
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 = "
%s
0
";
$msgType = 'text';
$cOntentStr= "你输入了:1";
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
}else if($postObj->COntent== '抽奖'){
$newsTpl ="
%s
1
-
http://special.sxcq.cn/cj/weixin/ggk/ggk.jpg]]>
0
";
$url="http://2311156115.44c.pw/prize.php";
$resultStr = sprintf($newsTpl, $fromUsername, $toUsername, $time,$url);
echo $resultStr;
}else{
$keyword = trim($postObj->Content);
$textTpl = "
%s
0
";
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;
}
}
}
?>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支PHP中文网。
更多PHP微信刮刮卡 相关文章请关注PHP中文网!