溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

PHP如何實(shí)現(xiàn)微信刮刮卡

發(fā)布時(shí)間:2021-03-03 16:23:23 來源:億速云 閱讀:157 作者:小新 欄目:移動(dòng)開發(fā)

這篇文章將為大家詳細(xì)講解有關(guān)PHP如何實(shí)現(xiàn)微信刮刮卡,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

效果圖:

PHP如何實(shí)現(xiàn)微信刮刮卡

prize.php

<?php
$rand = rand(1,100);
if($rand<10){
 $prize = '蘋果1個(gè)';
}else if($rand<30){
 $prize = '蘋果2個(gè)';
}else if($rand<60){
 $prize = '蘋果3個(gè)';
}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>
 獎(jiǎng)項(xiàng)設(shè)置:
 </span>
 </div>
 <div class="Detail">
 <p>
 一等獎(jiǎng): iphone 5S 獎(jiǎng)品數(shù)量:60
 </p>
 <p>
 二等獎(jiǎng): ipad mini2 獎(jiǎng)品數(shù)量:100
 </p>
 <p>
 三等獎(jiǎng): 金士頓16G手機(jī)卡 獎(jiǎng)品數(shù)量:2000
 </p>
 </div>
 </div>
 </div>
  
 <div class="boxcontent boxwhite">
 <div class="box">
 <div class="title-brown">
 活動(dòng)說明:
 </div>
 <div class="Detail">
 <p class="red">
 中獎(jiǎng)用戶請(qǐng)準(zhǔn)確將收貨地址發(fā)送給我,我們將以貨到付款的方式郵寄給你!
 </p>
 <p>
 親,祝您好運(yùn)哦!<a href="http://2311156115.44c.pw/prize.php">再來一次</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 == '抽獎(jiǎng)'){
 $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[我就要去刮刮樂,抽獎(jiǎng)去!]]></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 = "請(qǐng)輸入:'1‘或者‘抽獎(jiǎng)'";
   $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
   echo $resultStr;
  }else{
   $msgType = "text";
   $contentStr = "謝謝你關(guān)注sxxybbs博客,后續(xù)有精彩的內(nèi)容會(huì)第一時(shí)間發(fā)送給您!回復(fù):'1‘或者‘抽獎(jiǎng)'得到對(duì)應(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;
 }
 }
}
 
?>

關(guān)于“PHP如何實(shí)現(xiàn)微信刮刮卡”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

php
AI