Now this message informs the flood of the age; If you don't have an SMS sign-up, you can't say you're a developer.
This verification code is not difficult to make, but if just contact is also a little unknown from where to start the confusion;
First, the concept;
1: Find a reliable SMS verification code platform, recommended the following used; The following Jong communication as an example; other platforms a truth;
Ali Big Fish: http://www.alidayu.com/service?spm=a3142.7802752.1.4.oAfDUZ&_t=2#sms
Jong Communication: http://www.yuntongxun.com/
2: Registration, login, certification, all nonsense; get account SID, AUTH TOKEN;
3: Create an application;
4: Add a template;
5: Audit pass; get template id; OK;
6: Complete? Think more, this is just reached the basic conditions can send verification code, and then download the official SDK;
The title is hung with thinkphp integrated SMS verification code; do not write thinkphp; must be sprayed to slag! There's no residue left!
All source code can be found in my open source project bjyadmin: http://git.oschina.net/shuaibai123/thinkphp-bjyadmin
Take my open source project as an example; put it on the/thinkphp/library/org/xb/rongcloud.class.php.
7: Add function/application/common/common/function.php in public function library
/**
* Send the capacitive cloud communication verification Code
* @param int $phone mobile phone number
* @param int $code Verification Code
* @return Boole is sent successfully
*/
function Send_sms_code ($phone, $code) {
Request address, format as follows, do not need to write https://
$serverIP = ' app.cloopen.com ';
Request Port
$serverPort = ' 8883 ';
Rest version number
$softVersion = ' 2013-12-26 ';
Master Account
$accountSid =c (' Ronglian_account_sid ');
Master Account Token
$accountToken =c (' Ronglian_account_token ');
App ID
$appId =c (' ronglian_appid ');
$rest = new \org\xb\rest ($serverIP, $serverPort, $softVersion);
$rest->setaccount ($accountSid, $accountToken);
$rest->setappid ($appId);
Send Template SMS
$result = $rest->sendtemplatesms ($phone, Array ($code, 5), 59939);
if ($result ==null) {
return false;
}
if ($result->statuscode!=0) {
return false;
}else{
return true;
}
}
8: Fill in configuration item/application/common/conf/config.php with account SID, AUTH TOKEN, template ID
' Ronglian_account_sid ' = ', '//Jong Communication Master Account Accountsid
' Ronglian_account_token ' = ', '//Jong Communication master Account TOKEN Accounttoken
' Ronglian_appid ' + ',//Jong communication app ID APPID
9: Call Function: Send_sms_code (' phone number ', ' Verification Code ');
I recently organized the Open source project is already integrated well, all this, only need in the configuration item in the blanks, can send a text message;
Children's shoes need to be able to directly git clone test: http://git.oschina.net/shuaibai123/thinkphp-bjyadmin
Thinkphp Integration Series of SMS Verification Code, order notification