Php version: details about the instance for sending text messages from Alibaba Cloud> (Alibaba big fish)
The example in this article describes how to send a php version of Alibaba Cloud SMS. We will share this with you for your reference. The details are as follows:
Common functions
// Send more powerful protected function sendDayuSmsPlus ($ tel, $ type, $ data) {$ dayu_template = 'dayu _ template _'. $ type; $ signname = C ($ dayu_template. ". signname "); $ templatecode = C ($ dayu_template. ". templatecode "); // require LIB_PATH. 'org/Taobao-sdk-php/TopSdk. php'; include_once LIB_PATH. 'org/Taobao-sdk-php/TopSdk. php '; $ c = new TopClient; $ c-> appkey = C ('dayu _ appkey'); $ c-> secretKey = C ('dayu _ secretKey '); $ req = new AlibabaAliqinFcSmsNumSendRequest; $ req-> setSmsType ("normal"); $ req-> setSmsFreeSignName ("{$ signname }"); if ($ type = 'sold ') {$ req-> setSmsParam (' {"name ":"'. $ data ['name']. '"}');} if ($ type = 'buckets') {$ req-> setSmsParam ('{" name ":"'. $ data ['name']. '"," product ":"'. $ data ['product']. '"}');} if ($ type = 'newagent') {$ req-> setSmsParam ('{" name ":"'. $ data ['name']. '"}') ;}$ req-> setRecNum (" {$ tel} "); $ req-> setSmsTemplateCode (" {$ templatecode }"); $ resp = $ c-> execute ($ req); return $ resp ;}
Optimization
// Send more powerful protected function sendDayuSmsPlus ($ tel, $ type, $ data) {$ dayu_template = 'dayu _ template _'. $ type; $ signname = C ($ dayu_template. ". signname "); $ templatecode = C ($ dayu_template. ". templatecode "); // require LIB_PATH. 'org/Taobao-sdk-php/TopSdk. php'; include_once LIB_PATH. 'org/Taobao-sdk-php/TopSdk. php '; $ c = new TopClient; $ c-> appkey = C ('dayu _ appkey'); $ c-> secretKey = C ('dayu _ secretKey '); $ req = new AlibabaAliqinFcSmsNumSendRequest; $ req-> setSmsType ("normal"); $ req-> setSmsFreeSignName ("{$ signname}"); switch ($ type) {case 'sold ': $ req-> setSmsParam (' {"name ":"'. $ data ['name']. '"}'); break; case 'buckets': $ req-> setSmsParam ('{" name ":"'. $ data ['name']. '"," product ":"'. $ data ['product']. '"}'); break; case 'newagent': $ req-> setSmsParam ('{" name ":"'. $ data ['name']. '"}'); break; default: $ req-> setSmsParam ('{" code ":"'. $ data ['code']. '"," product ":"'. $ data ['product']. '"}') ;}$ req-> setRecNum (" {$ tel} "); $ req-> setSmsTemplateCode (" {$ templatecode }"); $ resp = $ c-> execute ($ req); return $ resp ;}
Here, there is a difference between require and include_once. If you use require to call the method again, an error is returned. Fatal error: Cannot redeclare class. Change to include_once.
Configuration Template
<? Phpreturn array (// configure 'dayu _ appkey' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'For Alibaba Cloud Big Fish SMS ', 'dayu _ template_register '=> array ('signname' => 'registration verification', 'templatecode' => 'sms _ 2017 '), 'dayu _ template_alteration' => array ('signature' => 'verification of change ', 'templatecode' => 'sms _ 2017 '), 'dayu _ template_identity '=> array ('signature' => 'Authentication', 'templatecode' => 'sms _ 2017 '), 'dayu _ template_sold '=> array ('signname' => 'click duoduo', 'templatecode' => 'sms _ 666666 '), 'dayu _ template_buysuccess '=> array ('signname' => 'click duoduo', 'templatecode' => 'sms _ 123456 '), 'dayu _ template_newagent '=> array ('signname' => 'click duoduo', 'templatecode' => 'sms _ 123 '),);
The signature will be displayed in the text message [Click More]. As long as the signature is allowed, the system or self-approved can be mixed.
Native class
<? Php/*** top api: alibaba. aliqin. fc. sms. num. send request ** @ author auto create * @ since 1.0, 2015.12.02 */class AlibabaAliqinFcSmsNumSendRequest {/*** public return parameter, which is passed back in message return; for example, you can pass in the member ID of your subordinates. When a message is returned, this member ID will be included, the user can identify which member uses your app **/private $ extend;/*** SMS receiving number based on the member ID. One or more mobile phone numbers are supported. The input number is an 11-digit mobile phone number and cannot be 0 or + 86. Multiple numbers must be entered for group-sending text messages, separated by commas (,). A maximum of 200 numbers can be entered for a single call. Example: 18600000000,13911111111, 13322222222 **/private $ recNum;/*** text message signature. The input text message signature must be available in Alibaba big fish "Management Center-text message signature management. If "Ali big fish" has passed the verification in the text message signature management, you can pass in "Ali big fish" (remove quotation marks when passing parameters) as the text message signature. Example of text message effect: [Alibaba Big Fish] Welcome to the Alibaba big fish service. **/Private $ smsFreeSignName;/*** SMS template variable. The parameter passing rule {"key": "value"} must be the same as the variable name in the Application Template, multiple variables are separated by commas. Example: For the template "Verification code $ [code], you are performing $ {product} authentication. Do not tell others when you are killed !", When passing parameters, You need to input {"code": "1234", "product": "alidayu"} **/private $ smsParam;/*** SMS template ID, the input template must be an available template in "Management Center-SMS template management. Example: SMS_585014 **/private $ smsTemplateCode;/*** text message type. Set the input value to normal **/private $ smsType; private $ apiParas = array (); public function setExtend ($ extend) {$ this-> extend = $ extend; $ this-> apiParas ["extend"] = $ extend;} public function getExtend () {return $ this-> extend;} public function setRecNum ($ recNum) {$ this-> recNum = $ recNum; $ this-> apiParas ["rec_num"] = $ recNum;} public function getRecNum () {return $ this-> recNum;} public function setSmsFreeSignName ($ smsFreeSignName) {$ this-> smsFreeSignName = $ smsFreeSignName; $ this-> apiParas ["sms_free_sign_name"] = $ smsFreeSignName;} public function callback () {return $ this-> response ;} public function setSmsParam ($ smsParam) {$ this-> smsParam = $ smsParam; $ this-> apiParas ["sms_param"] = $ smsParam;} public function getSmsParam () {return $ this-> smsParam;} public function setSmsTemplateCode ($ smsTemplateCode) {$ this-> smsTemplateCode = $ smsTemplateCode; $ this-> apiParas ["sms_template_code"] = $ smsTemplateCode;} public function getSmsTemplateCode () {return $ this-> smsTemplateCode;} public function setSmsType ($ smsType) {$ this-> smsType = $ smsType; $ this-> apiParas ["sms_type"] = $ smsType;} public function getSmsType () {return $ this-> smsType ;} public function getApiMethodName () {return "alibaba. aliqin. fc. sms. num. send ";} public function getApiParas () {return $ this-> apiParas;} public function check () {RequestCheckUtil: checkNotNull ($ this-> recNum," recNum "); requestCheckUtil: checkNotNull ($ this-> Accept, "smsFreeSignName"); RequestCheckUtil: checkNotNull ($ this-> smsTemplateCode, "smsTemplateCode"); RequestCheckUtil :: checkNotNull ($ this-> smsType, "smsType");} public function putOtherTextParam ($ key, $ value) {$ this-> apiParas [$ key] = $ value; $ this-> $ key = $ value ;}}