12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?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':
- $tpl_id = '5235852';
- break;
- case 'oudpa':
- $tpl_id = '5235856';
- break;
- case 'nuhaa':
- $tpl_id = '5235858';
- break;
- case 'numpa':
- $tpl_id = '5235866';
- break;
- case 'auaaa':
- $tpl_id = '5276092';
- break;
- default:
- return false;
- }
- $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;
- }
- }
|