Google Voice 收发短信API函数

自己写的新的接口,之前Google关闭了中间件,导致协议失效 重新更新接口

/*****************************************************Google Voice*****************************************************/
/**
 * @desc Google Voice 接收短信
 * @bash命令  bash命令
 * @return array
 */
function Voice_Receive_Sms($bash) {
    $Post=Json_Voice($bash);
    $html_arr=Get_Web_Contents($Post["url"],"POST",$Post["data"],'',$Post["header"]);
    $response=$html_arr["Body"];
    $data=json_decode($response,true);
    //授权失败
    if(isset($data["error"]) and $data["error"]["errors"][0]["location"] == "Authorization"){
        return "Authorization";
    }
    //返回错误数组
    if(isset($data["error"])){
        return "error";
    }
    //返回结果为数组时候 $data[0]为空
    if(empty($data[0]) and !empty($data[2])){
        return "nothing";
    }else{
        $r=0;
        foreach($data[0] as $k => $v){
            foreach($v[2] as $m => $n){
                $message[$r]["From"]=$n[3][0];
                $message[$r]["To"]=$n[2];
                if($n[12]==6){
                    $message[$r]["From"]=$n[2];
                    $message[$r]["To"]=$n[3][0];
                }
                $message[$r]["Data"]=delbr($n[9]);
                $message[$r]["Time"]=nicetime(round($n[1]/1000));
                $message[$r]["TimeUnix"]=round($n[1]/1000);
                $message[$r]["MessageId"]=$n[0];
                $r++;
            }
        }
        $message=array_values(arraySort($message, 'TimeUnix', 'desc'));
        return $message;
    }
}

/**
 * @desc Google Voice 只读取接收到的短信,不再读取自己发送的短信
 * @bash命令  bash命令
 * @return array
 */
function Voice_Read_Sms($bash) {
    $Post=Json_Voice($bash);
    $html_arr=Get_Web_Contents($Post["url"],"POST",$Post["data"],'',$Post["header"]);
    $response=$html_arr["Body"];
    $data=json_decode($response,true);
    //授权失败
    if(isset($data["error"]) and $data["error"]["errors"][0]["location"] == "Authorization"){
        return "Authorization";
    }
    //返回错误数组
    if(isset($data["error"])){
        return "error";
    }
    //返回结果为数组时候 $data[0]为空
    if(empty($data[0]) and !empty($data[2])){
        return "nothing";
    }else{
        $r=0;
        foreach($data[0] as $k => $v){
            foreach($v[2] as $m => $n){
                if($n[12]==5){
                    $message[$r]["From"]=$n[3][0];
                    $message[$r]["To"]=$n[2];
                    $message[$r]["Data"]=delbr($n[9]);
                    $message[$r]["Time"]=nicetime(round($n[1]/1000));
                    $message[$r]["TimeUnix"]=round($n[1]/1000);
                    $message[$r]["MessageId"]=$n[0];
                    $r++;
                }
            }
        }
        $message=array_values(arraySort($message, 'TimeUnix', 'desc'));
        return $message;
    }
}

/**
 * @desc Google Voice 接收指定号码短信
 * @tel     指定电话号码
 * @bash命令  bash命令
 * @return array
 */
function Voice_Responses_Sms($tel,$bash) {
    $Post=Json_Voice($bash);
    $Post["data"]=str_replace("888888888", $tel, $Post["data"]);
    $html_arr=Get_Web_Contents($Post["url"],"POST",$Post["data"],'',$Post["header"]);
    $response=$html_arr["Body"];
    $data=json_decode($response,true);
    //授权失败
    if(isset($data["error"]) and $data["error"]["errors"][0]["location"] == "Authorization"){
        return "Authorization";
    }
    //返回结果不是数组
    if(!isset($data[0])){
        return "error";
    }
    //返回结果为数组时候 $data[0]为空
    if(empty($data[0]) and !empty($data[2])){
        return "nothing";
    }else{
        $r=0;
        foreach($data[0][2] as $k => $v){
            $message[$r]["From"]=$v[3][0];
            $message[$r]["To"]=$v[2];
            if($v[12]==6){
                $message[$r]["From"]=$v[2];
                $message[$r]["To"]=$v[3][0];
            }
            $message[$r]["Data"]=delbr($v[9]);
            $message[$r]["Time"]=nicetime(round($v[1]/1000));
            $message[$r]["TimeUnix"]=round($v[1]/1000);
            $message[$r]["MessageId"]=$v[0];
            $r++;
        }
        return $message;
    }
}
/**
 * @desc    Google Voice 发送短信
 * @tel     接收短信的号码
 * @message 短信内容
 * @bash命令  bash命令 文件地址
 * @return array
 */
function Voice_Send_Sms($tel,$message,$bash) {
    $Post=Json_Voice($bash);
    //处理一下数据
    $Post["data"]=str_replace("999999999", $message, $Post["data"]);
    $Post["data"]=str_replace("888888888", $tel, $Post["data"]);
    $html_arr=Get_Web_Contents($Post["url"],"POST",$Post["data"],'',$Post["header"]);
    $response=$html_arr["Body"];
    $data=json_decode($response,true);
    //授权失败
    if(isset($data["error"]) and $data["error"]["errors"][0]["location"] == "Authorization"){
        return "Authorization";
    }
    //号码失效
    if(isset($data["error"]) and $data["error"]["errors"][0]["reason"] == "INVALID_ARGUMENT"){
        return "err_number";
    }
    //返回错误数组
    if(isset($data["error"])){
        return "error";
    }else{
        $redata["Success"]=true;;
        $redata["TimeUnix"]=round($data[3]/1000);
        $redata["MessageId"]=$data[2];
        return $redata;
    }

}

发表评论

邮箱地址不会被公开。 必填项已用*标注