<?php namespace App\Servers\Sms;

use Ixudra\Curl\Facades\Curl;

/**
 * 验证码模型
 *
 * @author    刘相欣
 */
class GuoDu {

    // 已开通的帐号名称
    private $operId     = 'dfwyyz';
    //与帐号名称对应的密码
    private $operPass   = 'vTfTsYzX';

    /**
     * 发送短信
     * @param  string $desMobile    接收手机号码
     * @param  string $content      短信内容
     * @param  string $sign         签名
     * 
     * @return array
     * 
     */
    public function sendSms($desMobile,$content,$sign){
        $result         = Curl::to('http://qxtsms.guodulink.net/QxtSms/QxtFirewall')->withData([
                            'OperID'=>$this->operId,
                            'OperPass'=>$this->operPass,
                            'DesMobile'=>$desMobile,
                            'Content'=>'【'.$sign.'】'.$content,
                            'Content_Code'=>1
                        ])->post();
        //如果没有返回值
        if( !$result )  return['error'=>'短信通道未正确返回格式'];
        // XML格式转PHP数组
        $result         = simplexml_load_string($result);
        $result         = json_decode(json_encode($result),true);
        // 返回结果
        return          $result;
    }

    /**
     * 查询余额
     * 
     * @return array|int
     * 
     */
    public function surplus(){
		// 查询
        $result         = Curl::to('http://124.251.7.68:8100/QxtSms_surplus/surplus')->withData(['OperID'=>$this->operId,'OperPass'=>$this->operPass])->get();
        //如果没有返回值
        if( !$result )  return['error'=>'短信通道未正确返回格式'];
        // 返回结果
        return          $result;
    }

}

