PHP scratch card attachment interface, php scratch card interface
Whether it's a big turntable or a scratch card, you can use the same method to calculate the winning probability and control the number of prize pools. This article shares the PHP scratch card instance code for everyone, PHP scratch card + interface, which can be called directly and comes with an interface for your learning.
:
Prize. php
<? Php $ rand = rand (1,100); if ($ rand <10) {$ prize = 'apple 1 ';} else if ($ rand <30) {$ prize = 'apple 2 ';} else if ($ rand <60) {$ prize = 'apple 3 ';} else {$ prize = 'Thank you for participating ';}?> <! DOCTYPE html>
Sxxybbs_wx.php
<? Php/*** wechat php test * // define your tokendefine ("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 d Ifferent 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 = "you entered: 1"; $ resultStr = sprintf ($ textTpl, $ fromUsername, $ toUsername, $ time, $ msgType, $ contentStr); echo $ resultStr ;} else if ($ postObj-> Content = 'lottery ') {$ newsTpl = "<xml> <ToUserName> <! [CDATA [% s]> </ToUserName> <FromUserName> <! [CDATA [% s]> </FromUserName> <CreateTime> % s </CreateTime> <MsgType> <! [CDATA [news]> </MsgType> <ArticleCount> 1 </ArticleCount> <Articles> <item> <Title> <! [CDATA [scratch a day]> </Title> <Description> <! [CDATA [I will go to scratch and draw a lottery!]> </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 = "enter '1' or 'lot'"; $ resultStr = sprintf ($ textTpl, $ fromUsername, $ toUsername, $ time, $ msgType, $ contentStr); echo $ resultStr;} else {$ msgType = "text"; $ contentStr = "thank you for following sxxybbs's blog, you will receive the most exciting content soon! Reply: '1' or 'lottery 'to get the corresponding service "; $ 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 ;}}?>
Source code download: scratch card
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.