|
- <?php
-
- /**
- * Created by PhpStorm.
- * User: Steven
- * Date: 2016/10/8
- * Time: 17:01
- *
- * Class utils 公共工具类
- */
- class utils
- {
- /**
- *创建日记类
- * @param $log log内容
- */
- /* static function writeLog($log)
- {
- $dir = __DIR__ . "/../Log/";
- if (!is_dir($dir)) {
- mkdir($dir);
- }
- $filename = $dir . date("Y-m-d") . ".log";
- file_put_contents($filename, date("Y-m-d H:i:s") . "\t" . $log . PHP_EOL, FILE_APPEND);
- }*/
-
- static function httpRequest($url, $data = null)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- if (!empty($data)) {
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- }
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $output = curl_exec($ch);
- curl_close($ch);
- return $output;
- }
-
- /**
- * 发送HTTP请求
- * @param $url
- * @param array $param
- * @return mixed
- * @throws Exception
- */
- static function httpsPost($url, $param = array())
- {
- $ch = curl_init(); // 初始化一个 cURL 对象
- curl_setopt($ch, CURLOPT_URL, $url); // 设置需要抓取的URL
- curl_setopt($ch, CURLOPT_HEADER, 0); // // 设置header
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
- // 如果你想PHP去做一个正规的HTTP POST,设置这个选项为一个非零值。这个POST是普通的 application/x-www-from-urlencoded 类型,多数被HTML表单使用。
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param)); // 传递一个作为HTTP “POST”操作的所有数据的字符串。//http_build_query:生成 URL-encode 之后的请求字符串
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-type:application/x-www-form-urlencoded;charset=utf-8'
- ));
- $rtn = curl_exec($ch); // 运行cURL,请求网页
- if ($errno = curl_errno($ch)) {
- throw new Exception ('Curl Error(' . $errno . '):' . curl_error($ch));
- }
- curl_close($ch); // 关闭URL请求
- return $rtn; // 返回获取的数据
- }
-
- /**
- * 发送短信
- * @param $phones 电话号码
- * @param $user_name 用户名称
- * @param $content 短信内容
- * @param $order_id 订单号
- * @return array|mixed
- */
- static function sendTelMessage($phones, $user_name, $content, $order_id)
- {
- $send_data = array();
- $send_data["cdkey"] = "8SDK-EMY-6699-RISUM";
- $send_data["password"] = "175348";
- $send_data["phone"] = $phones;
- $send_data["message"] = '【蜘蛛行】' . $content;
- if (SEND_MESSAGE == true) {
- //$url='http://www.mxtong.net.cn/GateWay/Services.asmx/DirectSend?UserID=995596&Account=alert&Password=zzcx8888&Phones='.$phones.'&Content='.$content.'【蜘蛛行】&SendTime=&SendType=1&PostFixNumber=';
- $url = 'http://hprpt2.eucp.b2m.cn:8080/sdkproxy/sendsms.action';
- //echo $url;
- $response = httpRequest($url, $send_data);
- // echo $response;die();
- writeLog('url' . $url . "返回值" . $response);
- } else {
- return array("未开启短信通知");
- }
- return $response;
- }
-
-
-
- }
|