YP_TPL_ID, 'tpl_value' => ('#code#').'='.urlencode($code), 'apikey' => YP_SMS_KEY, 'mobile' => $phone); // $json_data = self::tpl_send($ch,$data); // $array = json_decode($json_data,true); // echo '
';print_r($array); $data=array('tpl_id' => YP_TPL_ID,'text'=>$text,'apikey'=>YP_SMS_KEY,'mobile'=>$phone); $json_data = self::send($ch,$data); //print_r($json_data); ******************************maybe影响验证码发出 // $array = json_decode($json_data,true); // echo '';print_r($array); curl_close($ch); return $json_data; } 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; } } // YPSMS::init(); //$code=100; //$minutes=3; // YPSMS::sendSMS('13613665865','【钱多多随手记】您的验证码是' . $code . ',有效期为' . $minutes . '分钟,请尽快验证。'); // YPSMS::sendVoiceCheck('13613665865','123456');