求助生成app_key

本文深入探讨了在使用zend-diactoros库时遇到的PHP Parse Error,详细解析了错误原因,涉及unexpected 'function' (T_FUNCTION)的问题,并提供了代码示例及解决方案,帮助开发者理解和修复此类语法错误。

 php artisan key:generate

PHP Parse error:  syntax error, unexpected 'function' (T_FUNCTION), expecting identifier (T_STRING) or \\ (T_NS_SEPARATOR) in /var/www/snipe-it/vendor/zendframework/zend-diactoros/src/functions/marshal_headers_from_sapi.php on line 10
 

<?php
/**
 * @see       https://github.com/zendframework/zend-diactoros for the canonical source repository
 * @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
 * @license   https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
 */

namespace Zend\Diactoros;

use function array_key_exists;
use function strpos;
use function strtolower;
use function strtr;
use function substr;

/**
 * @param array $server Values obtained from the SAPI (generally `$_SERVER`).
 * @return array Header/value pairs
 */
function marshalHeadersFromSapi(array $server)
{
    $headers = [];
    foreach ($server as $key => $value) {
        // Apache prefixes environment variables with REDIRECT_
        // if they are added by rewrite rules
        if (strpos($key, 'REDIRECT_') === 0) {
            $key = substr($key, 9);

            // We will not overwrite existing variables with the
            // prefixed versions, though
            if (array_key_exists($key, $server)) {
                continue;
            }
        }

        if ($value && strpos($key, 'HTTP_') === 0) {
            $name = strtr(strtolower(substr($key, 5)), '_', '-');
            $headers[$name] = $value;
            continue;
        }

        if ($value && strpos($key, 'CONTENT_') === 0) {
            $name = 'content-' . strtolower(substr($key, 8));
            $headers[$name] = $value;
            continue;
        }
    }

    return $headers;
}
 

