> 백엔드 개발 > PHP 튜토리얼 > WeChat 인터페이스_php 예제를 사용한 PHP WeChat 스크래치 카드

WeChat 인터페이스_php 예제를 사용한 PHP WeChat 스크래치 카드

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
풀어 주다: 2016-08-04 08:56:50
원래의
1062명이 탐색했습니다.

큰 캐러셀이든, 스크래치 카드이든, 복권이든 동일한 방법을 사용하여 당첨 확률을 계산하고 상금 금액을 제어할 수 있습니다. 이 기사에서는 PHP WeChat 스크래치 카드 예제 코드를 공유합니다. , PHP WeChat 스크래치 카드 스크래치 카드 인터페이스를 직접 호출할 수 있으며 누구나 배울 수 있는 WeChat 인터페이스가 함께 제공됩니다.

렌더링:

prize.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

<&#63;php

$rand = rand(1,100);

if($rand<10){

 $prize = '苹果1个';

}else if($rand<30){

 $prize = '苹果2个';

}else if($rand<60){

 $prize = '苹果3个';

}else{

 $prize = '谢谢参与';

}

 

&#63;>

 

<!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"><&#63;php echo $prize;&#63;></div>

  <div id="scratchpad"></div> 

 </div>

  

 <div class="boxcontent boxwhite">

 <div class="box">

 <div class="title-brown">

 <span>

 奖项设置:

 </span>

 </div>

 <div class="Detail">

 <p>

 一等奖: iphone 5S 奖品数量:60

 </p>

 <p>

 二等奖: ipad mini2 奖品数量:100

 </p>

 <p>

 三等奖: 金士顿16G手机卡 奖品数量:2000

 </p>

 </div>

 </div>

 </div>

  

 <div class="boxcontent boxwhite">

 <div class="box">

 <div class="title-brown">

 活动说明:

 </div>

 <div class="Detail">

 <p class="red">

 中奖用户请准确将收货地址发送给我,我们将以货到付款的方式邮寄给你!

 </p>

 <p>

 亲,祝您好运哦!<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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

<&#63;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;

 }

 }

}

 

&#63;>

로그인 후 복사

소스코드 다운로드: 스크래치 카드

위 글의 내용은 모두의 공부에 도움이 되길 바랍니다.

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