YP_SMS_KEY, 'mobile' => $phone, 'tpl_id' => YP_TPL_ID, 'tpl_value' =>('#code#').'='.$money ]; $json_data = self::tpl_send($ch,$param); $array = json_decode($json_data,true); curl_close($ch); return $array; } #提醒红包到账,分享帮拆 public static function sendRedHelp($phone, $money, $name){ $ch=self::init(); $param = [ 'apikey' => YP_SMS_KEY, 'mobile' => $phone, 'tpl_id' => RED_TPL_ID, 'tpl_value' =>('#name#').'='.$name.'&'.('#money#').'='.$money ]; $json_data = self::tpl_send($ch,$param); $array = json_decode($json_data,true); curl_close($ch); return $array; } # 提醒新手红包 public static function sendNewRed($phone, $name, $flag=1,$money=22){ $ch=self::init(); $param = [ 'apikey' => YP_SMS_KEY, 'mobile' => $phone, ]; $param['tpl_value'] = ''; if($flag==1){ $param['tpl_id'] = NEW_TPL_ID1; }elseif($flag==3){ $param['tpl_id'] = NEW_TPL_ID3; } $param['tpl_value'] = ('#name#').'='.$name.'&'.('#money#').'='.$money; $json_data = self::tpl_send($ch,$param); $array = json_decode($json_data,true); curl_close($ch); return $array; } # 超过三天未登录单独发 public static function sendNewRed2($phone, $name='',$money=22){ $ch=self::init(); $param = [ 'apikey' => YP_SMS_KEY, 'mobile' => $phone, ]; $param['tpl_id'] = NEW_TPL_ID2; $param['tpl_value'] = ('#name#').'='.$name.'&'.('#money#').'='.$money; $json_data = self::tpl_send($ch,$param); $array = json_decode($json_data,true); curl_close($ch); return $array; } public static function sendVoiceCheck($phone,$code){ $ch=self::init(); $data=array('code'=>$code,'apikey'=>YP_SMS_KEY,'mobile'=>$phone); $json_data =self::voice_send($ch,$data); // $array = json_decode($json_data,true); // echo '
';print_r($array);
        curl_close($ch);
        return $json_data;

    }
    private static function checkErr($result,$error) {
        if($result === false)
        {
            echo 'Curl error: ' . $error;
        }
//        else
//        {
//            echo '操作完成没有任何错误';
//        }
    }
    private static function send($ch,$data){
        curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/single_send.json');
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        $result = curl_exec($ch);
        $error = curl_error($ch);
        self::checkErr($result,$error);
        return $result;
    }
    private static function voice_send($ch,$data){
        curl_setopt ($ch, CURLOPT_URL, YP_VOICE_URL);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        $result = curl_exec($ch);
        $error = curl_error($ch);
        self::checkErr($result,$error);
        return $result;
    }
    private static function tpl_send($ch,$data){
        curl_setopt ($ch, CURLOPT_URL, YP_TPL_URL);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        $result = curl_exec($ch);
        $error = curl_error($ch);
        self::checkErr($result,$error);
        return $result;
    }
    private static function tpl_many_send($ch,$data){
        curl_setopt ($ch, CURLOPT_URL, YP_TPL_MANY_URL);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        $result = curl_exec($ch);
        $error = curl_error($ch);
        self::checkErr($result,$error);
        return $result;
    }
}