Joke Collection Website - Public benefit messages - Short message interface batch

Short message interface batch

Let's introduce the short message php interface of Modu cloud platform. Link: www.moduyun.com

//Applicable to php5.3 and php5.6.

Namespace Moduyun \ Sms

require _ once(‘smssenderutil . PHP‘);

SmsSingleSender class {

var $ url

var $ accesskey

var $ secretkey

var $ util

function _ _ construct($ access key,$ secret key ){

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

$ this-& gt; accesskey =? $ accesskey

$ this-& gt; secretkey = $ secretkey

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

}

/**

* ordinary single issue, clearly specify the content. If there are multiple signatures, please add them to the information content in the form of, 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 scheme file for the omitted contents.

*/

Function send ($type, $nationCode, $phoneNumber, $msg, $extend = "",$ ext = "{

/*

Request packet body

{

"Telephone": {

"country code": "86",

[Mobile phone]: "137888888"

},

[Type]: 0,

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

“SIG“:“fdba 654 e 05 bc0d 157967 13a 1a 1a 23 18c“,

[Time]: 1479888540,

"expand": ",

“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 \ STD class();

$ tel-& gt; Country code = "". $ nationCode

$ tel-& gt; Mobile phone = "". $ phone number;

$ data-& gt; tel = $ tel

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

$ data-& gt; msg = $ msg

$ data-& gt; SIG = hash(“sha 256“,

“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($ whole URL,$ 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.

*/

The function sendWithParam($ nation code, $ phoneNumber, $templId = 0, $params, $sign = ",$extend =", $ ext = "{

/*

Request packet body

{

"Telephone": {

"country code": "86",

[Mobile phone]: "137888888"

},

"Zheng": "Mo Deyun",

【TPL _ id】: 19,

“params“:【

"verification code",

" 1234",

"4"

],

“SIG“:“fdba 654 e 05 bc0d 157967 13a 1a 1a 23 18c“,

[Time]: 1479888540,

"expand": ",

“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 \ STD class();

$ tel-& gt; Country code = "". $ nationCode

$ tel-& gt; Mobile phone = "". $ phone number;

$ 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($ whole URL,$ data);

}

}

SmsMultiSender class {

var $ url

var $ accesskey

var $ secretkey

var $ util

function _ _ construct($ access key,$ secret key ){

$ 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 in the form of, 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 scheme file for the omitted contents.

*/

Function send ($type, $nationCode, $phoneNumbers, $msg, $extend = "",$ ext = "{

/*

Request packet body

{

"Telephone": 【

{

"country code": "86",

[Mobile phone]: "137888888"

},

{

"country code": "86",

[Mobile phone]: "1378888889"

}

],

[Type]: 0,

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

“SIG“:“fdba 654 e 05 bc0d 157967 13a 1a 1a 23 18c“,

[Time]: 1479888540,

"expand": ",

“ext“:““

}

Response inclusion

{

[Result]: 0,

"errmsg": "ok",

“ext“:“,

"Details": 【

{

[Result]: 0,

"errmsg": "ok",

[Mobile phone]: "137888888",

"country code": "86",

“sid“:“xxxxxxx“,

[Cost]: 1

},

{

[Result]: 0,

"errmsg": "ok",

[Mobile phone]: "1378888889",

"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($ whole URL,$ 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 scheme file for the omitted contents.

*/

The function sendWithParam($ nation code, $phoneNumbers, $templId, $params, $sign = "",$extend = "",$ext = "")

/*

Request packet body

{

"Telephone": 【

{

"country code": "86",

[Mobile phone]: "137888888"

},

{

"country code": "86",

[Mobile phone]: "1378888889"

}

],

"Zheng": "Mo Deyun",

【TPL _ id】: 19,

“params“:【

"verification code",

" 1234",

"4"

],

“SIG“:“fdba 654 e 05 bc0d 157967 13a 1a 1a 23 18c“,

[Time]: 1479888540,

"expand": ",

“ext“:““

}

Response inclusion

{

[Result]: 0,

"errmsg": "ok",

“ext“:“,

"Details": 【

{

[Result]: 0,

"errmsg": "ok",

[Mobile phone]: "137888888",

"country code": "86",

“sid“:“xxxxxxx“,

[Cost]: 1

},

{

[Result]: 0,

"errmsg": "ok",

[Mobile phone]: "1378888889",

"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($ whole URL,$ data);

}

}

Learn more and welcome to pay attention to the cloud service-Magic Cloud Platform.

Official website:/