Manage.php.bak.20201202 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Controller;
  4. use think\Session;
  5. use think\Db;
  6. use think\Request;
  7. class Manage extends Controller
  8. {
  9. private $host="https://device.api.ct10649.com:8743/";
  10. private $appId="wvdOfp7JVe0ULwnFKwBF0edfbcAa";
  11. private $secret="Bihoe_rY9vebXMw6sFfpQy0jiRca";
  12. public function index(){
  13. $data_list =Db::table('managelog')->paginate();
  14. $pages = $data_list->render();
  15. $this->assign('data_list', $data_list);
  16. $this->assign('pages', $pages);
  17. //所有的服务类型
  18. $SetType=[
  19. 1=>"读取模块信息",
  20. 2=>"读取参数",
  21. 3=>"设置IOT平台IP地址",
  22. 4=>"设置参数",
  23. 5=>"复位模块",
  24. 6=>"配置下行波特率",
  25. 7=>"读取下行波特率配置",
  26. 8=>"设置DTU自动采集指令",
  27. 9=>"读取DTU自动采集指令",
  28. 10=>"设置APN",
  29. 11=>"读取APN设置",
  30. 12=>"AT指令",
  31. /* [1,"读取模块信息"],[2,"读取参数"],[3,"设置IOT平台IP地址"],[4,"设置参数"],[5,"复位模块"],[6,"配置下行波特率"],
  32. [7,"读取下行波特率配置"],[8,"设置DTU自动采集指令"],[9,"读取DTU自动采集指令"],[10,"设置APN"],[11,"读取APN设置"],
  33. [12,"AT指令"]*/
  34. ];
  35. $this->assign('SetType',$SetType);
  36. return $this->fetch();
  37. }
  38. //下发命令
  39. public function add(){
  40. if ($this->request->isPost()) {
  41. $data=$_POST;
  42. //调用电信接口
  43. $token=json_decode(gettoken(),true);
  44. $sendata=[
  45. "appId"=>$this->appId,
  46. "deviceId"=>$data['deviceId'],// c448d5e3-2ec5-4e42-99d7-0ad27668614f 137effbe-4980-4719-a768-0ae301fc5000
  47. "command"=>[
  48. "serviceId"=>"SomkNotifiction",
  49. "method"=>"REPORT",
  50. ],
  51. "callbackUrl"=>"http://www.jd-ioe.com:80/ytapi/admin/Manage/status",
  52. ];
  53. $header=[
  54. "Content-Type:application/json",
  55. "app_key:".$this->appId,
  56. "Authorization:Bearer ".$token["accessToken"]
  57. ];
  58. $rescurl=curl($this->host."iocm/app/cmd/v1.4.0/deviceCommands",json_encode($sendata),$header);
  59. var_dump($rescurl);
  60. if($rescurl[0]==201){//成功
  61. $res1=json_decode($rescurl[1],true);
  62. var_dump($res1);
  63. }else{//失败
  64. // $res2=json_decode($res1[1],true);
  65. return $this->error($rescurl[1]);
  66. }
  67. //将请求的结果存入managelog中
  68. $list=array();
  69. $list['commandId']=$res1['commandId'];
  70. $list['deviceId']=$res1['deviceId'];
  71. $list['status']=$res1['status'];
  72. $list['command']= json_encode($res1['command'],320) ;
  73. $list['IMEI']=$data['IMEI'];
  74. $list['HexStr']="";
  75. $list['settype']="";
  76. $list['addtime']= date('Y-m-d H:i:s');
  77. $res = Db::name('managelog')->insertGetId($list);//将推送的数据存入总表
  78. if($res) {
  79. return $this->success('添加成功','index');
  80. }else{
  81. return $this->error("添加失败,请稍后再试");
  82. }
  83. }
  84. if($this->request->isGet()){
  85. $deviceId=input('deviceId');
  86. $IMEI=input('IMEI');
  87. //所有的服务类型
  88. $SetType=[
  89. [1,"读取模块信息"],[2,"读取参数"],[3,"设置IOT平台IP地址"],[4,"设置参数"],[5,"复位模块"],[6,"配置下行波特率"],
  90. [7,"读取下行波特率配置"],[8,"设置DTU自动采集指令"],[9,"读取DTU自动采集指令"],[10,"设置APN"],[11,"读取APN设置"],
  91. [12,"AT指令"]
  92. ];
  93. $this->assign('SetType',$SetType);
  94. $this->assign('deviceId',$deviceId);
  95. $this->assign('IMEI', $IMEI);
  96. return $this->fetch();
  97. }
  98. }
  99. public function status(){
  100. $data=input('');
  101. if(is_array($data)){
  102. $getdata= json_encode($data,320);
  103. $getdata=json_decode($getdata,true);//转成数组
  104. $list['type']=1;
  105. }else{
  106. $getdata=$data;
  107. $getdata=json_decode($getdata,true);//转成数组
  108. $list['type']=2;
  109. }
  110. $list=array();
  111. $list['deviceId']=$getdata['deviceId'];
  112. $list['commandId']=$getdata['commandId'];
  113. $list['resultCode']=$getdata['result']['resultCode'];
  114. $list['result']= json_encode($getdata['result'],320) ;
  115. $list['addtime']= date('Y-m-d H:i:s');
  116. $res = Db::name('managedata')->insertGetId($list);//将推送的数据存入总表
  117. echo 111;
  118. }
  119. public function delete(){
  120. echo 111;
  121. }
  122. }