123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
- use App\libs\sms;
- //define("YP_SMS_KEY", "ac5dac49af17e882300749686982d333");//新账号
- define("YP_SMS_KEY", "fbdb5f2ddae13c2f4a592348bfe52137");
- define('YP_SMS_YHQ', '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_ID", "2122814");
- 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 sendCode($params)
- {
- $tpl_id = '3910790'; //【酷炫】您的验证码是#code#。如非本人操作,请忽略本短信
- $ch = self::init();
- $data = [
- 'apikey' => YP_SMS_KEY,
- 'mobile' => $params['mobile'],
- 'tpl_id' => $tpl_id,
- 'tpl_value' => ('#code#').'='.$params['code'],
- ];
- $json_data = self::tpl_send($ch,$data);
- $array = json_decode($json_data,true);
- curl_close($ch);
- return $array;
- }
- public static function auditResultSend($params)
- {
- $tpl_id = '3910830'; //【酷炫】您的#business#审核已经完成,审核结果为#result#,点击#url#进行下一步操作
- $ch = self::init();
- $data = [
- 'apikey' => YP_SMS_KEY,
- 'mobile' => $params['mobile'],
- 'tpl_id' => $tpl_id,
- 'tpl_value' => urlencode('#business#').'='.urlencode($params['business']).'&'.urlencode('#result#').'='.urlencode($params['result']).'&'.urlencode('#url#').'='.urlencode($params['url'])
- ];
- $json_data = self::tpl_send($ch,$data);
- $array = json_decode($json_data,true);
- curl_close($ch);
- return $array;
- }
- public static function signVerify($params)
- {
- $tpl_id = '3910802'; //【合乐文化】#red#已经完成签约,请及时审核。
- $ch = self::init();
- $data = [
- 'apikey' => YP_SMS_KEY,
- 'mobile' => $params['mobile'],
- 'tpl_id' => $tpl_id,
- 'tpl_value' => ('#red#').'='.urlencode($params['user_name'])
- ];
- $json_data = self::tpl_send($ch,$data);
- $array = json_decode($json_data,true);
- curl_close($ch);
- return $array;
- }
- //账号审核提醒
- public static function accountVerify($params)
- {
- $tpl_id = '3910796'; //【合乐文化】#red#已经完成账号注册,请尽快分配媒介,完成审核。
- $ch = self::init();
- $data = [
- 'apikey' => YP_SMS_KEY,
- 'mobile' => $params['mobile'],
- 'tpl_id' => $tpl_id,
- 'tpl_value' => ('#red#').'='.urlencode($params['user_name'])
- ];
- $json_data = self::tpl_send($ch,$data);
- $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);
- 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);
- Log::info(json_encode($result));
- $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);
- Log::info(json_encode($result));
- $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);
- Log::info(json_encode($result));
- $error = curl_error($ch);
- self::checkErr($result,$error);
- return $result;
- }
- //有参数发送短信验证码
- public static function sendMsgWithParams($phone, $params, $template_id) {
- $ch=self::init();
- $data=array('tpl_id' => $template_id,'apikey'=>YP_SMS_KEY,'mobile'=>$phone,'tpl_value'=>$params);
- $json_data = self::tplSend($ch,$data);
- $array = json_decode($json_data,true);
- curl_close($ch);
- return $array;
- }
- //无参数发送短信验证码
- public static function sendMsgSimple($phone, $template_id) {
- $ch=self::init();
- $data=array('tpl_id' => $template_id,'apikey'=>YP_SMS_KEY,'mobile'=>$phone);
- $json_data = self::tplSend($ch,$data);
- $array = json_decode($json_data,true);
- curl_close($ch);
- return $array;
- }
- private static function tplSend($ch,$data){
- curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/tpl_single_send.json');
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
- $result = curl_exec($ch);
- Log::info(json_encode($result));
- $error = curl_error($ch);
- self::checkErr($result,$error);
- return $result;
- }
- public static function sendOrderSyncMsg($params)
- {
- $tpl_id = '5370144'; //【酷炫网络】#msg#,请及时处理。
- // $tpl_id = '4452336'; //【酷炫网络】#msg#,请及时处理。
- $ch = self::init();
- $data = [
- 'apikey' => YP_SMS_KEY,
- 'mobile' => $params['mobile'],
- 'tpl_id' => $tpl_id,
- 'tpl_value' => ('#msg#').'='.urlencode($params['msg'])
- ];
- $json_data = self::tpl_send($ch,$data);
- $array = json_decode($json_data,true);
- curl_close($ch);
- return $array;
- }
- }
|