Joke Collection Website - Blessing messages - Universal authentication-free SMS interface, more than 100 messages from a single number per day

Universal authentication-free SMS interface, more than 100 messages from a single number per day

The following introduces the SMS php interface of the moduyun platform.

Link: www.moduyun.com

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

namespace Moduyun\Sms;

require_once('SmsSenderUtil .php');

class SmsSingleSender {

var $url;

var $accesskey;

var $secretkey;

p>

var $util;

function __construct($accesskey, $secretkey) {

$this->url = "/sms/v1/sendsinglesms";

p>

$this->accesskey =? $accesskey;

$this->secretkey = $secretkey;

$this->util = new SmsSenderUtil();< /p>

}

/**

* Ordinary single message, clearly specify the content. If there are multiple signatures, please add them to the message 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, such as 86 For China

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

* @param string $msg Information content must be consistent with the applied template format, otherwise an error will be returned

* @param string $extend extension code, blank string can be filled in

* @param string $ext parameter returned by the server as it is, blank string can be filled in

* @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... }, please refer to the protocol document for omitted content

*/

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

/*

Request package body

{

"tel": {

"nationcode": "86",

"mobile": "13788888888"

},

"type": 0,

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

"sig": "fdba654e05bc0d15796713a1a1a2318c",

"time": 1479888540,

"extend": "",

"ext": ""

}

Response packet body

{

"result": 0,

"errmsg": "OK",

"ext": "",

"sid": "xxxxxxx",

"fee": 1

}< /p>

*/

$random = $this->util->getRandom();

$curTime = time();

$wholeUrl = $this->url . "?accesskey=" . $this->accesskey . "&random=" . $random;

// Organize the post package body according to the protocol

$data = new \stdClass();

$tel = new \stdClass();

$tel->nationcode = "".$nationCode;

< p> $tel->mobile = "".$phoneNumber;

$data->tel = $tel;

$data->type = (int)$type;< /p>

$data->msg = $msg;

$data->sig = hash("sha256",

"secretkey=".$this-> secretkey."&random=".$random."&time=".$curTime."&mobile=".$phoneNumber, FALSE);

$data->time = $curTime;

< p> $data->extend = $extend;

$data->ext = $ext;

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

}

/**

* Specify template single send

* @param string $nationCode country code, such as 86 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 you fill in the blank string, the system will use the default Signature

* @param string $extend extension code, blank string can be filled in

* @param string $ext parameter returned by the server as it is, blank string can be filled in

* @return string json string { "result": xxxxx, "errmsg": "xxxxxx"? ... }, please refer to the protocol document for omitted content

*/

function sendWith

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

/*

Request package body

{

"tel": {

"nationcode": "86",

"mobile": "13788888888"

},

"sign": "Moduyun",

"tpl_id": 19,

"params" : [

"Verification code",

"1234",

"4"

],

"sig": "fdba654e05bc0d15796713a1a1a2318c",

"time": 1479888540,

"extend": "",

"ext": ""< /p>

}

Response packet body

{

"result": 0,

"errmsg": " OK",

"ext": "",

"sid": "xxxxxxx",

"fee": 1

}

*/

$random = $this->util->getRandom();

$curTime = time();

$wholeUrl = $this->url . "?sdkaccesskey=" . $this->accesskey . "&random=" . $random;

// Organize the post package body according to the protocol

$data = new \stdClass();

$tel = new \stdClass();

$tel->nationcode = "".$nationCode;

p>

$tel->mobile = "".$phoneNumber;

$data->tel = $tel;

$data->sig = $this-> util->calculateSigForTempl($this->secretkey, $random, $curTime, $phoneNumber);

$data->tpl_id = $templId;

$data->params = $params;

$data->sign = $sign;

$data->time = $curTime;

$data->extend = $extend ;

$data->ext = $ext;

return $this->util->

;sendCurlPost($wholeUrl, $data);

}

}

