PHP implementation of IMEI limit SMS Verification code send class _php tutorial

Source: Internet
Author: User

PHP implementation of IMEI limit SMS verification code send class


PHP implementation of IMEI limit SMS verification code send class

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

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

Class api_sms{

Const EXPIRE_SEC = 1800; Expiration time interval

Const RESEND_SEC = 60; Re-send time interval

Const ONE_DAY_FREQ = 5; The number of times you send text messages to the same phone number daily

Const ONE_DAY_IMEI_COUNT = 3; Number of IMEI messages sent to the same phone number daily

Public $error = Array ();

/**

* Send a verification code to the designated mobile phone number

* @param $mobile

* @param $imei

* @return BOOL

*/

Public Function Sendverifycode ($mobile, $imei) {

if (! $this->ismobile ($mobile)) {

$this->error = Array (' code ' = = 1, ' msg ' = ' = ' This mobile phone number is very wonderful Oh, please enter it correctly and try again ');

return false;

}

$redis = Api_common::redis ();

$vcKey = ' vc_ '. $mobile;

$limitKey = ' vc_limit_ '. $mobile;

Verification code re-issued limit

$data = Json_decode ($redis->get ($vcKey), true);

if ($data && time () < $data [' Resend_expire ']) {

$this->error = Array (' code ' = = 1, ' msg ' = ' + ' SMS has been sent within 1 minutes, please wait patiently ');

return false;

}

Mobile phone number and IMEI limit

$sendCnt = $redis->zscore ($limitKey, $imei);

if ($sendCnt && $sendCnt >= self::one_day_freq) {

$this->error = Array (' Code ' +-1, ' msg ' = ' = ' forfeited to SMS? Please wait or check if the text message is blocked ');

return false;

}

$imeiCnt = $redis->zcard ($limitKey);

if ($imeiCnt >= self::one_day_imei_count &&! $sendCnt) {

$this->error = Array (' code ' = = 1, ' msg ' = ' + ' has exceeded the verification code sending device limit ');

return false;

}

Get Verification Code

if (! $data) {

$VC = Strval (rand (100000, 999999));

$data = Array (' VC ' = = $VC, ' resend_expire ' = 0);

$redis->set ($vcKey, Json_encode ($data));

$redis->expire ($vcKey, self::expire_sec); Set the verification code expiration time

}

$VC = $data [' VC '];

$content = ' Security code: '. $VC;

$result = $this->send ($mobile, $content);

if ($result) {

Reset the re-send time limit

$data [' resend_expire '] = time () + self::resend_sec;

$ttl = $redis->ttl ($vcKey);

$redis->set ($vcKey, Json_encode ($data));

$redis->expire ($vcKey, $ttl);

Set phone number and IMEI limit

$redis->zincrby ($limitKey, 1, $imei);

$redis->expireat ($limitKey, Strtotime (date (' y-m-d ', Strtotime (' +1 Day ')));

}

return $result;

}

/**

* Send SMS to designated mobile phone number

* @param $mobile

* @param $content

* @return BOOL

*/

Public function Send ($mobile, $content) {

TODO invoke specific service provider API

return true;

}

/**

* Determine if the phone number is legal

* @param $mobile

* @return BOOL

*/

Private Function IsMobile ($mobile) {

if (Preg_match ('/^1\d{10}$/', $mobile))

return true;

return false;

}

/**

* Verify SMS Verification code

* @param $mobile

* @param $VC

* @return BOOL

*/

Public Function Checkverifycode ($mobile, $VC) {

$vcKey = ' vc_ '. $mobile;

$vcData = Json_decode (Api_common::redis ()->get ($vcKey), true);

if ($vcData && $vcData [' vc '] = = = = $VC) {

return true;

}

return false;

}

/**

* Clear Verification Code

* @param $mobile

*/

Public Function Cleanverifycode ($mobile) {

$redis = Api_common::redis ();

$vcKey = ' vc_ '. $mobile;

$limitKey = ' vc_limit_ '. $mobile;

$redis->del ($vcKey);

$redis->del ($limitKey);

}

}

Other users to pay for the implementation of the SMS Verification Code code

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

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

/*--------------------------------

Function: Chinese text message network PHP HTTP interface send SMS

Date Modified: 2009-04-08

Description: http://http.c123.com/tx/?uid= user account &pwd=md5 bit 32 password &mobile= number &content= content

State:

100 Successful Delivery

101 Validation Failure

102 Short Messages

103 operation failed

104 Illegal characters

105 Too much content

106th number Too many

107 Frequency too fast

108th Number Content Empty

109 Account freezes

110 prohibit frequent single sends

111 Tentative System Dispatch

No. 112th code is incorrect.

120 system upgrade

--------------------------------*/

$uid = ' 9999 '; User account

$pwd = ' 9999 '; Password

$mobile = ' 13912341234,13312341234,13512341234,02122334444 '; Number

$content = ' China SMS network PHP HTTP interface '; Content

Instant Delivery

$res = Sendsms ($uid, $pwd, $mobile, $content);

Echo $res;

Timed delivery

/*

$time = ' 2010-05-27 12:11 ';

$res = Sendsms ($uid, $pwd, $mobile, $content, $time);

Echo $res;

*/

function Sendsms ($uid, $pwd, $mobile, $content, $time = ", $mid =")

{

$http = ' http://http.c123.com/tx/';

$data = array

(

' UID ' = $uid,//user account

' PWD ' =>strtolower (MD5 ($PWD)),//MD5 bit 32 password

' Mobile ' = $mobile,//number

' Content ' = $content,//Contents

' Time ' = $time,//timed to send

' Mid ' = $mid//Sub-extension number

);

$re = Postsms ($http, $data); Post mode submission

if (Trim ($re) = = ' 100 ')

{

Return "sent successfully!";

}

Else

{

Return "Send failed! Status: ". $re;

}

}

function Postsms ($url, $data = ")

{

$row = Parse_url ($url);

$host = $row [' Host '];

$port = $row [' Port ']? $row [' Port ']:80;

$file = $row [' path '];

while (list ($k, $v) = each ($data))

{

$post. = Rawurlencode ($k). " = ". Rawurlencode ($v)." & "; Go to URL Standard code

}

$post = substr ($post, 0,-1);

$len = strlen ($post);

$fp = @fsockopen ($host, $port, $errno, $ERRSTR, 10);

if (! $fp) {

Return "$errstr ($errno) \ n";

} else {

$receive = ";

$out = "POST $file http/1.1\r\n";

$out. = "Host: $host \ r \ n";

$out. = "content-type:application/x-www-form-urlencoded\r\n";

$out. = "connection:close\r\n";

$out. = "Content-length: $len \r\n\r\n";

$out. = $post;

Fwrite ($fp, $out);

while (!feof ($fp)) {

$receive. = Fgets ($fp, 128);

}

Fclose ($FP);

$receive = Explode ("\r\n\r\n", $receive);

unset ($receive [0]);

Return implode ("", $receive);

}

}

?>

The above mentioned is the whole content of this article, I hope you can like.

http://www.bkjia.com/PHPjc/994740.html www.bkjia.com true http://www.bkjia.com/PHPjc/994740.html techarticle PHP Implementation of the IMEI limit SMS Verification code send class PHP implementation of the IMEI limit SMS verification code send class? 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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.