PHP微信刮刮卡 附微信接口
無論大轉(zhuǎn)盤也好,或者是刮刮卡都是抽獎都可以利用同樣的方法來計算中獎的概率和控制獎池的數(shù)量,本文為大家分享了PHP微信刮刮卡實(shí)例代碼,PHP微信刮刮卡+接口,可直接調(diào)用,自帶微信接口,供大家學(xué)習(xí)。
效果圖:

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>
<div class="main">
<div class="cover">
<img src="index/activity-scratch-card-bannerbg.png">
<div id="prize"><?php echo $prize;?></div>
<div id="scratchpad"></div>
</div>
<div class="boxcontent boxwhite">
<div class="box">
<div class="title-brown">
<span>
獎項設(shè)置:
</span>
</div>
<div class="Detail">
<p>
一等獎: iphone 5S 獎品數(shù)量:60
</p>
<p>
二等獎: ipad mini2 獎品數(shù)量:100
</p>
<p>
三等獎: 金士頓16G手機(jī)卡 獎品數(shù)量:2000
</p>
</div>
</div>
</div>
<div class="boxcontent boxwhite">
<div class="box">
<div class="title-brown">
活動說明:
</div>
<div class="Detail">
<p class="red">
中獎用戶請準(zhǔn)確將收貨地址發(fā)送給我,我們將以貨到付款的方式郵寄給你!
</p>
<p>
親,祝您好運(yùn)哦!<a >再來一次</a>
</p>
</div>
</div>
</div>
</div>
<div style="clear:both;">
</div>
</div>
<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 = "謝謝你關(guān)注sxxybbs博客,后續(xù)有精彩的內(nèi)容會第一時間發(fā)送給您!回復(fù):'1‘或者‘抽獎'得到對應(yīng)的服務(wù)";
$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;
}
}
}
?>
源碼下載:刮刮卡
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android刮刮卡效果實(shí)現(xiàn)代碼
- Android刮刮卡功能具體實(shí)現(xiàn)代碼
- php抽獎概率算法(刮刮卡,大轉(zhuǎn)盤)
- Android刮刮卡實(shí)現(xiàn)原理與代碼講解
- Android App中實(shí)現(xiàn)簡單的刮刮卡抽獎效果的實(shí)例詳解
- 基于PHP代碼實(shí)現(xiàn)中獎概率算法可用于刮刮卡、大轉(zhuǎn)盤等抽獎算法
- 利用HTML5的畫布Canvas實(shí)現(xiàn)刮刮卡效果
- javascript+canvas實(shí)現(xiàn)刮刮卡抽獎效果
- js和html5實(shí)現(xiàn)手機(jī)端刮刮卡抽獎效果完美兼容android/IOS
- 手機(jī)端js和html5刮刮卡效果
相關(guān)文章
php版微信開發(fā)Token驗(yàn)證失敗或請求URL超時問題的解決方法
這篇文章主要介紹了php版微信開發(fā)Token驗(yàn)證失敗或請求URL超時問題的解決方法,簡單分析了Token驗(yàn)證失敗及請求URL超時的原因及相關(guān)解決方法,需要的朋友可以參考下2016-09-09
如何使用PHP file_exists函數(shù)檢查文件是否存在
這篇文章主要為大家介紹了PHP函數(shù)file_exists檢查文件是否存在實(shí)現(xiàn)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2024-01-01
ThinkPHP3.2.3實(shí)現(xiàn)分頁的方法詳解
這篇文章主要介紹了ThinkPHP3.2.3實(shí)現(xiàn)分頁的方法,詳細(xì)分析了thinkPHP3.2.3分頁操作的相關(guān)技巧,包括分頁類的引用、數(shù)據(jù)庫查詢操作、分頁參數(shù)設(shè)置及前端視圖界面設(shè)計等,需要的朋友可以參考下2016-06-06
Drupal讀取Excel并導(dǎo)入數(shù)據(jù)庫實(shí)例
這篇文章主要介紹了Drupal利用PHPExcel讀取Excel并導(dǎo)入數(shù)據(jù)庫的例子,需要的朋友可以參考下2014-03-03
php 模擬 asp.net webFrom 按鈕提交事件實(shí)例
需要php方面的項目開發(fā),php剛剛?cè)腴T,在寫按鈕提交過程中,asp.net里的按鈕事件更好些,下面有個實(shí)例,大家可以看看2014-10-10
PHP配置把錯誤日志以郵件方式發(fā)送方法(Windows系統(tǒng))
這篇文章主要介紹了PHP配置把錯誤日志以郵件方式發(fā)送方法(Windows系統(tǒng)),本文給出了配置示例和使用例子,需要的朋友可以參考下2015-06-06
ecshop適應(yīng)在PHP7的修改方法解決報錯的實(shí)現(xiàn)
下面小編就為大家?guī)硪黄猠cshop適應(yīng)在PHP7的修改方法解決報錯的實(shí)現(xiàn)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11
Yii2-GridView 中讓關(guān)聯(lián)字段帶搜索和排序功能示例
這篇文章主要介紹了Yii2-GridView 中讓關(guān)聯(lián)字段帶搜索和排序功能示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-01-01

