<?php 
namespace App\Libs;
use DOMDocument;

/**
 * 短信发送类
 */
class SMS
{
    private static $third_party_user_id = "526";
    private static $third_party_account = "youxi12";
    private static $third_party_password = "zwkj20141025";
    private static $third_party_send_url = "http://121.42.146.54:18888/sms.aspx?action=send";

    static function send($number,$content,$sign='追书云')
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7");
        curl_setopt($ch, CURLOPT_POST, true);

        $post_data = "action=send&userid=".self::$third_party_user_id."&account=".self::$third_party_account."&password=".self::$third_party_password."&mobile=" . $number . "&content=【{$sign}】{$content}&sendTime=&checkcontent=0";

        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($ch, CURLOPT_URL, self::$third_party_send_url);

        $res = curl_exec($ch);
        \Log::info($res);
        curl_close($ch);

        $xml = new DOMDocument();
        $xml->loadXML($res);
        $status = $xml->getElementsByTagName('returnstatus')->item(0)->nodeValue;
        $message = $xml->getElementsByTagName('message')->item(0)->nodeValue;
        $money_left = $xml->getElementsByTagName('remainpoint')->item(0)->nodeValue;
        $task_id = $xml->getElementsByTagName('taskID')->item(0)->nodeValue;

        $status = (($status=='Success')?1:0);
        return $status;
    }

}