You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.0 KiB

7 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Common;
  3. use App\Http\Model\SmsLog;
  4. class Sms
  5. {
  6. /**
  7. * 云片接口发送-支持国际短信
  8. *
  9. * @param $text 发送的内容
  10. * @param $mobile 要发送到哪个手机号上
  11. * @return bool
  12. */
  13. public static function sendByYp($text, $mobile)
  14. {
  15. // 必要参数
  16. $apikey = 'f9c119a3e8a0dc4faee84fdd82cbc60d'; //示例:9b11127a9701975c734b8aee81ee3526,修改为您的apikey(https://www.yunpian.com)登录官网后获取
  17. $mobile = $mobile; //手机号
  18. $text = $text;
  19. // 发送短信
  20. $ch = curl_init();
  21. $data = array('text'=>$text,'apikey'=>$apikey,'mobile'=>$mobile);
  22. curl_setopt($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/single_send.json');
  23. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  24. curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
  25. $result = json_decode(curl_exec($ch),true);
  26. if ($result && $result['code'] != 0)
  27. {
  28. Log::info('短信发送失败:号码:' . $mobile . '; 短信内容:' . $text . '; 错误代码:' . $result['code'] . '; 错误详情:' . $result['msg']);
  29. SmsLog::fail($mobile, $text, $result);
  30. return false;
  31. }
  32. SmsLog::success($mobile, $text, $result);
  33. return true;
  34. }
  35. /**
  36. * 阿里大于
  37. *
  38. * @param $text 发送的内容
  39. * @param $mobile 要发送到哪个手机号上
  40. * @return bool
  41. */
  42. public static function SendDySms($text, $mobile)
  43. {
  44. $c = new TopClient;
  45. $c->appkey = $appkey;
  46. $c->secretKey = $secret;
  47. $req = new AlibabaAliqinFcSmsNumSendRequest;
  48. $req->setExtend("123456");
  49. $req->setSmsType("normal");
  50. $req->setSmsFreeSignName("阿里大于");
  51. $req->setSmsParam("{\"code\":\"1234\",\"product\":\"alidayu\"}");
  52. $req->setRecNum("13000000000");
  53. $req->setSmsTemplateCode("SMS_585014");
  54. $resp = $c->execute($req);
  55. }
  56. }