123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- use App\libs\sms;
- define("YP_SMS_KEY_1", "fbdb5f2ddae13c2f4a592348bfe52137");
- define("YP_TPL_URL_1", "https://sms.yunpian.com/v2/sms/tpl_single_send.json");
- class YPSMS{
- private static $order_tpl = [
- 1 => '3210114',
-
- 2 => '3211800',
- 3 => '3210134',
- 4 => '3210146',
- 5 => '3210312',
- 6 => '3391172',
- ];
- 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 sendMsg($phone,$type,$order_id = null, $send_date = null){
- $tpl = self::$order_tpl;
- $tpl_id = $tpl[$type];
- $ch=self::init();
-
- $data = [
- 'apikey' => YP_SMS_KEY_1,
- 'mobile' => $phone,
- 'tpl_id' => $tpl_id,
- ];
- if( in_array($type, [3,5]) ){
- $data['tpl_value'] = ('#order_id#').'='.$order_id;
- }elseif( $type == 2){
- $data['tpl_value'] = ('#order_id#').'='.$order_id.'&'. ('#send_date#').'='.urldecode($send_date);
- }
- $json_data = self::tpl_send($ch,$data);
-
- $array = json_decode($json_data,true);
-
- curl_close($ch);
- return $array;
- }
-
- public static function sendSkuWnum($phone, $note = null){
- $tpl = self::$order_tpl;
- $tpl_id = $tpl[6];
- $ch=self::init();
- $data = [
- 'apikey' => YP_SMS_KEY_1,
- 'mobile' => $phone,
- 'tpl_id' => $tpl_id,
- ];
-
- $data['tpl_value'] = ('#note#').'='.$note;
- $json_data = self::tpl_send($ch,$data);
- $array = json_decode($json_data,true);
- curl_close($ch);
- return $array;
- }
- public static function sendSMS($phone,$text){
- $ch=self::init();
-
-
-
-
- $data=array('tpl_id' => YP_TPL_ID,'text'=>$text,'apikey'=>YP_SMS_KEY_1,'mobile'=>$phone);
- $json_data = self::send($ch,$data);
-
- $array = json_decode($json_data,true);
-
- curl_close($ch);
- return $array;
- }
- public static function sendRedSMS($phone,$text,$id){
- $ch=self::init();
- $data=array('tpl_id' => $id,'text'=>$text,'apikey'=>YP_SMS_YHQ,'mobile'=>$phone);
- $json_data = self::send($ch,$data);
- curl_close($ch);
- return $json_data;
- }
- public static function sendVoiceCheck($phone,$code){
- $ch=self::init();
- $data=array('code'=>$code,'apikey'=>YP_SMS_KEY_1,'mobile'=>$phone);
- $json_data =self::voice_send($ch,$data);
-
-
- curl_close($ch);
- return $json_data;
- }
- private static function checkErr($result,$error) {
- if($result === false)
- {
- echo 'Curl error: ' . $error;
- }
- }
- 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_1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
- $result = curl_exec($ch);
- $error = curl_error($ch);
- self::checkErr($result,$error);
- return $result;
- }
- }
|