我正在尝试使用 c# 中的匿名类型发送 WhatsApp 云 API 消息。以下代码运行正常:
// Request Body
var body = new
{
messaging_product = "whatsapp",
to = "92" + patient.Phone.TrimStart('0'), // Use the entered recipient's phone number
type = "template",
template = new
{
name = "appointment_new",
language = new
{
code = "en"
},
components = new[]
{
new
{
type = "header",
parameters = new[]
{
new
{
type = "text",
text = clinicname??"Appointment"
}
}
},
new
{
type = "body",
parameters = new[]
{
new
{
type = "text",
text = $"test"
}
}
}
}
},
message = "test" // Use the entered message
};
但我想使用 mediaId 在标头中发送 PDF 文件。因此我进行了以下更改,例如:
// Request Body
var body = new
{
messaging_product = "whatsapp",
to = "92" + patient.Phone.TrimStart('0'), // Use the entered recipient's phone number
type = "template",
template = new
{
name = "appointment_new",
language = new
{
code = "en"
},
components = new[]
{
new
{
type = "header",
parameters = new[]
{
new
{
type = "document", //////change
document = new //////change
{
id = mediaId //////change
}
}
}
},
new
{
type = "body",
parameters = new[]
{
new
{
type = "text",
text = $"test"
}
}
}
}
},
message = "test" // Use the entered message
};
但是 Visual Studio 在此处给出语法错误:No best type found for implicitly-typed array
我想了解原因?第一个代码和第二个代码有什么不同?AI 也发布了第二个版本,没有其他想法。