123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- <?php
- class SMSClient
- {
- /**
- * 网关地址
- */
- public $url;
- /**
- * 序列号,请通过亿美销售人员获取
- */
- public $serialNumber;
- /**
- * 密码,请通过亿美销售人员获取
- */
- public $password;
- /**
- * 登录后所持有的SESSION KEY,即可通过login方法时创建
- */
- public $sessionKey;
- /**
- * webservice客户端
- */
- public $soap;
- /**
- * 默认命名空间
- */
- public $namespace = 'http://sdkhttp.eucp.b2m.cn/';
- /**
- * 往外发送的内容的编码,默认为 GBK
- */
- public $outgoingEncoding = 'GBK';
- /**
- * 往外发送的内容的编码,默认为 GBK
- */
- public $incomingEncoding = '';
-
- /**
- * @param string $url 网关地址
- * @param string $serialNumber 序列号,请通过亿美销售人员获取
- * @param string $password 密码,请通过亿美销售人员获取
- * @param string $sessionKey 登录后所持有的SESSION KEY,即可通过login方法时创建
- *
- * @param string $proxyhost 可选,代理服务器地址,默认为 false ,则不使用代理服务器
- * @param string $proxyport 可选,代理服务器端口,默认为 false
- * @param string $proxyusername 可选,代理服务器用户名,默认为 false
- * @param string $proxypassword 可选,代理服务器密码,默认为 false
- * @param string $timeout 连接超时时间,默认0,为不超时
- * @param string $response_timeout 信息返回超时时间,默认30
- *
- *
- */
- public function SMSClient($url, $serialNumber, $password, $sessionKey = '', $proxyhost = false, $proxyport = false, $proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30)
- {
- $this->url = $url;
- $this->serialNumber = $serialNumber;
- $this->password = $password;
-
- if ($sessionKey != '') {
- $this->sessionKey = $sessionKey;
- }
-
- $this->soap = new nusoap_client($url, false, $proxyhost, $proxyport, $proxyusername, $proxypassword, $timeout, $response_timeout);
- $this->soap->soap_defencoding = $this->outgoingEncoding;
- $this->soap->decode_utf8 = false;
- }
-
- /**
- * 设置发送内容 的字符编码
- * @param string $outgoingEncoding 发送内容字符集编码
- */
- public function setOutgoingEncoding($outgoingEncoding)
- {
- $this->outgoingEncoding = $outgoingEncoding;
- $this->soap->soap_defencoding = $this->outgoingEncoding;
- }
-
- /**
- * 设置接收内容 的字符编码
- * @param string $incomingEncoding 接收内容字符集编码
- */
- public function setIncomingEncoding($incomingEncoding)
- {
- $this->incomingEncoding = $incomingEncoding;
- $this->soap->xml_encoding = $this->incomingEncoding;
- }
-
- public function setNameSpace($ns)
- {
- $this->namespace = $ns;
- }
-
- public function getSessionKey()
- {
- return $this->sessionKey;
- }
-
- public function getError()
- {
- return $this->soap->getError();
- }
-
- /**
- *
- * 指定一个 session key 并 进行登录操作
- *
- * @param string $sessionKey 指定一个session key
- * @return int 操作结果状态码
- *
- * 代码如:
- *
- * $sessionKey = $client->generateKey(); //产生随机6位数 session key
- *
- * if ($client->login($sessionKey)==0)
- * {
- * //登录成功,并且做保存 $sessionKey 的操作,用于以后相关操作的使用
- * }else{
- * //登录失败处理
- * }
- *
- *
- */
- public function login($sessionKey = '')
- {
- if ($sessionKey != '') {
- $this->sessionKey = $sessionKey;
- }
-
- $params = array('arg0' => $this->serialNumber, 'arg1' => $this->sessionKey, 'arg2' => $this->password);
- $result = $this->soap->call('registEx', $params, $this->namespace);
- return $result;
- }
-
- /**
- * 注销操作 (注:此方法必须为已登录状态下方可操作)
- *
- * @return int 操作结果状态码
- *
- * 之前保存的sessionKey将被作废
- * 如需要,可重新login
- */
- public function logout()
- {
- $params = array('arg0' => $this->serialNumber, 'arg1' => $this->sessionKey);
- print_r($params);
- $result = $this->soap->call('logout', $params, $this->namespace);
- return $result;
- }
-
- /**
- * 获取版本信息
- * @return string 版本信息
- */
- public function getVersion()
- {
- $result = $this->soap->call('getVersion', array(), $this->namespace);
- return $result;
- }
-
- /**
- * 短信发送 (注:此方法必须为已登录状态下方可操作)
- *
- * @param array $mobiles 手机号, 如 array('159xxxxxxxx'),如果需要多个手机号群发,如 array('159xxxxxxxx','159xxxxxxx2')
- * @param string $content 短信内容
- * @param string $sendTime 定时发送时间,格式为 yyyymmddHHiiss, 即为 年年年年月月日日时时分分秒秒,例如:20090504111010 代表2009年5月4日 11时10分10秒
- * 如果不需要定时发送,请为'' (默认)
- *
- * @param string $addSerial 扩展号, 默认为 ''
- * @param string $charset 内容字符集, 默认GBK
- * @param int $priority 优先级, 默认5
- * @return int 操作结果状态码
- */
- public function sendSMS($mobiles = array(), $content, $sendTime = '', $addSerial = '', $charset = 'GBK', $priority = 5)
- {
- $params = array('arg0' => $this->serialNumber, 'arg1' => $this->sessionKey, 'arg2' => $sendTime, 'arg4' => $content, 'arg5' => $addSerial, 'arg6' => $charset, 'arg7' => $priority);
-
- foreach ($mobiles as $mobile) {
- array_push($params, new soapval('arg3', false, $mobile));
- }
-
- $result = $this->soap->call('sendSMS', $params, $this->namespace);
- return $result;
- }
-
- /**
- * 余额查询 (注:此方法必须为已登录状态下方可操作)
- * @return double 余额
- */
- public function getBalance()
- {
- $params = array('arg0' => $this->serialNumber, 'arg1' => $this->sessionKey);
- $result = $this->soap->call('getBalance', $params, $this->namespace);
- return $result;
- }
-
- /**
- * 取消短信转发 (注:此方法必须为已登录状态下方可操作)
- * @return int 操作结果状态码
- */
- public function cancelMOForward()
- {
- $params = array('arg0' => $this->serialNumber, 'arg1' => $this->sessionKey);
- $result = $this->soap->call('cancelMOForward', $params, $this->namespace);
- return $result;
- }
-
- /**
- * 短信充值 (注:此方法必须为已登录状态下方可操作)
- * @param string $cardId [充值卡卡号]
- * @param string $cardPass [密码]
- * @return int 操作结果状态码
- *
- * 请通过亿美销售人员获取 [充值卡卡号]长度为20内 [密码]长度为6
- */
- public function chargeUp($cardId, $cardPass)
- {
- $params = array('arg0' => $this->serialNumber, 'arg1' => $this->sessionKey, 'arg2' => $cardId, 'arg3' => $cardPass);
- $result = $this->soap->call('chargeUp', $params, $this->namespace);
- return $result;
- }
-
- /**
- * 查询单条费用 (注:此方法必须为已登录状态下方可操作)
- * @return double 单条费用
- */
- public function getEachFee()
- {
- $params = array('arg0' => $this->serialNumber, 'arg1' => $this->sessionKey);
- $result = $this->soap->call('getEachFee', $params, $this->namespace);
- return $result;
- }
-
- /**
- * 得到上行短信 (注:此方法必须为已登录状态下方可操作)
- *
- * @return array 上行短信列表, 每个元素是Mo对象, Mo对象内容参考最下面
- *
- *
- * 如:
- *
- * $moResult = $client->getMO();
- * echo "返回数量:".count($moResult);
- * foreach($moResult as $mo)
- * {
- * //$mo 是位于 Client.php 里的 Mo 对象
- * echo "发送者附加码:".$mo->getAddSerial();
- * echo "接收者附加码:".$mo->getAddSerialRev();
- * echo "通道号:".$mo->getChannelnumber();
- * echo "手机号:".$mo->getMobileNumber();
- * echo "发送时间:".$mo->getSentTime();
- * echo "短信内容:".$mo->getSmsContent();
- * }
- *
- *
- */
- public function getMO()
- {
- $ret = array();
- $params = array('arg0' => $this->serialNumber, 'arg1' => $this->sessionKey);
- $result = $this->soap->call('getMO', $params, $this->namespace);
- if (is_array($result) && 0 < count($result)) {
- if (is_array($result[0])) {
- foreach ($result as $moArray) {
- $ret[] = new Mo($moArray);
- }
- }
- else {
- $ret[] = new Mo($result);
- }
- }
-
- return $ret;
- }
-
- /**
- * 得到状态报告 (注:此方法必须为已登录状态下方可操作)
- * @return array 状态报告列表, 一次最多取5个
- */
- public function getReport()
- {
- $params = array('arg0' => $this->serialNumber, 'arg1' => $this->sessionKey);
- $result = $this->soap->call('getReport', $params, $this->namespace);
- return $result;
- }
-
- /**
- * 企业注册 [邮政编码]长度为6 其它参数长度为20以内
- *
- * @param string $eName 企业名称
- * @param string $linkMan 联系人姓名
- * @param string $phoneNum 联系电话
- * @param string $mobile 联系手机号码
- * @param string $email 联系电子邮件
- * @param string $fax 传真号码
- * @param string $address 联系地址
- * @param string $postcode 邮政编码
- *
- * @return int 操作结果状态码
- *
- */
- public function registDetailInfo($eName, $linkMan, $phoneNum, $mobile, $email, $fax, $address, $postcode)
- {
- $params = array('arg0' => $this->serialNumber, 'arg1' => $this->sessionKey, 'arg2' => $eName, 'arg3' => $linkMan, 'arg4' => $phoneNum, 'arg5' => $mobile, 'arg6' => $email, 'arg7' => $fax, 'arg8' => $address, 'arg9' => $postcode);
- $result = $this->soap->call('registDetailInfo', $params, $this->namespace);
- return $result;
- }
-
- /**
- * 修改密码 (注:此方法必须为已登录状态下方可操作)
- * @param string $newPassword 新密码
- * @return int 操作结果状态码
- */
- public function updatePassword($newPassword)
- {
- $params = array('arg0' => $this->serialNumber, 'arg1' => $this->sessionKey, 'arg2' => $this->password, 'arg3' => $newPassword);
- $result = $this->soap->call('serialPwdUpd', $params, $this->namespace);
- return $result;
- }
-
- /**
- *
- * 短信转发
- * @param string $forwardMobile 转发的手机号码
- * @return int 操作结果状态码
- *
- */
- public function setMOForward($forwardMobile)
- {
- $params = array('arg0' => $this->serialNumber, 'arg1' => $this->sessionKey, 'arg2' => $forwardMobile);
- $result = $this->soap->call('setMOForward', $params, $this->namespace);
- return $result;
- }
-
- /**
- * 短信转发扩展
- * @param array $forwardMobiles 转发的手机号码列表, 如 array('159xxxxxxxx','159xxxxxxxx');
- * @return int 操作结果状态码
- */
- public function setMOForwardEx($forwardMobiles = array())
- {
- $params = array('arg0' => $this->serialNumber, 'arg1' => $this->sessionKey);
-
- foreach ($forwardMobiles as $mobile) {
- array_push($params, new soapval('arg2', false, $mobile));
- }
-
- $result = $this->soap->call('setMOForwardEx', $params, $this->namespace);
- return $result;
- }
-
- /**
- * 生成6位随机数
- */
- public function generateKey()
- {
- return rand(100000, 999999);
- }
- }
-
- class Mo
- {
- /**
- * 发送者附加码
- */
- public $addSerial;
- /**
- * 接收者附加码
- */
- public $addSerialRev;
- /**
- * 通道号
- */
- public $channelnumber;
- /**
- * 手机号
- */
- public $mobileNumber;
- /**
- * 发送时间
- */
- public $sentTime;
- /**
- * 短信内容
- */
- public $smsContent;
-
- public function Mo(&$ret = array())
- {
- $this->addSerial = $ret[addSerial];
- $this->addSerialRev = $ret[addSerialRev];
- $this->channelnumber = $ret[channelnumber];
- $this->mobileNumber = $ret[mobileNumber];
- $this->sentTime = $ret[sentTime];
- $this->smsContent = $ret[smsContent];
- }
-
- public function getAddSerial()
- {
- return $this->addSerial;
- }
-
- public function getAddSerialRev()
- {
- return $this->addSerialRev;
- }
-
- public function getChannelnumber()
- {
- return $this->channelnumber;
- }
-
- public function getMobileNumber()
- {
- return $this->mobileNumber;
- }
-
- public function getSentTime()
- {
- return $this->sentTime;
- }
-
- public function getSmsContent()
- {
- return $this->smsContent;
- }
- }
-
- require_once dirname(__FILE__) . '/nusoaplib/nusoap.php';
-
- ?>
|