MonitorEmptyFreightCost(); } public function MonitorEmptyFreightCost() { //查询2天前C仓已发货但订单运费为0的订单 $endTime = date('Y-m-d', strtotime('-2 days')); $orderIdList = DB::table('order')->where('send_time','<',$endTime)->where('warehouse',3)->where('is_del',0) ->where('logistics_id','>','')->where('status',3)->whereNull('freight_cost')->lists('id'); if(count($orderIdList) > 0) { foreach($this->phoneArr as $phone) { $this->sendMsg($phone, [$this->dr_name=>$orderIdList]); } } echo 'SUCCESS'; } public function sendMsg($phone, $orders) { $orders = json_encode($orders,JSON_UNESCAPED_UNICODE);//防止中文被转义 $params = ('#order#').'='.$orders; //提醒销售 self::sendMsgWithParams($phone,$params, $this->templateId); } 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 checkErr($result,$error) { if($result === false) { echo 'Curl error: ' . $error; } // else // { // echo '操作完成没有任何错误'; // } } private static function send($ch,$data){ curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/tpl_single_send.json'); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); $result = curl_exec($ch); $error = curl_error($ch); self::checkErr($result,$error); return $result; } //有参数发送短信验证码 public static function sendMsgWithParams($phone, $params, $template_id) { $ch=self::init(); $data=array('tpl_id' => $template_id,'apikey'=>YP_SMS_KEY_1,'mobile'=>$phone,'tpl_value'=>$params); $json_data = self::send($ch,$data); $array = json_decode($json_data,true); curl_close($ch); // $json_data = iconv('utf-8','gbk',$json_data); // print_r($json_data); return $array; } //无参数发送短信验证码 public static function sendMsgSimple($phone, $template_id) { $ch=self::init(); $data=array('tpl_id' => $template_id,'apikey'=>YP_SMS_KEY_1,'mobile'=>$phone); $json_data = self::send($ch,$data); $array = json_decode($json_data,true); curl_close($ch); return $array; } }