深圳营销中心:

400-600-9885

传真:0755-8611-0002
业务 QQ1:点击这里给我发消息
业务 QQ2:点击这里给我发消息
地址:深圳市南山区科技园汇景豪苑海逸阁20楼

 

广州营销中心:

400-778-1138

传真:020-6261-8666
业务 QQ1:点击这里给我发消息
业务 QQ2:点击这里给我发消息
地址:广州市越秀区沿江中路313号康富来国际大厦6楼

 

<?php
/**
* Created by UEwang.
*优易网商务通php短信接口
*其余接口找业务下载
*/
class UeSmsApi{
    /*
     * 短信发送
     * @param string $userid    企业id
     * @param string $account   企业账户
     * @param string $password  账户密码
     * @param string $mobile    发送目标号码
     * @param string $content   发送内容
     * @param string $time      发送时间
     * @param string $extno     扩展子号
     * @param string $action    发送任务命令
     *
     */
    public function sendSMS($userid,$account,$password,$mobile,$content,$time='')
    {
        $http ='url'';
        $action='send';
        $extno='';
        $data = array
        (
            'action'=>$action,                  //发送任务命令
            'userid'=>$userid,                  //企业id
            'account'=>$account,     //企业账户
            'password'=>$password,           //账户密码
            'mobile'=>$mobile,            //目标号码
            'content'=>$content,           //发送内容
            'sendTime'=>$time,                  //发送时间
            'extno'=>$extno,         //扩展子号
        );
        $re= postSMS($http,$data);           //POST方式提交
        if(strstr($re,'ok'))
        {
            return "发送成功!";
        }
        else
        {
            return "发送失败! XML信息".$re;
        }
    }

    public function postSMS($url,$data='')
    {
        $row = parse_url($url);
        $row['port']='';
        $host = $row['host'];
        $port = $row['port'] ? $row['port']:80;
        $file = $row['path'];
        $post='';
        while (list($k,$v) = each($data))
        {
            $post .= rawurlencode($k)."=".rawurlencode($v)."&"; //转url
        }
        $post = substr( $post , 0 , -1 );
        $len = strlen($post);
        $fp = @fsockopen( $host ,$port, $errno, $errstr, 10);
        if (!$fp) {
            return "$errstr ($errno)\n";
        } else {
            $receive = '';
            $out = "POST $file HTTP/1.1\r\n";
            $out .= "Host: $host\r\n";
            $out .= "Content-type: application/x-www-form-urlencoded\r\n";
            $out .= "Connection: Close\r\n";
            $out .= "Content-Length: $len\r\n\r\n";
            $out .= $post;
            fwrite($fp, $out);
            while (!feof($fp)) {
                $receive .= fgets($fp, 128);
            }
            fclose($fp);
            $receive = explode("\r\n\r\n",$receive);
            unset($receive[0]);
            return implode("",$receive);
        }
    }
    /*
     * 查询余额及已发送量
     * @param string $userid    企业id
     * @param string $account   企业账户
     * @param string $password  账户密码
     * @param string $action    发送任务命令
     *
     */
    public function queryBalance($userid,$account,$password,$action){
        $post_data = array();
        $post_data['userid'] = $userid;
        $post_data['account'] = $account;
        $post_data['password'] = $password;
        $url='url?action='.$action.'';
        $o='';
        foreach ($post_data as $k=>$v)
        {
            $o.="$k=".urlencode($v).'&';
        }
        $post_data=substr($o,0,-1);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果需要将结果直接返回到变量里,那加上这句。
        $result = curl_exec($ch);
        return $result;
    }

    /*
     * 非法关键字查询
     * @param string $userid    企业id
     * @param string $account   企业账户
     * @param string $password  账户密码
     * @param string $content   发送内容
     * @param string $mobile    发送目标号码
     * @param string $time      发送时间
     * @param string $action    发送任务命令
     */
    public function checkKeyword($userid,$account,$password,$content,$mobile,$time,$action){
        $post_data = array();
        $post_data['userid'] = $userid;
        $post_data['account'] = $account;
        $post_data['password'] = $password;
        $post_data['content'] = urlencode($content);
        $post_data['mobile'] = $mobile;
        $post_data['sendtime']=$time;                   //格式化时间 如 1970-01-01 00:00:00
        $url='url?action='.$action.'';
        $o='';
        foreach ($post_data as $k=>$v)
        {
            $o.="$k=".urlencode($v).'&';
        }
        $post_data=substr($o,0,-1);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果需要将结果直接返回到变量里,那加上这句。
        $result = curl_exec($ch);
        return $result;
    }

    /*
     * 状态报告
     * @param string $userid    企业id
     * @param string $account   企业账户
     * @param string $password  账户密码
     * @param string $action    发送任务命令
     */
    public function queryStatus($userid,$account,$password,$action){
        $post_data = array();
        $post_data['userid'] = $userid;
        $post_data['account'] = $account;
        $post_data['password'] = $password;
        $url='url?action='.$action.'';
        $o='';
        foreach ($post_data as $k=>$v)
        {
            $o.="$k=".urlencode($v).'&';
        }
        $post_data=substr($o,0,-1);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果需要将结果直接返回到变量里,那加上这句。
        $result = curl_exec($ch);
        return $result;
    }

    /*
     * 上行状态
     * @param string $userid    企业id
     * @param string $account   企业账户
     * @param string $password  账户密码
     * @param string $action    发送任务命令
     */
    public function callApi($userid,$account,$password,$action){
        $post_data = array();
        $post_data['userid'] = $userid;
        $post_data['account'] = $account;
        $post_data['password'] = $password;
        $url='url?action='.$action.'';
        $o='';
        foreach ($post_data as $k=>$v)
        {
            $o.="$k=".urlencode($v).'&';
        }
        $post_data=substr($o,0,-1);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果需要将结果直接返回到变量里,那加上这句。
        $result = curl_exec($ch);
        return $result;
    }
}