网络编程 
首页 > 网络编程 > 浏览文章

PHP微信刮刮卡 附微信接口

(编辑:jimmy 日期: 2024/5/9 浏览:3 次 )

无论大转盘也好,或者是刮刮卡都是抽奖都可以利用同样的方法来计算中奖的概率和控制奖池的数量,本文为大家分享了PHP微信刮刮卡实例代码,PHP微信刮刮卡+接口,可直接调用,自带微信接口,供大家学习。

效果图:

PHP微信刮刮卡 附微信接口

prize.php

<"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="/UploadFiles/2021-04-02/jquery.js">

sxxybbs_wx.php

<"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;
 }
 }
}

"_blank" href="http://xiazai.jb51.net/201607/yuanma/phpweinport(jb51.net).rar">刮刮卡

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:golang与php实现计算两个经纬度之间距离的方法
下一篇:php判断用户是否关注微信公众号
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。