public static function getInstance($cpId, $cpPwd, $wsdl = "http://hl.my2my.cn/newesms/services/esmsservice?wsdl") { if (null == self::$_self) { self::$_self = new WS_SDK($cpId, $cpPwd, $wsdl); } return self::$_self; }
public function actionSendMobileMess() { $sendMessage = new SendMessage(); $response = array(); $target = $this->request->getParam('target'); $user_name = $this->request->getParam('user_name'); $condition_user_name = array('condition' => 'nick_name = :nick_name OR phone_num = :phone_num', 'params' => array(':nick_name' => $user_name, ':phone_num' => $user_name)); if (!empty($user_name)) { $userList = $this->user_model->find($condition_user_name); $target = $userList->phone_num; } if (!$target) { $response['content'] = '请输入目标手机号'; $response['status'] = 100001; Yii::app()->end(FHelper::json($response['content'], $response['status'])); } if (empty($user_name)) { if (!$this->verifyPhone($target)) { $response['content'] = '该手机号已经被验证过来'; $response['status'] = 100002; Yii::app()->end(FHelper::json($response['content'], $response['status'])); } } $code = FHelper::generate_code(); $content = FConfig::item('siteMessage.register.first') . $code . FConfig::item('siteMessage.register.end'); $user = FConfig::item('config.ws_mobile.userName'); $pass = FConfig::item('config.ws_mobile.passWord'); //查询发送条数 $today = date('Y-m-d 0:0:0', time()); $condition = array('condition' => "mobile_no = '{$target}' and send_time >= '{$today}'"); $messageCount = $sendMessage->count($condition); if ($messageCount < 5) { Yii::import('ext.wsMobile.ws.*'); require_once 'ws-demo.php'; $engine = WS_SDK::getInstance($user, $pass); $res = $engine->sendSmsAsNormal($target, $content, '', 0); if (intval($res) === 0) { //短息发送成功对短信进行加密 $cryRes = Fn::crypt($code, FConfig::item('config.cookie.phone_code')); FCookie::set(FConfig::item('config.cookie.phone_key'), $cryRes); //放到cookie中 $response['status'] = 100000; $response['content'] = $target; // 短信发送成功 $telArr = array('mobile_no' => $target, 'mess_code' => $code, 'send_time' => FF_DATE_TIME); $sendMessage->attributes = $telArr; $sendMessage->save(); } else { $response['status'] = 100003; $response['content'] = '短信发送失败,请重试'; } } else { $response['status'] = 100004; $response['content'] = '该手机号码今天发送验证码过多'; } Yii::app()->end(FHelper::json($response['content'], $response['status'])); }
} $method = $_REQUEST['method']; if ($method == 'sendsmsnormal' || $method == 'sendsmsxml') { $content = $_REQUEST['content']; if (!$content) { echo "<meta charset='utf-8'>请输入发送内容<a href='/'>返回</a>"; exit; } $target = $_REQUEST['target']; if (!$target) { echo "<meta charset='utf-8'>请输入目标手机号<a href='/'>返回</a>"; exit; } } require "ws-demo.php"; $engine = WS_SDK::getInstance($cpid, $cppsw); echo "<meta charset='utf-8'>"; //echo $test->sendSmsAsNormal(phone, content, spnumber, 0);//1,手机号、2,内容、3,流水号 switch ($method) { case 'sendsmsnormal': echo $engine->sendSmsAsNormal($target, $content, '317000001', 0); //1,手机号、2,内容、3,流水号、4,通道号(默认为0,预留扩展用) break; case 'sendsmsxml': $smspack = "<?xml version='1.0' encoding='utf-8' ?><sms><msg><phone>" . $target . "</phone><content>" . $content . "</content><spnumber>1111111111</spnumber><chid>0</chid></msg></sms>"; echo $engine->sendSmsAsXml($smspack); //1,手机号、2,内容、3,流水号、4,通道号(默认为0,预留扩展用) break; case 'getsmsstatus': echo htmlspecialchars($engine->getSmsStates()); break;
public function actionSendMsgPhone() { $sendMessage = new SendMessage(); $response = array(); $code = FHelper::generate_code(); $content = FConfig::item('siteMessage.register.first') . $code . FConfig::item('siteMessage.register.end'); $user = FConfig::item('config.ws_mobile.userName'); $pass = FConfig::item('config.ws_mobile.passWord'); $today = date('Y-m-d 0:0:0', time()); $condition = array('condition' => "mobile_no = '{$this->user['phone_num']}' and send_time >= '{$today}'"); $messageCount = $sendMessage->count($condition); if ($messageCount < 5) { Yii::import('ext.wsMobile.ws.*'); require_once 'ws-demo.php'; $engine = WS_SDK::getInstance($user, $pass); $res = $engine->sendSmsAsNormal($this->user['phone_num'], $content, '', 0); if (intval($res) === 0) { $cryRes = Fn::crypt($code, FConfig::item('config.cookie.phone_code')); FCookie::set(FConfig::item('config.cookie.phone_key'), $cryRes); $response['status'] = 100000; $response['content'] = '短信发送成功'; $telArr = array('mobile_no' => $this->user['phone_num'], 'mess_code' => $code, 'send_time' => FF_DATE_TIME); $sendMessage->attributes = $telArr; $sendMessage->save(); } else { $response['status'] = 100001; $response['content'] = '短信发送失败,请重试'; } } else { $response['status'] = 100002; $response['content'] = '该手机号码今天发送验证码过多'; } Yii::app()->end(FHelper::json($response['content'], $response['status'])); }