菜谱项目

YMSMS.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. use App\libs\sms;
  3. define("YM_SMS_ADDR", "http://bjmtn.b2m.cn");/*接口地址,请联系销售获取*/
  4. define("YM_SMS_SEND_URI", "/simpleinter/sendSMS");/*发送短信接口*/
  5. define("YM_SMS_APPID", "EUCP-EMY-SMS1-0NOFX");/*APPID,请联系销售或者在页面获取*/
  6. define("YM_SMS_AESPWD", "A1596CC01B89E134");/*密钥,请联系销售或者在页面获取*/
  7. class YMSMS {
  8. # 群发phone=15810540853,15810540854...
  9. public static function sendSMS($phone, $content){
  10. $timestamp = date("YmdHis");
  11. $sign = self::signmd5(YM_SMS_APPID,YM_SMS_AESPWD,$timestamp);
  12. $data = array(
  13. "appId" => YM_SMS_APPID,
  14. "timestamp" => $timestamp,
  15. "sign" => $sign,
  16. "mobiles" => $phone,
  17. "content" => $content,
  18. "customSmsId" => "10001",
  19. "timerTime" => "",
  20. "extendedCode" => "3"
  21. );
  22. $url = YM_SMS_ADDR.YM_SMS_SEND_URI;
  23. $resobj = self::cPost($url, $data);
  24. return $resobj;
  25. }
  26. public static function cPost($url, $data){
  27. $data = http_build_query($data);
  28. $curl = curl_init();
  29. curl_setopt($curl, CURLOPT_URL, $url);
  30. curl_setopt($curl, CURLOPT_POST, TRUE);
  31. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  32. curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
  33. $output = curl_exec($curl);
  34. curl_close($curl);
  35. return $output;
  36. }
  37. public static function signmd5($appId,$secretKey,$timestamp){
  38. return md5($appId.$secretKey.$timestamp);
  39. }
  40. //发送语音验证
  41. public static function sendVoiceCheck($phone, $code)
  42. {
  43. $timestamp = date("YmdHis");
  44. $sign = self::signmd5(YM_SMS_APPID, YM_SMS_AESPWD, $timestamp);
  45. $url = YM_SMS_ADDR . "/voice/sendSMS?appId=" . YM_SMS_APPID . "&timestamp=$timestamp&sign=$sign&mobile=$phone&content=$code";
  46. $result = self::request($url, false, "get");
  47. return $result;
  48. }
  49. //curl
  50. public static function request($url, $https=true, $method="get", $data=null)
  51. {
  52. $ch = curl_init($url);
  53. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  54. if ($https === true) {
  55. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  56. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  57. }
  58. if ($method == "post") {
  59. curl_setopt($ch, CURLOPT_POST, true);
  60. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  61. }
  62. $str = curl_exec($ch);
  63. curl_close($ch);
  64. return $str;
  65. }
  66. }