#include "cJSON.h" const char *voice_cmd[] = {"场景模式", "回家模式", "离家模式", "会客模式", "阅读模式", "睡眠模式", "娱乐模式", "温馨模式", "明亮模式", "观影模式","灯光亮一点", "灯光最亮", "灯光暗一点", "灯光最暗","灯光暖一点","灯光最暖", "灯光冷一点", "灯光最冷", "打开窗帘", "窗帘半开", "窗帘停", "打开空调", "空调制热", "空调制冷", "关闭空调", "打开风扇", "关闭风扇", "开灯", "关灯", "关闭窗帘"}; /* mqtt JSON数据发送集中处理函数 */ void mqtt_json_send(int type_temp) { cJSON *pRoot = cJSON_CreateObject(); // 创建JSON根部结构体 cJSON *pValue = cJSON_CreateObject(); // 创建JSON子叶结构体 cJSON *pValue2 = cJSON_CreateObject(); // 创建JSON子叶结构体 cJSON *userid = cJSON_CreateObject(); // 创建JSON子叶结构体 // Preparing_encrypted_msg((uint8_t *)json_data, strlen(json_data), 1); switch (type_temp) { case 0: // 上报睡眠带数据 { cJSON_AddStringToObject(pRoot, "action", "upload_sleep_data"); cJSON_AddItemToObject(pRoot, "device", pValue); cJSON_AddStringToObject(pValue, "mac", STA_MAC_string_hex); cJSON_AddStringToObject(pValue, "type", "80"); cJSON_AddItemToObject(pRoot, "data", pValue2); cJSON_AddStringToObject(pValue2, "type", device_sleep.type_name); cJSON_AddStringToObject(pValue2, "Odata", (char *)device_sleep.Odata); cJSON_AddNumberToObject(pValue2, "index", device_sleep.index); cJSON_AddNumberToObject(pValue2, "status", device_sleep.status); cJSON_AddNumberToObject(pValue2, "heart_rate", device_sleep.heart_rate); cJSON_AddNumberToObject(pValue2, "breathe_rate", device_sleep.breathe_rate); } break; case 1: // SOS 悉知 { cJSON_AddStringToObject(pRoot, "action", "know_dev_alert"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddStringToObject(pValue, "alert_mac", sos_other_mac); } break; case 2: // SOS 悉知 { cJSON_AddStringToObject(pRoot, "action", "handle_dev_alert"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddStringToObject(pValue, "alert_mac", sos_other_mac); } break; case 3: // 发送设备数据 { int battery_voltage = 0; xQueuePeek(adc_battery_queue, &battery_voltage, 0); // 因为关闭了光感功能,所以不再读取光感电压 //int light_voltage = 0; //xQueuePeek(adc_light_queue, &light_voltage, 0); cJSON_AddStringToObject(pRoot, "action", "debug_msg"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddNumberToObject(pValue, "battery_voltage", battery_voltage); //cJSON_AddNumberToObject(pValue, "light_voltage", light_voltage); cJSON_AddNumberToObject(pValue, "sos_flag", sos.sos_flag); cJSON_AddNumberToObject(pValue, "sos_mode", sos.mode); cJSON_AddNumberToObject(pValue, "iram_free_size", iram_free_size); #if DEFINE_HARDWARE_NB cJSON_AddNumberToObject(pValue, "nb_rssi", my_nb.rssi - 256); #endif } break; case 4: // 发送SOS触发方式 { cJSON_AddStringToObject(pRoot, "action", "debug_msg"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddNumberToObject(pValue, "type", sos.type); cJSON_AddNumberToObject(pValue, "dev", sos.device_type); } break; case 5: // 发送SOS解除方式 { cJSON_AddStringToObject(pRoot, "action", "debug_msg"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddNumberToObject(pValue, "type", sos.dis_type); cJSON_AddNumberToObject(pValue, "dev", sos.device_type); } break; case 6: // 上传本地日志 { int address = 0; address = my_log_read(); if (address == -1) { cJSON_AddStringToObject(pRoot, "action", "log_msg"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddStringToObject(pValue, "local_log", "get fail"); my_log_new(); } else { queue_data_t *data = (queue_data_t *)address; ESP_LOGW(TAG, "len = %d, data : %s", data->len, data->data); cJSON_AddStringToObject(pRoot, "action", "log_msg"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddStringToObject(pValue, "local_log", (char *)data->data); free((char *)address); my_log_new(); } } break; case 7: // 发送电池电压 { int battery_voltage = 0; xQueuePeek(adc_battery_queue, &battery_voltage, 0); cJSON_AddStringToObject(pRoot, "action", "report_msg"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddNumberToObject(pValue, "battery_voltage", battery_voltage); cJSON_AddStringToObject(pValue, "battery_status", "dry"); } break; case 8: // 上报WIFI信息 { cJSON_AddStringToObject(pRoot, "action", "report_wifi_ap_msg"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddStringToObject(pValue, "s1", (char *)backup_wifi_config[0].ssid); cJSON_AddStringToObject(pValue, "p1", (char *)backup_wifi_config[0].password); cJSON_AddStringToObject(pValue, "s2", (char *)backup_wifi_config[1].ssid); cJSON_AddStringToObject(pValue, "p2", (char *)backup_wifi_config[1].password); } break; case 9: // 上报睡眠带分钟数据 { cJSON_AddStringToObject(pRoot, "action", "upload_sleep_data_min"); cJSON_AddItemToObject(pRoot, "device", pValue); cJSON_AddStringToObject(pValue, "mac", STA_MAC_string_hex); cJSON_AddStringToObject(pValue, "type", "80"); cJSON_AddItemToObject(pRoot, "data", pValue2); cJSON_AddStringToObject(pValue2, "type", device_sleep.type_name); // cJSON_AddStringToObject(pValue2, "Odata", (char *)device_sleep.Odata); cJSON_AddNumberToObject(pValue2, "index", device_sleep.index_min); cJSON_AddNumberToObject(pValue2, "status", device_sleep.status_min); cJSON_AddNumberToObject(pValue2, "heart_rate", device_sleep.heart_rate_min); cJSON_AddNumberToObject(pValue2, "breathe_rate", device_sleep.breathe_rate_min); cJSON_AddNumberToObject(pValue2, "body_move_cnt", device_sleep.body_move_cnt); cJSON_AddNumberToObject(pValue2, "snore_cnt", device_sleep.snore_cnt); cJSON_AddNumberToObject(pValue2, "breathe_rate", device_sleep.breathe_rate_min); cJSON_AddNumberToObject(pValue2, "respiratory_disturbance", device_sleep.respiratory_disturbance); cJSON_AddNumberToObject(pValue2, "PTHD", device_sleep.PTHD); cJSON_AddNumberToObject(pValue2, "temperature", device_sleep.temperature); } break; case 10: // 回复OK { cJSON_AddStringToObject(pRoot, "action", action_type); cJSON_AddStringToObject(pRoot, "data", "OK"); } break; case 11: // 触发求助 { char str_type[8] = {0}; cJSON_AddStringToObject(pRoot, "action", "sos_start"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddNumberToObject(pValue, "type", sos.type); sprintf(str_type, "%02X", sos.device_type); cJSON_AddStringToObject(pValue, "dev", str_type); } break; case 12: // 解除求助 { char str_type[8] = {0}; cJSON_AddStringToObject(pRoot, "action", "sos_stop"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddNumberToObject(pValue, "type", sos.dis_type); sprintf(str_type, "%02X", sos.device_type); cJSON_AddStringToObject(pValue, "dev", str_type); } break; case 13: // 设备回应邀请 { cJSON_AddStringToObject(pRoot, "action", "device_join_rsp"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddNumberToObject(pValue, "type", 1); } break; case 14: // 重复发送报警 { char str_type[8] = {0}; cJSON_AddStringToObject(pRoot, "action", "sos_resend"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddNumberToObject(pValue, "type", sos.type); sprintf(str_type, "%02x", sos.device_type); cJSON_AddStringToObject(pValue, "dev", str_type); } break; // case 14: // 请求不通过 // { // cJSON_AddStringToObject(pRoot, "action", "add_ack"); // cJSON_AddItemToObject(pRoot, "data", pValue); // cJSON_AddStringToObject(pValue, "result", "ERR"); // } // break; case 15: { cJSON_AddStringToObject(pRoot, "action", "upload_all_sleep_report"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddStringToObject(pValue, "report", (char *)device_sleep.report_data); } break; case 16: { cJSON_AddStringToObject(pRoot, "action", "upload_sleep_report_detail"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddNumberToObject(pValue, "time", device_sleep.report_time); cJSON_AddStringToObject(pValue, "detail", (char *)device_sleep.report_data); } break; case 17: // 自学习成功 { cJSON_AddStringToObject(pRoot, "action", "learn_help_ack"); cJSON_AddStringToObject(pRoot, "data", "success"); } break; case 18: // 自学习失败或退出 { cJSON_AddStringToObject(pRoot, "action", "learn_help_ack"); cJSON_AddStringToObject(pRoot, "data", "fail"); } break; case 19: { uint8_t temp_data_cmd = 0; xQueuePeek(offline_voice_cmd_queue, (void *)&temp_data_cmd, 0); cJSON_AddStringToObject(pRoot, "action", "voice_cmd"); cJSON_AddStringToObject(pRoot, "data", voice_cmd[temp_data_cmd]); } break; case 20: //设备回应邀请(设备->云端) { cJSON_AddStringToObject(pRoot, "action", "device_join_rsp"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddNumberToObject(pValue, "type", 2); } break; case 21: //SOS识别到上报 { cJSON_AddStringToObject(pRoot, "action", "sos_detected"); } break; case 22: //产测完成上报 { cJSON_AddStringToObject(pRoot, "action", "testing_completed"); } break; case 27: { cJSON_AddStringToObject(pRoot, "action", "confirm_add_device_rsp"); cJSON_AddItemToObject(pRoot, "data", userid); cJSON_AddNumberToObject(userid, "userid", g_userid); } break; case 28: { cJSON_AddStringToObject(pRoot, "action", "wake_up"); } break; case 29: { int tim_show; tim_show = update_cnt; cJSON_AddStringToObject(pRoot, "action", "time_new"); cJSON_AddItemToObject(pRoot, "data", pValue); cJSON_AddNumberToObject(pValue, "type", tim_show); } break; case 30: { cJSON_AddStringToObject(pRoot, "action", "LCD_Config"); } break; /*case 31: { //uint8_t data_cmd_id = 0; xQueuePeek(offline_voice_cmd_queue, (void *)&data_cmd_id, 0); cJSON_AddStringToObject(pRoot, "action", "new_voice_cmd"); cJSON_AddStringToObject(pRoot, "data", voice_cmd[data_cmd_id]); }*/ /*break; case 32: { cJSON_AddStringToObject(pRoot, "action", "new_voice_cmd"); cJSON_AddStringToObject(pRoot, "data", voice_cmd[0x10]); } break;*/ case 51: { #if DEFINE_SOFT_blood_pressure extern uint8_t blood_pressure_result[6]; char temp_data[16] = {0}; sprintf(temp_data, "%02x%02x%02x%02x%02x%02x", blood_pressure_result[0], blood_pressure_result[1], blood_pressure_result[2], blood_pressure_result[3], blood_pressure_result[4], blood_pressure_result[5]); cJSON_AddStringToObject(pRoot, "action", "blood_pressure_result"); cJSON_AddStringToObject(pRoot, "data", temp_data); #endif } break; case 0xFF: { } break; default: break; } //printf("esp_get_minimum_free_heap_size : %d \n", esp_get_minimum_free_heap_size()); //printf("[APP] Free memory: %d bytes\n", esp_get_free_heap_size()); char *json_data = cJSON_PrintUnformatted(pRoot); // ESP_LOGI(TAG, "json_data : \n%s\n", json_data); /*if (!json_data) { cJSON_Delete(pRoot); return; }*/ int json_data_len = strlen(json_data); // ESP_LOGI(TAG, "json_data_len : %d", json_data_len); Preparing_encrypted_msg((uint8_t *)json_data, json_data_len, 1); cJSON_free(json_data); cJSON_Delete(pRoot); ESP_LOGE("MEM", "[msgrecv] Free heap: %u", (unsigned int)esp_get_free_heap_size()); } 这段函数哪里会导致内存泄露的问题,因为每次调用后都会减少内存
最新发布
08-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值