PHP Simple verification process for mobile phone verification code
Have done a demand: advertisers backstage to initiate investigation activities, the average user to participate in the survey after the jump value of a URL to pick up 1Q points (1 cents); After a period of time, the advertiser feedback received a lot of mobile phone numbers are forged (we began to use regular match to determine the correct cell phone number), Then the product let us add mobile phone message verification, it becomes the following look.
The beginning of the train of thought should be very normal kind, with Rand generated random code, and then there is redis inside, set expire for 60 seconds; later consideration, the user for 1 cents is not so, need to verify the code is not blind fill, the system also restricts an ID user can only participate in 5 times a day this activity , but also in order not to waste the principle of system resources, the company sent a text message already need 2 cents a piece, decided not to use Redis, with the following ideas:
Use the user account + activity id+ mobile phone number processing to generate a fixed number, and then driving the time stamp to generate 4-digit number, interference will only guarantee 4 digits corresponding to the binary 1, 5, 6, 7, 8, 9 bits are not disturbed, so that the corresponding would produce a POW (2,6) a different 4-digit number, Randomly sent to a user.
User Verification Verification Code is also only to verify that the verification code 1, 5, 6, 7, 8, 9 is correct, for the user account + activity id+ mobile phone number processing generated, so that no storage verification code, to verify the number of mobile phone number.
Specific test examples in the following, why is the test example, because the end is not used, I went to close the development of other projects, the following code is occasionally turned to see the code unexpectedly is I work the first anniversary of writing, test code generated verification code hash is not very good, there is no time to improve, Mainly introduce the above ideas.
Gettelephonecode ($uin, $actId, $telephone), Var_dump ($code), Var_dump ($telCode->checktelephonecode ($uin, $actId, $telephone, $code)); Var_dump ($telCode->checktelephonecode ($uin, $actId, $telephone, $code +10));