网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 PHP微信刮刮卡 附微信接口
内容
    无论大转盘也好,或者是刮刮卡都是抽奖都可以利用同样的方法来计算中奖的概率和控制奖池的数量,本文为大家分享了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">
     <script src="index/jquery.js" type="text/javascript"></script>
     <script src="index/wScratchPad.js" type="text/javascript"></script>
     <div>
     <div>
     <img src="index/activity-scratch-card-bannerbg.png"> 
     <div id="prize"><?php echo $prize;?></div>
      <div id="scratchpad"></div>  
     </div>
     <div>
     <div>
     <div>
     <span>
     奖项设置:
     </span>
     </div>
     <div>
     <p>
     一等奖: iphone 5S 奖品数量:60
     </p>
     <p>
     二等奖: ipad mini2 奖品数量:100
     </p>
     <p>
     三等奖: 金士顿16G手机卡 奖品数量:2000
     </p>
     </div>
     </div>
     </div>
     <div>
     <div>
     <div>
     活动说明:
     </div>
     <div>
     <p>
     中奖用户请准确将收货地址发送给我,我们将以货到付款的方式邮寄给你!
     </p>
     <p>
     亲,祝您好运哦!<a href="http://2311156115.44c.pw/prize.php">再来一次</a>
     </p>
     </div>
     </div>
     </div>
     </div>
     <div>
     </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 = "谢谢你关注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;
     }
     }
    }
    ?>
    源码下载:刮刮卡
    以上就是本文的全部内容,希望对大家的学习有所帮助
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/28 21:54:45