企微短剧业务系统

YPSMS.php 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace App\Support;
  3. class YPSMS
  4. {
  5. const YP_TPL_URL = 'https://sms.yunpian.com/v2/sms/tpl_single_send.json';
  6. private static function init()
  7. {
  8. $ch = curl_init();
  9. /* 设置验证方式 */
  10. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8',
  11. 'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
  12. /* 设置返回结果为流 */
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  14. /* 设置超时时间*/
  15. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  16. /* 设置通信方式 */
  17. curl_setopt($ch, CURLOPT_POST, 1);
  18. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  19. return $ch;
  20. }
  21. private static function send($ch, $data)
  22. {
  23. curl_setopt ($ch, CURLOPT_URL, self::YP_TPL_URL);
  24. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  25. $result = curl_exec($ch);
  26. return $result;
  27. }
  28. public static function warn_check_rule($phone, $param, $ruleType)
  29. {
  30. $ch = self::init();
  31. $sms_key = '995629e02beaaf47118b84ac19c4b5b9';
  32. switch ($ruleType) {
  33. case 'oudaa':
  34. // 预警组#group#主体#corp#客服号#user#单天主动添加人数超#num#人,请及时调整
  35. // $tpl_id = '5235852';
  36. $tpl_id = '5467448';
  37. break;
  38. case 'oudpa':
  39. // 预警组#group#主体#corp#客服号#user#单天被动添加人数超#num#人,请及时调整
  40. // $tpl_id = '5235856';
  41. $tpl_id = '5467450';
  42. break;
  43. case 'nuhaa':
  44. // 预警组#group#主体#corp#新客服号#user#一小时内主动添加人数超#num#人,请及时调整
  45. // $tpl_id = '5235858';
  46. $tpl_id = '5467452';
  47. break;
  48. case 'numpa':
  49. // 预警组#group#主体#corp#新客服号#user#一分钟内被动添加人数超#num#人,请及时调整
  50. // $tpl_id = '5235866';
  51. $tpl_id = '5467454';
  52. break;
  53. case 'auaaa':
  54. case 'buaaa':
  55. // 预警组#group#主体#corp#客服号#user#添加总客户数超#num#人,请及时调整
  56. // $tpl_id = '5276092';
  57. $tpl_id = '5467446';
  58. break;
  59. case 'abnormal_account':
  60. // 主体#corp#下客服号#user#在#minute#分钟内添加客户数#num#人,请及时调整
  61. // $tpl_id = '5445372';
  62. $tpl_id = '5467444';
  63. break;
  64. case 'corp_user_scale':
  65. # 主体#corp#用户规模已经达到预警值#num#人,请及时扩容。
  66. $tpl_id = '5782722';
  67. break;
  68. case 'user_scale':
  69. # 主体#corp#下客服号#user#总粉丝数达到#num#人,请及时扩容。
  70. $tpl_id = '5784676';
  71. break;
  72. case 'feed_back':
  73. # 主体#corp#下客服号#user#有客户提交意见反馈,请及时查看。
  74. $tpl_id = 5834154;
  75. break;
  76. default:
  77. return false;
  78. }
  79. if($ruleType == 'abnormal_account') {
  80. $tpl_value =
  81. urlencode("#minute#")."=".urlencode($param['minute'])
  82. ."&".
  83. urlencode("#corp#")."=".urlencode($param['corp'])
  84. ."&".
  85. urlencode("#user#")."=".urlencode($param['user'])
  86. ."&".
  87. urlencode("#num#")."=".urlencode($param['num']);
  88. } elseif ($ruleType == 'corp_user_scale') {
  89. $tpl_value =
  90. urlencode("#corp#")."=".urlencode($param['corp'])
  91. ."&".
  92. urlencode("#num#")."=".urlencode($param['num']);
  93. } elseif($ruleType == 'user_scale') {
  94. $tpl_value =
  95. urlencode("#corp#")."=".urlencode($param['corp'])
  96. ."&".
  97. urlencode("#user#")."=".urlencode($param['user'])
  98. ."&".
  99. urlencode("#num#")."=".urlencode($param['num']);
  100. } elseif($ruleType == 'feed_back'){
  101. $tpl_value =
  102. urlencode("#corp#")."=".urlencode($param['corp'])
  103. ."&".
  104. urlencode("#user#")."=".urlencode($param['user']);
  105. } else {
  106. $tpl_value =
  107. urlencode("#group#")."=".urlencode($param['group'])
  108. ."&".
  109. urlencode("#corp#")."=".urlencode($param['corp'])
  110. ."&".
  111. urlencode("#user#")."=".urlencode($param['user'])
  112. ."&".
  113. urlencode("#num#")."=".urlencode($param['num']);
  114. }
  115. $data = [
  116. 'apikey' => $sms_key,
  117. 'mobile' => $phone,
  118. 'tpl_id' => $tpl_id,
  119. 'tpl_value' => $tpl_value,
  120. ];
  121. $json_data = self::send($ch, $data);
  122. $array = json_decode($json_data,true);
  123. curl_close($ch);
  124. return $array;
  125. }
  126. }