Commit de6c3ce2 authored by 冯超鹏's avatar 冯超鹏

更新 短信操作

parent 4546c1c7
Pipeline #240 canceled with stages
...@@ -11,6 +11,7 @@ use App\Http\Controllers\DevicesController; ...@@ -11,6 +11,7 @@ use App\Http\Controllers\DevicesController;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use App\Http\Controllers\Auth\SwooleCommandMeTcpController; use App\Http\Controllers\Auth\SwooleCommandMeTcpController;
use App\Http\Controllers\SmsailiyunController; use App\Http\Controllers\SmsailiyunController;
class ZehongTcpController extends Controller class ZehongTcpController extends Controller
{ {
...@@ -35,15 +36,15 @@ class ZehongTcpController extends Controller ...@@ -35,15 +36,15 @@ class ZehongTcpController extends Controller
$devicecrc = substr($data, 22, 4); $devicecrc = substr($data, 22, 4);
$isdata = substr($data, 0, 22); $isdata = substr($data, 0, 22);
// return $this->jsonSuccessData([$this->getPrc($isdata),$devicecrc]); // return $this->jsonSuccessData([$this->getPrc($isdata),$devicecrc]);
if($this->getPrc($isdata) == $devicecrc){ if ($this->getPrc($isdata) == $devicecrc) {
$data = ['id'=>$deviceId,'status'=>$status,'np'=>$devicenp,'famen'=>$devicefamen,'chongqi'=>$devicechongqi,'zijian'=>$devicezijian]; $data = ['id' => $deviceId, 'status' => $status, 'np' => $devicenp, 'famen' => $devicefamen, 'chongqi' => $devicechongqi, 'zijian' => $devicezijian];
$totcp = json_decode($this->mysqldb($data),true); $totcp = json_decode($this->mysqldb($data), true);
if ($totcp == "No equipment"){ if ($totcp == "No equipment") {
return $totcp; return $totcp;
} }
$totcpdata = $totcp['devicenum'] . $totcp['device_control'] . $devicechongqi . $devicezijian; $totcpdata = $totcp['devicenum'] . $totcp['device_control'] . $devicechongqi . $devicezijian;
$crcdata = $this->getPrc($totcpdata); $crcdata = $this->getPrc($totcpdata);
return $totcpdata .$crcdata ; return $totcpdata . $crcdata;
} }
} else { } else {
return "Data format error"; return "Data format error";
...@@ -78,42 +79,50 @@ class ZehongTcpController extends Controller ...@@ -78,42 +79,50 @@ class ZehongTcpController extends Controller
} }
} }
//return the result as HEX-formatted string //return the result as HEX-formatted string
$data = strrev(sprintf('%04X', $crc)); $data = strrev(sprintf('%04X', $crc));
$crc1 = strrev(substr($data, 0, 2)); $crc1 = strrev(substr($data, 0, 2));
$crc2 = strrev(substr($data, 2, 2)); $crc2 = strrev(substr($data, 2, 2));
return $crc1 . $crc2; return $crc1 . $crc2;
} }
//获取上报数据从数据库查询 //获取上报数据从数据库查询
public function mysqldb($data){ public function mysqldb($data)
if($data != []){ {
if ($data != []) {
// 报警提醒 // 报警提醒
$meTcp = new SwooleCommandMeTcpController(); $meTcp = new SwooleCommandMeTcpController();
$alarmData = $data['id'] . '/' . $data['status'] . '/' . $data['np']; $alarmData = $data['id'] . '/' . $data['status'] . '/' . $data['np'];
$meTcp->swooletcplist($alarmData); $meTcp->swooletcplist($alarmData);
$this->smsphone($data); $this->smsphone($data);
$datainfo = DB::table('device') $datainfo = DB::table('device')
->where('devicenum','=',$data['id']) ->where('devicenum', '=', $data['id'])
->update(['nd'=>intval($data['np']),'devicepolice'=>$data['status'] == 0 ? '1' : $data['status'],'update_time'=>time(),'shutoff_status'=>$data['famen']]); ->update(['nd' => intval($data['np']), 'devicepolice' => $data['status'] == 0 ? '1' : $data['status'], 'update_time' => time(), 'shutoff_status' => $data['famen']]);
$todata = DB::table('device') $todata = DB::table('device')
->where('devicenum','=',$data['id']) ->where('devicenum', '=', $data['id'])
->select('devicenum','nd','device_control','devicepolice') ->select('devicenum', 'nd', 'device_control', 'devicepolice')
->first(); ->first();
if ($todata){ if ($todata) {
return json_encode($todata); return json_encode($todata);
}else{ } else {
return json_encode("No equipment"); return json_encode("No equipment");
} }
} }
} }
// 发送手机报警信息 // 发送手机报警信息
public function smsphone($data){ public function smsphone($data)
if(Redis::get('smsyanshi') != ''){ {
if($data['status'] != 1 || $data['status'] != 0){ if (Redis::get($data['id']) != '') {
$sms = new SmsailiyunController(); if ($data['status'] == 1 || $data['status'] == 0) {
$code = json_encode($sms->sendSms(),true); Redis::del($data['id']);
if($code['Message'] == 'OK' && $code['Code'] == 'OK'){ } else {
Redis::set('smsyanshi',$code); if ($data['status'] != 1 || $data['status'] != 0) {
$sms = new SmsailiyunController();
$code = json_encode($sms->sendSms(), true);
if ($code['Message'] == 'OK' && $code['Code'] == 'OK') {
Redis::set($data['id'], $code);
}
} }
} }
} }
......
...@@ -66,7 +66,7 @@ class SmsailiyunController ...@@ -66,7 +66,7 @@ class SmsailiyunController
// 必填,设置短信接收号码 // 必填,设置短信接收号码
// 15200013720 // 15200013720
$request->setPhoneNumbers("16631150870"); $request->setPhoneNumbers("15200013720");
// 必填,设置签名名称,应严格按"签名名称"填写,请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/sign // 必填,设置签名名称,应严格按"签名名称"填写,请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/sign
$request->setSignName("泽宏云"); $request->setSignName("泽宏云");
...@@ -76,7 +76,7 @@ class SmsailiyunController ...@@ -76,7 +76,7 @@ class SmsailiyunController
// 可选,设置模板参数, 假如模板中存在变量需要替换则为必填项 // 可选,设置模板参数, 假如模板中存在变量需要替换则为必填项
$request->setTemplateParam(json_encode(array( // 短信模板中字段的值 $request->setTemplateParam(json_encode(array( // 短信模板中字段的值
"cphone"=>"16631150870", "cphone"=>"15200013720",
"position"=>"您的设备尾号为" . 5712, "position"=>"您的设备尾号为" . 5712,
"alarm" => '离线' "alarm" => '离线'
), JSON_UNESCAPED_UNICODE)); ), JSON_UNESCAPED_UNICODE));
......
...@@ -14520,7 +14520,7 @@ ...@@ -14520,7 +14520,7 @@
}, },
"uppercamelcase": { "uppercamelcase": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npm.taobao.org/uppercamelcase/download/uppercamelcase-1.1.0.tgz", "resolved": "https://registry.npmjs.org/uppercamelcase/-/uppercamelcase-1.1.0.tgz",
"integrity": "sha1-Mk2YprOvx+iolT4QZBUJsOTiP5c=", "integrity": "sha1-Mk2YprOvx+iolT4QZBUJsOTiP5c=",
"requires": { "requires": {
"camelcase": "^1.2.1" "camelcase": "^1.2.1"
...@@ -14528,7 +14528,7 @@ ...@@ -14528,7 +14528,7 @@
"dependencies": { "dependencies": {
"camelcase": { "camelcase": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npm.taobao.org/camelcase/download/camelcase-1.2.1.tgz", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz",
"integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=" "integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk="
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment