No Description

Ypsms.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Support\Code;
  3. use Illuminate\Support\Facades\DB;
  4. define("YP_SMS_KEY", "fbdb5f2ddae13c2f4a592348bfe52137");
  5. define("YP_VOICE_URL", "http://voice.yunpian.com/v2/voice/send.json");
  6. define("YP_TPL_URL", "https://sms.yunpian.com/v2/sms/tpl_single_send.json");
  7. define("YP_TPLS_URL", "https://sms.yunpian.com/v2/sms/tpl_batch_send.json");
  8. // define("YP_TPL_URL", "https://sms.yunpian.com/v2/sms/single_send.json");
  9. class Ypsms implements \App\Support\Contracts\Code
  10. {
  11. /**
  12. * [sendCodes 短信群发]
  13. * @Author mzb
  14. * @DateTime 2018-11-09T16:09:35+0800
  15. * @param [type] $tplId [description]
  16. * @param [type] $mobiles [description]
  17. * @param [type] $parameter [description]
  18. * @return [type] [description]
  19. */
  20. public static function sendCodes($tplId, $mobiles, $parameter)
  21. {
  22. $parameter = json_decode($parameter, true);
  23. $arr = [];
  24. foreach ($parameter as $k => $p) {
  25. $arr[] = '#' . $k . '#=' . urlencode($p);
  26. }
  27. $str = implode('&', $arr);
  28. $data = array('tpl_id' => $tplId, 'tpl_value' => $str, 'apikey' => YP_SMS_KEY, 'mobile' => $mobiles);
  29. // return self::tplSend($data);
  30. $result = curlInit(YP_TPLS_URL, $data, 'Post');
  31. if ($result !== false) {
  32. $result = json_decode($result, true);
  33. /*liujuan 错误原因*/
  34. $reason="";
  35. if (isset($result['data'][0]['msg'])) {
  36. $reason=$result['data'][0]['msg'];
  37. }
  38. if (isset($result['total_fee'])) {
  39. /*liujuan total_fee>0.0000才是发送成功*/
  40. if ($result['total_fee']>0.0000) {
  41. $result['IS_SUCCESS'] = 1;
  42. }else{
  43. $result['IS_SUCCESS'] = 0;
  44. $result['reason']=$reason;
  45. }
  46. //原版 $result['IS_SUCCESS'] = 1;
  47. } else {
  48. $result['IS_SUCCESS'] = 0;
  49. /*liujuan 报错原因*/
  50. $result['reason']="服务端错误";
  51. }
  52. }
  53. return $result;
  54. }
  55. /**
  56. * [sendBillCode 钱多多发送验证码接口]
  57. * @Author mzb
  58. * @DateTime 2018-04-02T14:07:06+0800
  59. * @param [type] $phone [description]
  60. * @param integer $type [description]
  61. * @return [type] [description]
  62. */
  63. public static function sendCode($tplId, $mobile, $parameter, $type = 1)
  64. {
  65. $parameter = json_decode($parameter, true);
  66. if ($type == 1) {
  67. $arr = [];
  68. foreach ($parameter as $k => $p) {
  69. $arr[] = '#' . $k . '#=' . urlencode($p);
  70. }
  71. $str = implode('&', $arr);
  72. $data = array('tpl_id' => $tplId, 'tpl_value' => $str, 'apikey' => YP_SMS_KEY, 'mobile' => $mobile);
  73. // return self::tplSend($data);
  74. $result = curlInit(YP_TPL_URL, $data, 'Post');
  75. } else if ($type == 2) {
  76. if (!isset($parameter['code'])) {
  77. return false;
  78. }
  79. $code = $parameter['code'];
  80. $data = array('code' => $code, 'apikey' => YP_SMS_KEY, 'mobile' => $mobile);
  81. $result = curlInit(YP_VOICE_URL, $data, 'Post');
  82. }
  83. if ($result == false) {
  84. return false;
  85. }
  86. $result = json_decode($result, true);
  87. if (isset($result['fee'])) {
  88. $result['IS_SUCCESS'] = 1;
  89. } else {
  90. $result['IS_SUCCESS'] = 0;
  91. $result['reason']="服务端错误";
  92. }
  93. return $result;
  94. }
  95. }