From 08be20420fd1e94a72a6797be86f698fd3a411d4 Mon Sep 17 00:00:00 2001 From: zhangweilai Date: Tue, 4 Dec 2018 17:21:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=85=BE=E8=AE=AF?= =?UTF-8?q?=E4=BA=91=E7=9F=AD=E4=BF=A1=E7=AD=BE=E5=90=8D=E5=92=8C=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E6=93=8D=E4=BD=9C=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SmsSign.php | 99 +++++++++++++++++++++++++++++++++++++++++++ src/SmsTemplate.php | 101 ++++++++++++++++++++++++++++++++++++++++++++ src/index.php | 5 ++- 3 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 src/SmsSign.php create mode 100644 src/SmsTemplate.php diff --git a/src/SmsSign.php b/src/SmsSign.php new file mode 100644 index 0000000..f7f9f8a --- /dev/null +++ b/src/SmsSign.php @@ -0,0 +1,99 @@ +url = "https://yun.tim.qq.com/v5/tlssmssvr/"; + $this->appid = $appid; + $this->appkey = $appkey; + $this->util = new SmsSenderUtil(); + } + + public function addSmsSign($text,$remark = '',$international = 0, $pic = '') + { + $this->url = $this->url.self::ADD_SIGN_URI; + $random = $this->util->getRandom(); + $curTime = time(); + $wholeUrl = $this->url . "?sdkappid=" . $this->appid . "&random=" . $random; + // 按照协议组织 post 包体 + $data = new \stdClass(); + $data->sig = $this->util->calculateSigForPuller($this->appkey, $random, $curTime); + $data->time = $curTime; + $data->text = $text; + $data->pic = $pic; + $data->international = $international; + $data->remark = $remark; + return $this->util->sendCurlPost($wholeUrl, $data); + } + + public function modSmsSign($sign_id,$text,$remark = '',$international = 0, $pic = '') + { + $this->url = $this->url.self::MOD_SIGN_URI; + $random = $this->util->getRandom(); + $curTime = time(); + $wholeUrl = $this->url . "?sdkappid=" . $this->appid . "&random=" . $random; + // 按照协议组织 post 包体 + $data = new \stdClass(); + $data->sig = $this->util->calculateSigForPuller($this->appkey, $random, $curTime); + $data->time = $curTime; + $data->text = $text; + $data->pic = $pic; + $data->sign_id = $sign_id; + $data->international = $international; + $data->remark = $remark; + return $this->util->sendCurlPost($wholeUrl, $data); + } + + public function delSmsSign($sign_id) + { + $this->url = $this->url.self::DEL_SIGN_URI; + $random = $this->util->getRandom(); + $curTime = time(); + $wholeUrl = $this->url . "?sdkappid=" . $this->appid . "&random=" . $random; + // 按照协议组织 post 包体 + $data = new \stdClass(); + $data->sig = $this->util->calculateSigForPuller($this->appkey, $random, $curTime); + $data->time = $curTime; + $data->sign_id = $sign_id; + return $this->util->sendCurlPost($wholeUrl, $data); + } + + public function getSmsSign($sign_id) + { + $this->url = $this->url.self::GET_SIGN_URI; + $random = $this->util->getRandom(); + $curTime = time(); + $wholeUrl = $this->url . "?sdkappid=" . $this->appid . "&random=" . $random; + // 按照协议组织 post 包体 + $data = new \stdClass(); + $data->sig = $this->util->calculateSigForPuller($this->appkey, $random, $curTime); + $data->time = $curTime; + $data->sign_id = $sign_id; + return $this->util->sendCurlPost($wholeUrl, $data); + } +} diff --git a/src/SmsTemplate.php b/src/SmsTemplate.php new file mode 100644 index 0000000..aedb885 --- /dev/null +++ b/src/SmsTemplate.php @@ -0,0 +1,101 @@ +url = "https://yun.tim.qq.com/v5/tlssmssvr/"; + $this->appid = $appid; + $this->appkey = $appkey; + $this->util = new SmsSenderUtil(); + } + + public function addSmsTemplate($text, $type, $remark = '',$international = 0, $title = '') + { + $this->url = $this->url . self::ADD_TEMPL_URI; + $random = $this->util->getRandom(); + $curTime = time(); + $wholeUrl = $this->url . "?sdkappid=" . $this->appid . "&random=" . $random; + // 按照协议组织 post 包体 + $data = new \stdClass(); + $data->sig = $this->util->calculateSigForPuller($this->appkey, $random, $curTime); + $data->time = $curTime; + $data->text = $text; + $data->title = $title; + $data->type = $type; + $data->international = $international; + $data->remark = $remark; + return $this->util->sendCurlPost($wholeUrl, $data); + } + + public function modSmsTemplate($tpl_id, $text, $type, $remark = '',$international = 0, $title = '') + { + $this->url = $this->url . self::MOD_TEMPL_URI; + $random = $this->util->getRandom(); + $curTime = time(); + $wholeUrl = $this->url . "?sdkappid=" . $this->appid . "&random=" . $random; + // 按照协议组织 post 包体 + $data = new \stdClass(); + $data->sig = $this->util->calculateSigForPuller($this->appkey, $random, $curTime); + $data->time = $curTime; + $data->text = $text; + $data->type = $type; + $data->title = $title; + $data->tpl_id = $tpl_id; + $data->international = $international; + $data->remark = $remark; + return $this->util->sendCurlPost($wholeUrl, $data); + } + + public function delSmsTemplate($tpl_id) + { + $this->url = $this->url . self::DEL_TEMPL_URI; + $random = $this->util->getRandom(); + $curTime = time(); + $wholeUrl = $this->url . "?sdkappid=" . $this->appid . "&random=" . $random; + // 按照协议组织 post 包体 + $data = new \stdClass(); + $data->sig = $this->util->calculateSigForPuller($this->appkey, $random, $curTime); + $data->time = $curTime; + $data->tpl_id = $tpl_id; + return $this->util->sendCurlPost($wholeUrl, $data); + } + + public function getSmsTemplate($tpl_id) + { + $this->url = $this->url.self::GET_TEMPL_URI; + $random = $this->util->getRandom(); + $curTime = time(); + $wholeUrl = $this->url . "?sdkappid=" . $this->appid . "&random=" . $random; + // 按照协议组织 post 包体 + $data = new \stdClass(); + $data->sig = $this->util->calculateSigForPuller($this->appkey, $random, $curTime); + $data->time = $curTime; + $data->tpl_id = $tpl_id; + return $this->util->sendCurlPost($wholeUrl, $data); + } +} diff --git a/src/index.php b/src/index.php index d3f64df..755e0a1 100644 --- a/src/index.php +++ b/src/index.php @@ -10,4 +10,7 @@ require_once __DIR__ . "/VoiceFileUploader.php"; require_once __DIR__ . "/FileVoiceSender.php"; -require_once __DIR__ . "/TtsVoiceSender.php"; \ No newline at end of file +require_once __DIR__ . "/TtsVoiceSender.php"; + +require_once __DIR__ . "/SmsSign.php"; +require_once __DIR__ . "/SmsTemplate.php"; \ No newline at end of file From 7f33d264c60db33e8f3160cf80860a0d0a605e3e Mon Sep 17 00:00:00 2001 From: zhangweilai Date: Wed, 5 Dec 2018 11:55:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SmsSign.php | 35 ++++++++++++++++++++++++++++++++--- src/SmsTemplate.php | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/SmsSign.php b/src/SmsSign.php index f7f9f8a..7d15b03 100644 --- a/src/SmsSign.php +++ b/src/SmsSign.php @@ -34,7 +34,16 @@ public function __construct($appid, $appkey) $this->util = new SmsSenderUtil(); } - public function addSmsSign($text,$remark = '',$international = 0, $pic = '') + /** + * 添加签名 + * + * @param string $text 签名内容,不带【】,例如:【腾讯科技】这个签名,这里填"腾讯科技" + * @param string $remark 签名备注,比如申请原因,使用场景等 + * @param int $international 0表示国内短信,1表示海外短信,默认为0 + * @param string $pic 签名对应的资质证明图片进行 base64 编码格式转换后的字符串base64 编码格式工具: http://base64.xpcha.com/indexie.php ,注意编译后去掉字符串前面的前缀:“data:image/jpeg;base64,” + * @return string + */ + public function addSmsSign($text, $remark = '', $international = 0, $pic = '') { $this->url = $this->url.self::ADD_SIGN_URI; $random = $this->util->getRandom(); @@ -51,7 +60,16 @@ public function addSmsSign($text,$remark = '',$international = 0, $pic = '') return $this->util->sendCurlPost($wholeUrl, $data); } - public function modSmsSign($sign_id,$text,$remark = '',$international = 0, $pic = '') + /** + * 修改签名 + * + * @param int $sign_id 待修改的签名对应的签名 id + * @param string $text 新的签名内容,不带【】,例如:改为【腾讯科技】这个签名,这里填"腾讯科技" + * @param string $remark 新的签名备注,比如申请原因,使用场景等 + * @param string $pic 签名对应的资质证明图片进行 base64 编码格式转换后的字符串base64 编码格式工具: http://base64.xpcha.com/indexie.php ,注意编译后去掉字符串前面的前缀:“data:image/jpeg;base64,” + * @return string + */ + public function modSmsSign($sign_id, $text, $remark = '', $pic = '') { $this->url = $this->url.self::MOD_SIGN_URI; $random = $this->util->getRandom(); @@ -64,11 +82,16 @@ public function modSmsSign($sign_id,$text,$remark = '',$international = 0, $pic $data->text = $text; $data->pic = $pic; $data->sign_id = $sign_id; - $data->international = $international; $data->remark = $remark; return $this->util->sendCurlPost($wholeUrl, $data); } + /** + * 删除签名 + * + * @param array $sign_id 签名 id,也可以通过值指定一个 "sign_id":123 + * @return string + */ public function delSmsSign($sign_id) { $this->url = $this->url.self::DEL_SIGN_URI; @@ -83,6 +106,12 @@ public function delSmsSign($sign_id) return $this->util->sendCurlPost($wholeUrl, $data); } + /** + * 短信签名状态查询 + * + * @param array $sign_id 签名 id,也可以通过值指定一个 "sign_id":123 + * @return string + */ public function getSmsSign($sign_id) { $this->url = $this->url.self::GET_SIGN_URI; diff --git a/src/SmsTemplate.php b/src/SmsTemplate.php index aedb885..364da77 100644 --- a/src/SmsTemplate.php +++ b/src/SmsTemplate.php @@ -34,7 +34,17 @@ public function __construct($appid, $appkey) $this->util = new SmsSenderUtil(); } - public function addSmsTemplate($text, $type, $remark = '',$international = 0, $title = '') + /** + * 添加短信模板 + * + * @param string $text 模板内容 + * @param int $type 短信类型,Enum{0:普通短信, 1:营销短信} + * @param string $remark 模板备注,比如申请原因,使用场景等 + * @param int $international 0表示国内短信,1表示海外短信,默认为0 + * @param string $title 模板名称 + * @return string + */ + public function addSmsTemplate($text, $type, $remark = '', $international = 0, $title = '') { $this->url = $this->url . self::ADD_TEMPL_URI; $random = $this->util->getRandom(); @@ -52,6 +62,17 @@ public function addSmsTemplate($text, $type, $remark = '',$international = 0, $t return $this->util->sendCurlPost($wholeUrl, $data); } + /** + * 修改短信模板 + * + * @param array $tpl_id 模板id + * @param string $text 新的模板内容 + * @param int $type 短信类型,Enum{0:普通短信, 1:营销短信} + * @param string $remark 新的模板备注,比如申请原因,使用场景等 + * @param int $international 0表示国内短信,1表示海外短信,默认为0 + * @param string $title 新的模板名称 + * @return string + */ public function modSmsTemplate($tpl_id, $text, $type, $remark = '',$international = 0, $title = '') { $this->url = $this->url . self::MOD_TEMPL_URI; @@ -71,6 +92,12 @@ public function modSmsTemplate($tpl_id, $text, $type, $remark = '',$internationa return $this->util->sendCurlPost($wholeUrl, $data); } + /** + * 删除短信模板 + * + * @param array $tpl_id 待删除的模板 id 数组 + * @return string + */ public function delSmsTemplate($tpl_id) { $this->url = $this->url . self::DEL_TEMPL_URI; @@ -85,6 +112,12 @@ public function delSmsTemplate($tpl_id) return $this->util->sendCurlPost($wholeUrl, $data); } + /** + * 短信模板状态查询 + * + * @param array $tpl_id 待删除的模板 id 数组 + * @return string + */ public function getSmsTemplate($tpl_id) { $this->url = $this->url.self::GET_TEMPL_URI;