123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace App\Support;
- class YPSMS
- {
- const YP_TPL_URL = 'https://sms.yunpian.com/v2/sms/tpl_single_send.json';
- private static function init()
- {
- $ch = curl_init();
- /* 设置验证方式 */
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8',
- 'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
- /* 设置返回结果为流 */
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- /* 设置超时时间*/
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- /* 设置通信方式 */
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- return $ch;
- }
- private static function send($ch, $data)
- {
- curl_setopt ($ch, CURLOPT_URL, self::YP_TPL_URL);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
- $result = curl_exec($ch);
- return $result;
- }
- public static function warn_check_rule($phone, $param, $ruleType)
- {
- $ch = self::init();
- $sms_key = '995629e02beaaf47118b84ac19c4b5b9';
- switch ($ruleType) {
- case 'oudaa':
- // 预警组#group#主体#corp#客服号#user#单天主动添加人数超#num#人,请及时调整
- // $tpl_id = '5235852';
- $tpl_id = '5467448';
- break;
- case 'oudpa':
- // 预警组#group#主体#corp#客服号#user#单天被动添加人数超#num#人,请及时调整
- // $tpl_id = '5235856';
- $tpl_id = '5467450';
- break;
- case 'nuhaa':
- // 预警组#group#主体#corp#新客服号#user#一小时内主动添加人数超#num#人,请及时调整
- // $tpl_id = '5235858';
- $tpl_id = '5467452';
- break;
- case 'numpa':
- // 预警组#group#主体#corp#新客服号#user#一分钟内被动添加人数超#num#人,请及时调整
- // $tpl_id = '5235866';
- $tpl_id = '5467454';
- break;
- case 'auaaa':
- case 'buaaa':
- // 预警组#group#主体#corp#客服号#user#添加总客户数超#num#人,请及时调整
- // $tpl_id = '5276092';
- $tpl_id = '5467446';
- break;
- case 'abnormal_account':
- // 主体#corp#下客服号#user#在#minute#分钟内添加客户数#num#人,请及时调整
- // $tpl_id = '5445372';
- $tpl_id = '5467444';
- break;
- case 'corp_user_scale':
- # 主体#corp#用户规模已经达到预警值#num#人,请及时扩容。
- $tpl_id = '5782722';
- break;
- case 'user_scale':
- # 主体#corp#下客服号#user#总粉丝数达到#num#人,请及时扩容。
- $tpl_id = '5784676';
- break;
- case 'feed_back':
- # 主体#corp#下客服号#user#有客户提交意见反馈,请及时查看。
- $tpl_id = 5834154;
- break;
- default:
- return false;
- }
- if($ruleType == 'abnormal_account') {
- $tpl_value =
- urlencode("#minute#")."=".urlencode($param['minute'])
- ."&".
- urlencode("#corp#")."=".urlencode($param['corp'])
- ."&".
- urlencode("#user#")."=".urlencode($param['user'])
- ."&".
- urlencode("#num#")."=".urlencode($param['num']);
- } elseif ($ruleType == 'corp_user_scale') {
- $tpl_value =
- urlencode("#corp#")."=".urlencode($param['corp'])
- ."&".
- urlencode("#num#")."=".urlencode($param['num']);
- } elseif($ruleType == 'user_scale') {
- $tpl_value =
- urlencode("#corp#")."=".urlencode($param['corp'])
- ."&".
- urlencode("#user#")."=".urlencode($param['user'])
- ."&".
- urlencode("#num#")."=".urlencode($param['num']);
- } elseif($ruleType == 'feed_back'){
- $tpl_value =
- urlencode("#corp#")."=".urlencode($param['corp'])
- ."&".
- urlencode("#user#")."=".urlencode($param['user']);
- } else {
- $tpl_value =
- urlencode("#group#")."=".urlencode($param['group'])
- ."&".
- urlencode("#corp#")."=".urlencode($param['corp'])
- ."&".
- urlencode("#user#")."=".urlencode($param['user'])
- ."&".
- urlencode("#num#")."=".urlencode($param['num']);
- }
- $data = [
- 'apikey' => $sms_key,
- 'mobile' => $phone,
- 'tpl_id' => $tpl_id,
- 'tpl_value' => $tpl_value,
- ];
- $json_data = self::send($ch, $data);
- $array = json_decode($json_data,true);
- curl_close($ch);
- return $array;
- }
- }
|