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

更新 短信操作

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