京东jcq消息列队接口获取订单信息和改变订单状态

直接上代码,对应的值按照自己jcq消息列队上面填就OK。

url = "https://jcq-shared-004-httpsrv-pub-nlb-FI.jvessel-open-hb.jdcloud.com:443";
        $this->accessKey = '';
        $this->secretKey = '';
        $this->topic = 'open_message_medicine_ordchange_64FC3A8881B204A7EAAD320476343ED9';//状态改变
        $this->consumerGroupId = 'open_message_622491002583';
        $this->topic_new = 'open_message_medicine_ordcreate_64FC3A8881B204A7EAAD320476343ED9';//新订单

    }

    //获取消息
    public function ct_order_create()
    {
        $size = 30;//每次拉取条数
        $url = $this->url . "/v2/messages?topic=" . $this->topic_new . "&consumerGroupId=" . $this->consumerGroupId . "&size=" . $size;
        $dateTime = gmdate("Y-m-d\TH:i:s\Z");
        $headers[] = 'accessKey: ' . $this->accessKey;
        $headers[] = 'dateTime: ' . $dateTime;
        $data['accessKey'] = $this->accessKey;
        $data['dateTime'] = $dateTime;
        $data['topic'] = $this->topic_new;
        $data['consumerGroupId'] = $this->consumerGroupId;
        $data['size'] = $size;
        $headers[] = 'signature: ' . $this->getSignature($data);
        $get = $this->postData($url, $headers);
        $get = json_decode($get, true);
        //获取消息
        $messages = $get['result']['messages'];
        $ackIndex = $get['result']['ackIndex'];

        if (is_array($messages)) {
            foreach ($messages  as $k=>$v) {
                $body = $v['messageBody'];
                $businessinfo = json_decode($body, true);
                $order_id = $businessinfo['businessinfo']['orderId'];
                //调用获取单条订单信息接口
                //jingdong.medicine.ds.order.getOrder ( 获取单个店送订单 )
                $fx = new functions();
                $newOrderData = $fx->getOneOrders($order_id);
                $newOrderData = json_decode(json_encode($newOrderData),true);
                if (is_array($newOrderData) &&
                    $newOrderData['jingdong_medicine_ds_order_getOrder_responce']['ApiResult']['msg'] == "success" &&
                    !empty($newOrderData['jingdong_medicine_ds_order_getOrder_responce']['ApiResult']['data'])) {
                    //返回请求到的数据
                    $orderDataArray = $newOrderData['jingdong_medicine_ds_order_getOrder_responce']
                    ['ApiResult']['data'];     
                }
            }
        }
    }

    //获取状态改变消息
    public function ct_order_change()
    {
        $size = 30;//每次拉取条数
        $ack = 'true';
        //$url = $this->url . "/v2/messages?topic=" . $this->topic . "&consumerGroupId=" . $this->consumerGroupId . "&size=" . $size . "&ack=" . $ack;
        $url = $this->url . "/v2/messages?topic=" . $this->topic . "&consumerGroupId=" . $this->consumerGroupId . "&size=" . $size;
        $dateTime = gmdate("Y-m-d\TH:i:s\Z");
        $headers[] = 'accessKey: ' . $this->accessKey;
        $headers[] = 'dateTime: ' . $dateTime;
        $data['accessKey'] = $this->accessKey;
        $data['dateTime'] = $dateTime;
        $data['topic'] = $this->topic;
        $data['consumerGroupId'] = $this->consumerGroupId;
        $data['size'] = $size;
        //$data['ack'] = $ack;
        $headers[] = 'signature: ' . $this->getSignature($data);
        $get = $this->postData($url, $headers);
        $get = json_decode($get, true);
        $ackIndex = $get['result']['ackIndex'];
        //获取消息
        $messages = $get['result']['messages'];
        if (is_array($messages)) {
            foreach ($messages  as $k=>$v) {
                $body = $v['messageBody'];
                $businessinfo = json_decode($body, true);
                $order_id = $businessinfo['businessinfo']['orderId'];
                //调用获取单条订单信息接口
                //jingdong.medicine.ds.order.getOrder ( 获取单个店送订单 )
                $fx = new functions();
                $newOrderData = $fx->getOneOrders($order_id);
                $newOrderData = json_decode(json_encode($newOrderData),true);
                if (is_array($newOrderData) &&
                    $newOrderData['jingdong_medicine_ds_order_getOrder_responce']['ApiResult']['msg'] == "success" &&
                    !empty($newOrderData['jingdong_medicine_ds_order_getOrder_responce']['ApiResult']['data'])) {
                    //获取请求的数据
                    $orderDataArray = $newOrderData['jingdong_medicine_ds_order_getOrder_responce']
                    ['ApiResult']['data'];
                }
            }
        }
    }

你可能感兴趣的:(京东jcq消息列队接口获取订单信息和改变订单状态)