【推荐页游戏卡】调用后返回为空
53 浏览2025年05月07日作者:tigerrr

为小游戏配置推荐页游戏卡,但是请求API(https://minigame.zijieapi.com/mgplatform/api/apps/open/push_feed_card)后返回为空,也有任何报错信息。使用PHP请求API。


$ch = curl_init();
            // 设置 cURL 选项
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_POST, true);
            // 设置请求头
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                "Content-Type: application/json",
                'access_token: ' . $res['data'],
            ));
            // 要发送的 POST 参数
            $data = array(
                'aid' => 2,
                'mp_id' => $appID,
                'open_id' => $openids,
                'card_id' => "258**",
                'data' => array("reward_index" => 1, "reward_count" => [1]),
            );
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
            // 执行 cURL 会话
            $response = curl_exec($ch);
            // 检查是否有错误发生
            if (curl_errno($ch)) {
                $error = curl_error($ch);
                error_log("CURL error: " . $error);
                // 关闭 cURL 会话
                curl_close($ch);
                $this->ajaxReturn(['code' => 0, "msg" => "CURL 请求出错: " . $error, 'data' => []]);
                return;
            }
            // 关闭 cURL 会话
            curl_close($ch);
            if (empty($response)) {
                $this->ajaxReturn(['code' => 0, "msg" => "服务器响应为空", 'data' => []]);
                return;
            }
            // 将响应内容解析为数组
            $resData = json_decode($response, true);
最后一次编辑于 2025 年 05 月 07 日
共 5 条评论

相关问答

专题推荐

热门文章

热门问答