url = $this->ghsUrl; } else if ($client == 'hd') { $this->url = $this->hdUrl; } else { throw new \Exception('client not found'); } } public function pushByCloud($cids, $title, $content, $payload = []) { $sign = md5($title . $content . $this->secret); $optionsArr = [ "android" => [ // "XM" => [ // "/extra.channel_id" => "" //小米后台申请的通知类别id // ], "HW" => [ "/message/android/category" => "EXPRESS" ] ] ]; $data = [ 'cid' => is_array($cids) ? $cids : [$cids], 'title' => $title, 'content' => $content, 'payload' => $payload, 'force_notification' => true, // true: 无论是离线推送还是在线推送,都自创建通知栏消息 'sign' => $sign, 'options' => $optionsArr ]; $ch = curl_init($this->url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json' ]); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); $res = curl_exec($ch); curl_close($ch); return json_decode($res, true); } }