打你一下

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; //取消订单通知
}
unset($order["ordersn"]);
unset($order["openid"]);
unset($order["tel1"]);
unset($order["tel2"]);
unset($order["createtime"]);
unset($order["shop_id"]);
unset($order["position"]);
unset($order["cance_time"]);
unset($order["userInfo"]);
unset($order["subs_id"]);
unset($order["secret_no"]);
unset($order["userInfo"]);
unset($order["consignee"]);
unset($order["make_time"]);
unset($order["insurance_server"]);
unset($order["driver_take_distance"]);
unset($order["estimate_take_time"]);
unset($order["driver_send_distance"]);
unset($order["estimate_send_time"]);
unset($order["transaction_id"]);
unset($order["send_code"]);
unset($order["company_commission"]);
unset($order["grab_time"]);
unset($order["is_send_message"]);
unset($order["make_time_c"]);
unset($order["driver"]);
unset($order["tip_price"]);
$orderstring = json_encode($order);
$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);
}
}
}

}

posted on 2020-06-27 16:41  打你一下  阅读(284)  评论(0编辑  收藏  举报

导航