前言:
现在兄弟们对“php消息推送技术”大致比较着重,我们都需要知道一些“php消息推送技术”的相关文章。那么小编同时在网摘上网罗了一些对于“php消息推送技术””的相关文章,希望朋友们能喜欢,姐妹们一起来了解一下吧!<?php
namespace addons\takeoutshop\common\model;
use GatewayWorker\Lib\Gateway;
use think\Db;
use addons\takeoutshop\common\model\TakeoutshopToolAllState;
use JPush\Client as JPush;
class TakeoutshopSend {
public static function onMessage($order, $driver_client_id = "") {
$setting = Db::name("ztm_takeoutshop_setting")->where(["uniacid" => $order["uniacid"]])->find(); //company_client_id
$order["is_connect"] = 0;
if (empty($driver_client_id)) {
try {
if (empty($order["type"])) {
$order["type"] = 2; //其他的状态
$user_client_id = Db::name("ztm_takeoutshop_member")->where(["id" => $order["uid"]])->value("client_id");
$company_client_id = Db::name("ztm_takeoutshop_setting")->where(["uniacid" => $order["uniacid"]])->value("company_client_id");
if (!empty($user_client_id)) {
Gateway::sendToClient($user_client_id, json_encode($order));
}
if (!empty($setting["company_client_id"])) {
Gateway::sendToClient($company_client_id, json_encode($order));
}
}
} catch (\Exception $exc) {
file_put_contents("./notice.text", date("Y-m-d H:i:s", time()) . $exc->getMessage() . "其他状态取消" . PHP_EOL, FILE_APPEND);
}
} else {
$order["type"] = 3; //取消订单通知
}
$client = new JPush($setting["jiguang_app_key"], $setting["jiguang_master_secret"]);
if ($order["type"] == 3) {
try {
$client->push()
->setPlatform(['ios', 'android'])
->addAllAudience("ant" . $order["horseman_id"])
->message('你有新取消的订单', [
'title' => '你有新取消的订单',
'content_type' => 'text',
'extras' => [
'orderMessageType' => 1,
'order' => $orderstring]])->send();
} catch (\Exception $exc) {
file_put_contents("./notice.text", date("Y-m-d H:i:s", time()) . $exc->getMessage() . "订单取消" . PHP_EOL, FILE_APPEND);
}
}
if ($order["type"] == 1) {
try {
$client->push()
->setPlatform(['ios', 'android'])
->addAllAudience("all")
->message('你有新的订单', [
'title' => '你有新的订单',
'content_type' => 'text',
'extras' => [
'orderMessageType' => 0,
'order' => $orderstring]])->send();
} catch (\Exception $exc) {
file_put_contents("./notice.text", date("Y-m-d H:i:s", time()) . $exc->getMessage() . "订单群发" . PHP_EOL, FILE_APPEND);
}
}
}
}