'华为', 'oppo' => 'OPPO', 'vivo' => 'VIVO', 'xiaomi' => '小米', ]; public static function contentFormat(string $content, string $provider): string { return str_replace('{device}', self::providers[$provider], $content); } /** * @param $uid * @param $title * @param $content * @param $url * @return array|bool|mixed|string|null * @throws ApiException * @throws GuzzleException */ public static function pushMessageToUser($uid, $title, $content, $url) { // 获取用户push信息 $pushUser = QappPushUser::getPushUserByUid($uid); $regId = getProp($pushUser, 'reg_id'); $regIdList = [$regId]; if (empty($regId)) { Utils::throwError(ErrorConst::PUSH_TOKEN_INVALID); } // 获取push app信息 $pushAppId = getProp($pushUser, 'app_id'); $pushApp = QappPushApp::getPushAppByAppId($pushAppId); $package = getProp($pushApp, 'package'); $appId = getProp($pushApp, 'app_id'); $provider = getProp($pushApp, 'provider'); $appSecret = getProp($pushApp, 'app_secret'); $appKey = getProp($pushApp, 'app_key'); $masterSecret = getProp($pushApp, 'master_secret'); $content = self::contentFormat($content, $provider); $result = []; try { switch ($provider) { // 华为 case PushConst::PROVIDER_HW: // 初始化huawei推送 $client = new HwPushCommon($appId, $appSecret); // 循环推送 $client->setToken($regIdList); $result = $client->sendPushMessage($title, $content, $url); break; // 小米 case PushConst::PROVIDER_MI: // 初始化小米推送 $client = new MiPushCommon($package, $appSecret); // 循环推送 $client->setRegArr($regIdList); $result = $client->sendMessage($title, $content, $url); break; // OPPO case PushConst::PROVIDER_OPPO: // 初始化oppo推送 $client = new OPPOPushCommon($appKey, $masterSecret); $messageId = $client->getMessageId($title, $content, $url); // 循环推送 $client->setRegArr($regIdList); $result = $client->broadCastRegIds($messageId); break; case PushConst::PROVIDER_VIVO: $client = new VPush($appId, $appKey, $appSecret); $result = $client->send($regId, $title, $content, $url); break; } } catch (Exception $e) { $message = $e->getMessage(); myLog('push')->info('Exception', compact('result', 'message')); Utils::throwError(ErrorConst::PUSH_FAIELD); } return $result; } }