/** * 创建client实例 */ function &getSingleClient($smownerid) { global $current_user; static $client = false; if ($client === false) { global $adb; $gwUrl = 'http://sdkhttp.eucp.b2m.cn/sdk/SDKService'; $sql = "select * from ec_messageaccount where smownerid='" . $smownerid . "'"; $result = $adb->query($sql); $serialNumber = trim($adb->query_result($result, 0, 'username')); $password = trim($adb->query_result($result, 0, 'password')); //$password='******'; $sessionKey = $password; $connectTimeOut = 5; /** * 远程信息读取超时时间,单位为秒 */ $readTimeOut = 10; /** $proxyhost 可选,代理服务器地址,默认为 false ,则不使用代理服务器 $proxyport 可选,代理服务器端口,默认为 false $proxyusername 可选,代理服务器用户名,默认为 false $proxypassword 可选,代理服务器密码,默认为 false */ $proxyhost = false; $proxyport = false; $proxyusername = false; $proxypassword = false; $client = new Client($gwUrl, $serialNumber, $password, $sessionKey, $proxyhost, $proxyport, $proxyusername, $proxypassword, $connectTimeOut, $readTimeOut); $client->setOutgoingEncoding("UTF-8"); } return $client; }
/** * 亿美短信发送接口 * @param unknown $mobile 手机号 * @param unknown $content 短信内容 */ private function _sendEmay($mobile, $content) { set_time_limit(0); define('SCRIPT_ROOT', BASE_DATA_PATH . '/api/emay/'); require_once SCRIPT_ROOT . 'include/Client.php'; /** * 网关地址 */ $gwUrl = C('sms.gwUrl'); /** * 序列号,请通过亿美销售人员获取 */ $serialNumber = C('sms.serialNumber'); /** * 密码,请通过亿美销售人员获取 */ $password = C('sms.password'); /** * 登录后所持有的SESSION KEY,即可通过login方法时创建 */ $sessionKey = C('sms.sessionKey'); /** * 连接超时时间,单位为秒 */ $connectTimeOut = 2; /** * 远程信息读取超时时间,单位为秒 */ $readTimeOut = 10; /** $proxyhost 可选,代理服务器地址,默认为 false ,则不使用代理服务器 $proxyport 可选,代理服务器端口,默认为 false $proxyusername 可选,代理服务器用户名,默认为 false $proxypassword 可选,代理服务器密码,默认为 false */ $proxyhost = false; $proxyport = false; $proxyusername = false; $proxypassword = false; $client = new Client($gwUrl, $serialNumber, $password, $sessionKey, $proxyhost, $proxyport, $proxyusername, $proxypassword, $connectTimeOut, $readTimeOut); /** * 发送向服务端的编码,如果本页面的编码为GBK,请使用GBK */ $client->setOutgoingEncoding("UTF-8"); $statusCode = $client->login(); if ($statusCode != null && $statusCode == "0") { } else { //登录失败处理 // echo "登录失败,返回:".$statusCode;exit; } $statusCode = $client->sendSMS(array($mobile), $content); if ($statusCode != null && $statusCode == "0") { return true; } else { return false; print_R($statusCode); echo "处理状态码:" . $statusCode; } }
$readTimeOut = 10; /** $proxyhost 可选,代理服务器地址,默认为 false ,则不使用代理服务器 $proxyport 可选,代理服务器端口,默认为 false $proxyusername 可选,代理服务器用户名,默认为 false $proxypassword 可选,代理服务器密码,默认为 false */ $proxyhost = false; $proxyport = false; $proxyusername = false; $proxypassword = false; $client = new Client($gwUrl, $serialNumber, $password, $sessionKey, $proxyhost, $proxyport, $proxyusername, $proxypassword, $connectTimeOut, $readTimeOut); /** * 发送向服务端的编码,如果本页面的编码为GBK,请使用GBK */ $client->setOutgoingEncoding("UTF-8"); // login(); //激活序列号 // updatePassword(); //修改密码 // logout(); //注销序列号 // registDetailInfo();//注册企业信息 // getEachFee(); //得到单价 // getMO(); //接收短信 // getVersion(); //得到版本号 sendSMS(); //发送短信 // getBalance(); //得到余额 // chargeUp(); //充值 //---------------------------------------------------------------------- // 注: // 1. 下面是各接口的使用用例,Client.php 还有每一个接口更详细的参数说明 // 2. 凡是返回 $statusCode 的, 都是相关操作的状态码
$readTimeOut = 10; /** $proxyhost 可选,代理服务器地址,默认为 false ,则不使用代理服务器 $proxyport 可选,代理服务器端口,默认为 false $proxyusername 可选,代理服务器用户名,默认为 false $proxypassword 可选,代理服务器密码,默认为 false */ $proxyhost = false; $proxyport = false; $proxyusername = false; $proxypassword = false; $client = new Client($gwUrl, $serialNumber, $password, $sessionKey, $proxyhost, $proxyport, $proxyusername, $proxypassword, $connectTimeOut, $readTimeOut); /** * 发送向服务端的编码,如果本页面的编码为GBK,请使用GBK */ $client->setOutgoingEncoding("GBK"); // login(); //激活序列号 // updatePassword(); //修改密码 // logout(); //注销序列号 // registDetailInfo();//注册企业信息 // getEachFee(); //得到单价 // getMO(); //接收短信 // getVersion(); //得到版本号 sendSMS(); //发送短信 // getBalance(); //得到余额 // chargeUp(); //充值 //sendVoice(); //发送短信验证码 //---------------------------------------------------------------------- // 注: // 1. 下面是各接口的使用用例,Client.php 还有每一个接口更详细的参数说明
private function sendSms($mobile, $content) { require_once APPPATH . 'libraries/sms/Client.php'; //$sms_config = $this->tickets->select('configs',array('tc_type'=>'sms_config')); $sql = "select * from t_configs where 1=1 and tc_type='sms_config'"; $sms_config = $this->db->query($sql)->row(); if (!$sms_config) { return false; } else { $config = $sms_config; } /** * 网关地址 */ $gwUrl = 'http://sdk4report.eucp.b2m.cn:8080/sdk/SDKService'; /** * 序列号,请通过亿美销售人员获取 */ $serialNumber = $config->tc_title; //'6SDK-EMY-6688-KGZSP'; /** * 密码,请通过亿美销售人员获取 */ $password = $config->tc_content; //'845379'; /** * 登录后所持有的SESSION KEY,即可通过login方法时创建 */ $sessionKey = '123456'; /** * 连接超时时间,单位为秒 */ $connectTimeOut = 2; /** * 远程信息读取超时时间,单位为秒 */ $readTimeOut = 10; $proxyhost = false; $proxyport = false; $proxyusername = false; $proxypassword = false; $client = new Client($gwUrl, $serialNumber, $password, $sessionKey, $proxyhost, $proxyport, $proxyusername, $proxypassword, $connectTimeOut, $readTimeOut); /** * 发送向服务端的编码,如果本页面的编码为GBK,请使用GBK */ $client->setOutgoingEncoding("utf8"); $statusCode = $client->login(); $statusCode = $client->sendSMS(array($mobile), $content); if ($statusCode == 0) { return true; } else { return false; } }
//验证类 $serialNumber = '3SDK-EMY-0130-OGYQS';//亿美得序列号 $password = '******';//亿美得序列号密码 $sessionKey = 'SessionKEY';//session密钥,可以是123456,随便填 //超时 $connectTimeOut = 2; $readTimeOut = 10; $proxyhost = false; $proxyport = false; $proxyusername = false; $proxypassword = false; $client = new Client($gwUrl,$serialNumber,$password,$sessionKey,$proxyhost,$proxyport,$proxyusername,$proxypassword,$connectTimeOut,$readTimeOut); $client->setOutgoingEncoding("utf-8"); //login(); //激活序列号 // updatePassword(); //修改密码 // logout(); //注销序列号 // registDetailInfo();//注册企业信息 // getEachFee(); //得到单价 // getMO(); //接收短信 // getVersion(); //得到版本号 // sendSMS(); //发送短信 // getBalance(); //得到余额 // chargeUp(); //充值 /** * 接口调用错误查看 用例 */
/** * 短信发送 用例 * @param array $mobiles * @param string $content * @return int $errorcode */ function mobileSMS($mobiles, $content) { set_time_limit(0); header("Content-Type: text/html; charset=UTF-8"); #定义程序绝对路径 define('SCRIPT_ROOT', FCPATH . APPPATH . 'libraries/sms/'); require_once SCRIPT_ROOT . 'include/Client.php'; #网关地址 $gwUrl = 'http://sdkhttp.eucp.b2m.cn/sdk/SDKService?wsdl'; #序列号,请通过亿美销售人员获取 $serialNumber = '3SDK-EMY-0130-JFTRN'; #密码,请通过亿美销售人员获取 $password = '******'; #登录后所持有的SESSION KEY,即可通过login方法时创建 $sessionKey = '169304'; #连接超时时间,单位为秒 $connectTimeOut = 2; #远程信息读取超时时间,单位为秒 $readTimeOut = 10; /** $proxyhost 可选,代理服务器地址,默认为 false ,则不使用代理服务器 $proxyport 可选,代理服务器端口,默认为 false $proxyusername 可选,代理服务器用户名,默认为 false $proxypassword 可选,代理服务器密码,默认为 false */ $proxyhost = false; $proxyport = false; $proxyusername = false; $proxypassword = false; $client = new Client($gwUrl, $serialNumber, $password, $sessionKey, $proxyhost, $proxyport, $proxyusername, $proxypassword, $connectTimeOut, $readTimeOut); #发送向服务端的编码,如果本页面的编码为GBK,请使用GBK $client->setOutgoingEncoding("UTF8"); #global $client; /* * 下面的代码将发送内容为 test 给 159xxxxxxxx 和 159xxxxxxxx * $client->sendSMS还有更多可用参数,请参考 Client.php */ #第一次使用需要先执行,以后无需再执行,除非调用logout #$statusCode = $client->login($sessionKey); $msg = '【赛酷网】' . $content; $statusCode = $client->sendSMS($mobiles, $msg); if ($statusCode != '' && $statusCode == 0) { return true; } else { return false; } }