收藏
回答

/v2/bot/publish通过这个接口发布的机器人,怎么所有的回答全部失效了?

/v2/bot/publish通过这个接口发布的机器人,怎么所有的回答全部失效了?

就是通过平台的机器人发布,所有回答全部生效,然后通过接口进行发布的机器人,所有的回答就会失效。

我看了自己写的发布接口,也正确返回了的,证明接口应该是没有问题吧。

public function publish(){
         // 接口地址
        $url = 'https://openaiapi.weixin.qq.com/v2/bot/publish';
        // 替换为你的真实Token
        $token = $this->getAccessToken();
        // 请求体数据
        // 生成sign签名
        $timestamp = TM;
        $nonce = UID;
        $bodyStr = '';
        $signStr = $this->openaiToken . $timestamp . $nonce . md5($bodyStr);
        $sign = md5($signStr);    
        // 请求头信息
        $headers = [
            'Content-Type: application/json',
            'X-OPENAI-TOKEN: ' . $token,
            'request_id: ' . UID, // 生成唯一request_id
            'timestamp: ' . $timestamp,
            'nonce: ' . $nonce,
            'sign: ' . $sign,
        ];
        // 初始化cURL
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POSTFIELDS, '');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        // 执行cURL请求
        $response = curl_exec($ch);
        // dump(json_decode($response, true));
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        // 检查HTTP状态码
        if ($httpCode !== 200) {
            return json([
                'code' => -1,
                'msg' => '请求失败,HTTP状态码:' . $httpCode,
                'data' => null,
            ]);
        }
        // 解析响应
        $result = json_decode($response, true);
        if (isset($result['code']) && $result['code'] === 0) {
            return true;
        } else {
            return false;
        }
    }

回答关注问题邀请回答
收藏

1 个回答

  • 管理员LT
    管理员LT
    05-21

    您好 请提供下机器人ID,谢谢

    05-21
    有用
    回复 13
    • 输入中
      输入中
      05-21
      stovef4dbe
      05-21
      回复
    • 管理员LT
      管理员LT
      05-21回复输入中
      您好  请提供下“问题失效的错误日志”,谢谢
      05-21
      回复
    • 输入中
      输入中
      05-21
      在哪个地方
      05-21
      回复
    • 管理员LT
      管理员LT
      05-21回复输入中
      通过开放接口发布bot后,回答失效时,query 接口的调用日志
      05-21
      回复
    • 输入中
      输入中
      05-22回复管理员LT
      我没有用/v2/bot/query这个接口, 是直接在我运营的公众号上面回复的。就是通过接口发布bot,然后到公众号里面回复就不起作用,直接在对话平台发布,又可以。
      05-22
      回复
    查看更多(8)
登录 后发表内容
问题标签