class SmsMultiSender {

var $url;

var $accesskey;

var $secretkey;

var $util;

function __construct($accesskey, $secretkey) {

$this->url = "/sms/v1/sendsinglesms";

$this->accesskey =? $accesskey;

$this->secretkey = $ secretkey;

$this->util = new SmsSenderUtil();

}

/**

* Ordinary group sending, clear Specify the content. If there are multiple signatures, please add them to the message content in the form of , otherwise the system will use the default signature

* Note that overseas SMS does not have a group sending function

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

* @param string $nationCode country code, such as 86 is China

* @param string $phoneNumbers No List of mobile phone numbers with country code

* @param string $msg Information content must be consistent with the applied template format, otherwise an error will be returned

* @param string $extend extension code , a blank string can be filled in

* @param string $ext The parameter returned by the server as it is, a blank string can be filled in

* @return string json string { "result": xxxxx, "errmsg" : "xxxxxx" ... }, please refer to the protocol document for omitted content

*/

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

/*

Request package body

{

"tel": [< /p>

{

"nationcode": "86",

"mobile": "13788888888"

},

< p> {

"nationcode": "86",

"mobile": "13788888889"

}

],< /p>

"type": 0,

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

"sig": "fdba654e05bc0d15796713a1a1a2318c",

"time": 1479888540,

"extend": "",

"ext": ""

}

Response packet body

{

"result": 0,

< p> "errmsg": "OK",

"ext": "",

"detail": [

{

"result": 0,

"errmsg": "OK",

"mobile": "13788888888",

"nationcode": "86 ",

"sid": "xxxxxxx",

"fee": 1

},

{

"result": 0,

"errmsg": "OK",

"mobile": "13788888889",

"nationcode": "86",

"sid": "xxxxxxx",

"fee": 1

}

]

}

*/

$random = $this->util->getRandom();

$curTime = time();< /p>

$wholeUrl = $this->url . "?accesskey=" . $this->accesskey . "&random=" . $random;

$data = new \stdClass() ;

$data->tel = $this->util->phoneNumbersToArray($nationCode, $phoneNumbers);

$data->type = $type;

$data->msg = $msg;

$data->sig = $this->util->calculateSig($this->secretkey, $random, $curTime, $phoneNumbers);

$data->time = $curTime;

$data->extend = $extend;

$data->ext = $ext;

p>

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

}

/**

* Specify template Group sending

* Note that overseas SMS does not have group sending function

* @param string $nationCode country code, such as 86 for China

* @param array $phoneNumbers without List of mobile phone numbers with country codes

* @param int $templId template id

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

* @param string $sign signature, if you fill in the blank string, the system will use the default signature

* @param string $extend extension code, you can fill in the blank string

< p> * @param string $ext Parameters returned by the server as they are, blank strings can be filled in

* @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... }, For omitted content, please refer to the protocol document

*/

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

/*

Request package body

{

"tel": [

{

"nationcode": "86",

"mobile": "13788888888"

},

{

"nationcode": "86",

"mobile": "13788888889"

}

],

"sign": "Moduyun",

"tpl_id": 19,

"params": [

"Verification code",

p>

"1234",

"4"

],

"sig": "fdba654e05bc0d15796713a1a1a2318c",

"time": 1479888540,

"extend": "",

"ext": ""

}

Response packet Body

{

"result": 0,

"errmsg": "OK",

"ext": "" ,

"detail": [

{

"result": 0,

"errmsg": "OK",< /p>

"mobile": "13788888888",

"nationcode": "86",

"sid": "xxxxxxx",

"fee": 1

},

{

"result": 0,

"errmsg": "OK" ,

"mobile": "13788888889",

<

p> "nationcode": "86",

"sid": "xxxxxxx",

"fee": 1

}

< p> ]

}

*/

$random = $this->util->getRandom();

$curTime = time();

$wholeUrl = $this->url . "?accesskey=" . $this->accesskey . "&random=" . $random;

$data = new \stdClass();

$data->tel = $this->util->phoneNumbersToArray($nationCode, $phoneNumbers);

$data->sign = $ sign;

$data->tpl_id = $templId;

$data->params = $params;

$data->sig = $this- >util->calculateSigForTemplAndPhoneNumbers(

$this->secretkey, $random, $curTime, $phoneNumbers);

$data->time = $curTime;

< p> $data->extend = $extend;

$data->ext = $ext;

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

}

}

For more, welcome to pay attention to the cloud service-moduyun platform

Official website: /