123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- //define("YP_SMS_KEY", "fbdb5f2ddae13c2f4a592348bfe52137");
- define("YP_SMS_KEY", "73a74eb72c42b765669acd8e94096b9f");
- define("YP_SMS_KEY_FAMLI",'995629e02beaaf47118b84ac19c4b5b9');
- define("YP_VOICE_URL", "http://voice.yunpian.com/v2/voice/send.json");
- define("YP_TPL_URL", "https://sms.yunpian.com/v2/sms/tpl_single_send.json");
- define("YP_TPL_MANY_URL", "https://sms.yunpian.com/v2/sms/tpl_batch_send.json");
- define("YP_TPL_ID", "2731830");
- define("RED_TPL_ID", "2741432");
- define("NEW_TPL_ID1", "2765270");
- define("NEW_TPL_ID2", "2765274");
- define("NEW_TPL_ID3", "2765282");
- class YPSMS{
- private static function init(){
- $ch = curl_init();
- /* 设置验证方式 */
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8',
- 'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
- /* 设置返回结果为流 */
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- /* 设置超时时间*/
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- /* 设置通信方式 */
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- return $ch;
- }
- public static function sendSMS($phone, $money){
- $ch=self::init();
- $param = [
- 'apikey' => 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 '<pre>';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;
- }
- }
|