$access_token, 'timestamp' => time(), 'nonce' => md5(uniqid('', true)) ]; // 用户标识 $userId = array_filter([ 'wechat_app_id' => $data['wechat_app_id'], 'wechat_openid' => $data['wechat_openid'] ?? null, 'wechat_unionid' => $data['wechat_unionid'] ?? null ]); $parameters = [ 'account_id' => intval($data['account_id']), 'user_action_set_id' => intval($data['user_action_set_id']), 'actions' => [ [ 'action_time' => intval($data['action_time']), 'user_id' => $userId, 'action_type' => $data['action_type'], // 'trace' => [ // 'click_id' => $data['click_id'] // ] // 'action_param' => [ // 'value' => $data['value'], // 'object' => $data['object'], // 'product_name' => $data['product_name'] ?? null // ] ] ] ]; if(isset($data['click_id'])) { $parameters['actions'][0]['trace']['click_id'] = $data['click_id']; } // if(empty($parameters['actions'][0]['action_param']['product_name'])) { // unset($parameters['actions'][0]['action_param']['product_name']); // } $parameters = json_encode($parameters); $request_url = $url . '?' . http_build_query($common_parameters); do { try { $res = HttpService::httpPost($request_url, $parameters, true); } catch (\Throwable $e) { Log::logError('数据回传接口请求异常', [ 'params' => json_encode($parameters), 'msg' => $e->getTraceAsString() ], 'UserActionsOpenApi'); } // 记录日志 Log::logInfo('数据上报API:' . $interface, [ 'url' => $request_url, 'params' => $parameters, 'response' => $res, ], 'UserActionsOpenApi'); $resArr = json_decode($res, true); if (!$resArr) { $resArr = [ 'code' => 666666, 'message' => '请求失败(自定义)' ]; } } while(($resArr['code'] != 0) && (--$retry > 0)); if ($resArr['code'] == 0) { return self::returnSuccess([]); } else { return self::returnFail([], $resArr['message']); } } }