Joke Collection Website - Blessing messages - Personal registration SMS interface

Personal registration SMS interface

Let's introduce the short message php interface of Magic Cloud Platform. Link: www.moduyun.com

//works well with php5.3 and php5.6.

Namespace Moduyun \ Sms

require _ once(' smssenderutil . PHP ');

SmsSingleSender class {

var $ url

var $ accesskey

var $ secretkey

var $ util

function __construct($accesskey,$secretkey) {

$ this-& gt; URL = "/SMS/v 1/sendsinglesms ";

$ this-& gt; accesskey =? $ accesskey

$ this-& gt; secretkey = $ secretkey

$ this-& gt; util = new SmsSenderUtil();

}

/**

* ordinary single distribution, clearly indicate the content. If there are multiple signatures, please add them to the information content of the form, otherwise the system will use the default signature.

* @param int $type SMS type, 0 is ordinary SMS, 1 is marketing SMS.

* @param string $nationCode country code, for example, 86 is China.

* @param string $phoneNumber mobile phone number without country code

* @param string $msg information content must be consistent with the template format of the application, otherwise an error will be returned.

* @param string $extend extension code, which can fill in the blanks.

* @param string $ext parameters returned by the server as they are can be filled in.

* @ returnstring JSON string {"result": xxxxx, "errmsg": "xxxxx "...}, please refer to the agreement document for the omitted contents.

*/

Send function ($ type, $nationCode, $ phoneNumber, $msg, $extend = "",$ ext = ""{

/*

Request packet body

{

"Telephone": {

"country code": "86",

[Mobile phone]: "1378888888"

},

[Type]: 0,

"msg": "Your verification code is 1234",

" SIG ":" fdba 654 e 05 BC 0d 157967 13a 1a 1a 23 18c ",

[Time]: 1479888540,

"expansion": "",

" ext ":" "

}

Response inclusion

{

[Result]: 0,

" errmsg": "OK ",

" ext ":" ",

" sid": "xxxxxxx ",

[Cost]: 1

}

*/

$ random = $ this-& gt; util-& gt; get random();

$ curTime = time();

$ whole URL = $ this-& gt; Website. "? accesskey= "。 $ this-& gt; Access key. “& amprandom= "。 $ random

//Organize the post package body according to the protocol.

$ data = new \ stdClass();

$ tel = new \ stdClass();

$ tel->; Country code = "". $ nationCode

$ tel->; Mobile phone = "". $ number mobile phones;

$ data-& gt; tel = $ tel

$ data-& gt; type =(int)$ type;

$ data-& gt; msg = $ msg

$ data-& gt; sig = hash("sha256 ",

" secretkey= "$ this-& gt; Secret key. “& amprandom= "。 $random。 & time =. $curTime。 & mobile phone =. $ phoneNumber,FALSE);

$ data-& gt; time = $ curTime

$ data-& gt; extend = $ extend

$ data-& gt; ext = $ ext

return $ this-& gt; util-& gt; sendCurlPost($wholeUrl,$ data);

}

/**

* Specify the template sheet.

* @param string $nationCode country code, for example, 86 is China.

* @param string $phoneNumber mobile phone number without country code

* @param int $templId template Id

* @param array $params template parameter list, such as template {1}...{2}...{3}, then you need to bring three parameters.

* @param string $sign signature. If a string is filled in, the system will use the default signature.

* @param string $extend extension code, which can fill in the blanks.

* @param string $ext parameters returned by the server as they are can be filled in.

* @ return string JSON string { " result ":xxxxx," errmsg": "xxxxxx "? ...}, please refer to the agreement document for the omitted contents.

*/

SendWithParam($nationCode, $ phoneNumber, $templId = 0, $params, $sign = "",$extend = "",$ ext = ""{

/*

Request packet body

{

"Telephone": {

"country code": "86",

[Mobile phone]: "1378888888"

},

"Sign": "Magic Cloud",

【TPL _ id】: 19,

" params": [

"Verification code",

" 1234",

"4"

],

" SIG ":" fdba 654 e 05 BC 0d 157967 13a 1a 1a 23 18c ",

[Time]: 1479888540,

"expansion": "",

" ext ":" "

}

Response inclusion

{

[Result]: 0,

" errmsg": "OK ",

" ext ":" ",

" sid": "xxxxxxx ",

[Cost]: 1

}

*/

$ random = $ this-& gt; util-& gt; get random();

$ curTime = time();

$ whole URL = $ this-& gt; Website. "? sdkaccesskey= "。 $ this-& gt; Access key. “& amprandom= "。 $ random

//Organize the post package body according to the protocol.

$ data = new \ stdClass();

$ tel = new \ stdClass();

$ tel->; Country code = "". $ nationCode

$ tel->; Mobile phone = "". $ number mobile phones;

$ data-& gt; tel = $ tel

$ data-& gt; SIG = $ this-& gt; util-& gt; calculateSigForTempl($ this-& gt; secretkey,$random,$curTime,$ phone $ number);

$ data-& gt; tpl _ id = $ templId

$ data-& gt; params = $ params

$ data-& gt; sign = $ sign

$ data-& gt; time = $ curTime

$ data-& gt; extend = $ extend

$ data-& gt; ext = $ ext

return $ this-& gt; util-& gt; sendCurlPost($wholeUrl,$ data);

}

}

SmsMultiSender class {

var $ url

var $ accesskey

var $ secretkey

var $ util

function __construct($accesskey,$secretkey) {

$ this-& gt; URL = "/SMS/v 1/sendsinglesms ";

$ this-& gt; accesskey =? $ accesskey

$ this-& gt; secretkey = $ secretkey

$ this-& gt; util = new SmsSenderUtil();

}

/**

* ordinary mass, clearly specify the content. If there are multiple signatures, please add them to the information content of the form, otherwise the system will use the default signature.

* Note that overseas SMS has no group sending function.

* @param int $type SMS type, 0 is ordinary SMS, 1 is marketing SMS.

* @param string $nationCode country code, for example, 86 is China.

* @param string $phoneNumbers mobile phone number list without country code

* @param string $msg information content must be consistent with the template format of the application, otherwise an error will be returned.

* @param string $extend extension code, which can fill in the blanks.

* @param string $ext parameters returned by the server as they are can be filled in.

* @ returnstring JSON string {"result": xxxxx, "errmsg": "xxxxx "...}, please refer to the agreement document for the omitted contents.

*/

Send function ($ type, $nationCode, $phoneNumbers, $msg, $extend = "",$ext = "").

/*

Request packet body

{

"Telephone": [

{

"country code": "86",

[Mobile phone]: "1378888888"

},

{

"country code": "86",

[Mobile phone]: "/kloc-0 13788888889"

}

],

[Type]: 0,

"msg": "Your verification code is 1234",

" SIG ":" fdba 654 e 05 BC 0d 157967 13a 1a 1a 23 18c ",

[Time]: 1479888540,

"expansion": "",

" ext ":" "

}

Response inclusion

{

[Result]: 0,

" errmsg": "OK ",

" ext ":" ",

"Details": [

{

[Result]: 0,

" errmsg": "OK ",

[mobile phone]: "/kloc-0 1378888888",

"country code": "86",

" sid": "xxxxxxx ",

[Cost]: 1

},

{

[Result]: 0,

" errmsg": "OK ",

[mobile phone]: "/kloc-0 13788888889",

"country code": "86",

" sid": "xxxxxxx ",

[Cost]: 1

}

]

}

*/

$ random = $ this-& gt; util-& gt; get random();

$ curTime = time();

$ whole URL = $ this-& gt; Website. "? accesskey= "。 $ this-& gt; Access key. “& amprandom= "。 $ random

$ data = new \ stdClass();

$ data-& gt; Telephone = $ this-& gt;; util-& gt; phoneNumbersToArray($ nation code,$ phone numbers);

$ data-& gt; type = $ type

$ data-& gt; msg = $ msg

$ data-& gt; SIG = $ this-& gt; util-& gt; calculateSig($ this-& gt; secretkey,$random,$curTime,$ phone numbers);

$ data-& gt; time = $ curTime

$ data-& gt; extend = $ extend

$ data-& gt; ext = $ ext

return $ this-& gt; util-& gt; sendCurlPost($wholeUrl,$ data);

}

/**

* Specify the template group to send.

* Note that overseas SMS has no group sending function.

* @param string $nationCode country code, for example, 86 is China.

* @param array $phoneNumbers mobile phone number list without country code

* @param int $templId template Id

* @param array $params template parameter list, such as template {1}...{2}...{3}, then you need to bring three parameters.

* @param string $sign signature. If a string is filled in, the system will use the default signature.

* @param string $extend extension code, which can fill in the blanks.

* @param string $ext parameters returned by the server as they are can be filled in.

* @ returnstring JSON string {"result": xxxxx, "errmsg": "xxxxx "...}, please refer to the agreement document for the omitted contents.

*/

Function sendWithParam($nationCode, $phoneNumbers, $templId, $params, $sign = "",$extend = "",$ ext = ""{

/*

Request packet body

{

"Telephone": [

{

"country code": "86",

[Mobile phone]: "1378888888"

},

{

"country code": "86",

[Mobile phone]: "/kloc-0 13788888889"

}

],

"Sign": "Magic Cloud",

【TPL _ id】: 19,

" params": [

"Verification code",

" 1234",

"4"

],

" SIG ":" fdba 654 e 05 BC 0d 157967 13a 1a 1a 23 18c ",

[Time]: 1479888540,

"expansion": "",

" ext ":" "

}

Response inclusion

{

[Result]: 0,

" errmsg": "OK ",

" ext ":" ",

"Details": [

{

[Result]: 0,

" errmsg": "OK ",

[mobile phone]: "/kloc-0 1378888888",

"country code": "86",

" sid": "xxxxxxx ",

[Cost]: 1

},

{

[Result]: 0,

" errmsg": "OK ",

[mobile phone]: "/kloc-0 13788888889",

"country code": "86",

" sid": "xxxxxxx ",

[Cost]: 1

}

]

}

*/

$ random = $ this-& gt; util-& gt; get random();

$ curTime = time();

$ whole URL = $ this-& gt; Website. "? accesskey= "。 $ this-& gt; Access key. “& amprandom= "。 $ random

$ data = new \ stdClass();

$ data-& gt; Telephone = $ this-& gt;; util-& gt; phoneNumbersToArray($ nation code,$ phone numbers);

$ data-& gt; sign = $ sign

$ data-& gt; tpl _ id = $ templId

$ data-& gt; params = $ params

$ data-& gt; SIG = $ this-& gt; util-& gt; calculateSigForTemplAndPhoneNumbers(

$ this-& gt; secretkey,$random,$curTime,$ phone numbers);

$ data-& gt; time = $ curTime

$ data-& gt; extend = $ extend

$ data-& gt; ext = $ ext

return $ this-& gt; util-& gt; sendCurlPost($wholeUrl,$ data);

}

}

More welcome to pay attention to the cloud service-Magic Cloud Platform.

Official website:/