session Error: Bad Request 求助

在沙盒是能正常运行的
错误
session Error: Bad Request
at [cordis.invoke] (C:\Users\zhang\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules@cordisjs\plugin-http\lib\index.cjs:334:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async [as sendPrivateMessage] (C:\Users\zhang\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules@satorijs\adapter-qq\lib\index.cjs:587:32)
at async send (C:\Users\zhang\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules@satorijs\adapter-qq\lib\index.cjs:991:46)
at async QQMessageEncoder.flush (C:\Users\zhang\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules@satorijs\adapter-qq\lib\index.cjs:1019:5)
at async QQMessageEncoder.send (C:\Users\zhang\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules@satorijs\core\lib\index.cjs:625:5)
at async Proxy.sendMessage (C:\Users\zhang\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules@satorijs\core\lib\index.cjs:355:22)
at async _Command.eval (eval at (C:\Users\zhang\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\koishi-plugin-blockly-null\lib\index.js:197:32), :9:7)
at async Array. (C:\Users\zhang\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules@koishijs\core\lib\index.cjs:1078:14)
at async _Command.execute (C:\Users\zhang\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules@koishijs\core\lib\index.cjs:1092:22)
at async C:\Users\zhang\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules@koishijs\core\lib\index.cjs:2059:22
at async Proxy.withScope (C:\Users\zhang\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules@koishijs\core\lib\index.cjs:1968:22)
at async next (C:\Users\zhang\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules@koishijs\core\lib\index.cjs:824:16)
at async next (C:\Users\zhang\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules@koishijs\core\lib\index.cjs:824:16)
at async next (C:\Users\zhang\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules@koishijs\core\lib\index.cjs:824:16)
at async Processor._handleMessage (C:\Users\zhang\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules@koishijs\core\lib\index.cjs:835:22)

代码
import { JSONPath as parseJson } from “jsonpath-plus”
export const name = “api”
export async function apply(ctx){
ctx.command(‘111 <域名:string>’).action(async ({session},…args)=>{
{
let msg = await ctx.http.get((‘https://who.cx/api/price?domain=域名’ + String(args[0])),{responseType:“json”});
await session.send(([‘域名价格(仅供参考) ‘,await parseJson({path: “$.domain”, json: msg}),’ 价格’,await parseJson({path: “$.new”, json: msg}),’ 续费’,await parseJson({path: “$.renew”, json: msg})].join(‘’)));
}

});

}

1 个赞

你要不要看看你写的什么玩意

2 个赞

代码逻辑没啥大问题,报错是 blockly-null 的和你的插件没关系(应该?

2 个赞

我写的话喜欢这样写

import { Context, Schema } from "koishi"

export const name = "domain-price"
export interface Config { }
export const Config: Schema<Config> = Schema.object({})

export async function apply(ctx: Context) {
  ctx.command('domain-price <domain:string>')
    .action(async (_, domain) => {
      const res = await ctx.http.get<DomainPrice>(`https://who.cx/api/price?domain=${domain}`)
      if (res.code !== 200) return `获取域名价格失败,错误码:${res.code},服务器返回的信息:${res.msg}`
      return `域名价格(仅供参考): ${res.domain} 价格: ${res.new + res.currency_symbol} 续费: ${res.renew + res.currency_symbol}`
    })
}

// {"code":200,"currency":"CNY","currency_symbol":"\u00a5","domain":"koishi.chat","new":"36","renew":"67"}
// {"code":400,"domain":"wtf","msg":"\u57df\u540d\u683c\u5f0f\u4e0d\u6b63\u786e\uff01"}
interface DomainPrice {
  code: number
  currency?: string
  currency_symbol?: string
  domain: string
  new?: string
  renew?: string
  msg?: string
}

2 个赞

感谢回复,是我没说清楚,这个代码是blockly生成的,在沙盒里的运行是正常的,但是在qq测试时会bad request



2 个赞

image
有没有可能你这请求参数也有问题 虽然不影响结果输出就是了

把域名俩字去掉

2 个赞

估计有可能应该不确定我觉得是因为你返回的字符串里带了域名 然后因为没过白被腾讯拦了

3 个赞

这个应该没问题

2 个赞

好像是这个原因

2 个赞

厉害,我完全没想到 QQ 是 QQ

是我观察不够仔细了

2 个赞

辛苦了

2 个赞

十分感谢

2 个赞

也有点问题,指绿色方块里不需要加 域名 二字,加了之后你查询的每个域名都会变成 域名xxx.com 这种的中文域名,可以删除的

2 个赞

ok好的

2 个赞