|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
-
- /**
- * Created by PhpStorm.
- * User: Steven
- * Date: 2016/12/27
- * Time: 17:21
- *
- * CS系统任务通知
- * 定时任务:没十五分钟查看当前还有无待处理订单,有则通知客服
- */
-
- require_once __DIR__.'/../domain.php';
-
- class sendRTX
- {
- public function reportforCS()
- {
- $mem = new Memcache;
- $mem->connect("127.0.0.1", 11211);
- $newOrder = $mem->get('hotel_newOrder');
- if ($newOrder || count($newOrder) > 0) {
- foreach ($newOrder as $value) {
- foreach ($value as $k => $v) {
- //313待发单、382异常处理待发单,383异常处理已取消,148正常已取消,147已完成,198待确认,314已安排。
- $data[$v['type']][] = $v;
- }
- }
- $flag = false;
- $msg = "你还有以下事项待处理:\n";
- foreach ($data as $d_k => $d_v) {
- if (count($data[$d_k]) > 0) {
- if ($d_k == 313) {
- $msg .= "待发单:" . count($data[$d_k]) . "个\n";
- $flag = true;
- }
- if ($d_k == 198) {
- $msg .= "待确认:" . count($data[$d_k]) . "个\n";
- $flag = true;
- }
- if ($d_k == 382) {
- $msg .= "异常处理待发单:" . count($data[$d_k]) . "个\n";
- $flag = true;
- }
- }
- }
- if (!$flag) {
- return false;
- }
- $title = "订单处理提醒:\n";
- $this->sendMessageToRTX($title, $msg);
- }
- }
-
-
- public 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; // 返回获取的数据
- }
-
- public function sendMessageToRTX($title, $msg)
- {
- $url = $this->sinaShortenUrl('http://'. CS_DOMAIN. '/zz-jd/hotel_order_list.html');
- $msg = $msg . "\n点击查看 " . $url;
- $cuntomer_list = 'gaoj,hel,lisb,lufy,panlj,zhusy,shifp,wangxj,chenyb,luocj,zhucy'; //目的地资源部客服
- $arr = array(
- 'title' => $title,
- 'receiver' => $cuntomer_list,
- 'msg' => $msg,
- );
- $this->httpsPost('http://180.168.4.58:8012/SendNotify.cgi', $arr);
- }
-
- //获取短网址
- public function sinaShortenUrl($long_url)
- {
- $url = 'http://api.t.sina.com.cn/short_url/shorten.json?source=31641035' . '&url_long=' . $long_url;
- //获取请求结果
- $result = $this->curlQuery($url);
- $json = json_decode($result);
- //异常情况返回false
- if (isset($json->error) || !isset($json[0]->url_short) || $json[0]->url_short == '')
- return false;
- else
- return $json[0]->url_short;
- }
-
- /**
- * User:Steven
- *
- * @param $url
- * @return mixed
- */
- function curlQuery($url)
- {
- //设置附加HTTP头
- $addHead = array(
- "Content-type: application/json"
- );
- //初始化curl,当然,你也可以用fsockopen代替
- $curl_obj = curl_init();
- //设置网址
- curl_setopt($curl_obj, CURLOPT_URL, $url);
- //附加Head内容
- curl_setopt($curl_obj, CURLOPT_HTTPHEADER, $addHead);
- //是否输出返回头信息
- curl_setopt($curl_obj, CURLOPT_HEADER, 0);
- //将curl_exec的结果返回
- curl_setopt($curl_obj, CURLOPT_RETURNTRANSFER, 1);
- //设置超时时间
- curl_setopt($curl_obj, CURLOPT_TIMEOUT, 15);
- //执行
- $result = curl_exec($curl_obj);
- //关闭curl回话
- curl_close($curl_obj);
- return $result;
- }
- }
-
- $sendRTX = new sendRTX();
- $sendRTX->reportforCS();
-
- ?>
|