1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- use App\libs\sms;
- define("YM_SMS_ADDR", "http://bjmtn.b2m.cn");/*接口地址,请联系销售获取*/
- define("YM_SMS_SEND_URI", "/simpleinter/sendSMS");/*发送短信接口*/
- define("YM_SMS_APPID", "EUCP-EMY-SMS1-0NOFX");/*APPID,请联系销售或者在页面获取*/
- define("YM_SMS_AESPWD", "A1596CC01B89E134");/*密钥,请联系销售或者在页面获取*/
- class YMSMS {
-
- # 群发phone=15810540853,15810540854...
- public static function sendSMS($phone, $content){
- $timestamp = date("YmdHis");
- $sign = self::signmd5(YM_SMS_APPID,YM_SMS_AESPWD,$timestamp);
- $data = array(
- "appId" => YM_SMS_APPID,
- "timestamp" => $timestamp,
- "sign" => $sign,
- "mobiles" => $phone,
- "content" => $content,
- "customSmsId" => "10001",
- "timerTime" => "",
- "extendedCode" => "3"
- );
- $url = YM_SMS_ADDR.YM_SMS_SEND_URI;
- $resobj = self::cPost($url, $data);
- return $resobj;
- }
- public static function cPost($url, $data){
- $data = http_build_query($data);
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_POST, TRUE);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
- $output = curl_exec($curl);
- curl_close($curl);
- return $output;
- }
- public static function signmd5($appId,$secretKey,$timestamp){
- return md5($appId.$secretKey.$timestamp);
- }
- //发送语音验证
- public static function sendVoiceCheck($phone, $code)
- {
- $timestamp = date("YmdHis");
- $sign = self::signmd5(YM_SMS_APPID, YM_SMS_AESPWD, $timestamp);
- $url = YM_SMS_ADDR . "/voice/sendSMS?appId=" . YM_SMS_APPID . "×tamp=$timestamp&sign=$sign&mobile=$phone&content=$code";
- $result = self::request($url, false, "get");
- return $result;
- }
- //curl
- public static function request($url, $https=true, $method="get", $data=null)
- {
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- if ($https === true) {
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- }
- if ($method == "post") {
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- }
- $str = curl_exec($ch);
- curl_close($ch);
- return $str;
- }
- }
|