fudiwei / DotNetCore.SKIT.FlurlHttpClient.Wechat

可能是全网最完整的 C# 版微信 SDK,封装全部已知的微信 OpenAPI,包含微信公众平台(订阅号+服务号+小程序+小游戏+小商店+视频号)、微信开放平台、微信商户平台(微信支付+微企付)、企业微信、微信广告平台、微信智能对话开放平台等模块,可跨平台。持续随官方更新,欢迎 Star/Fork/PR。QQ 交流群 875580418【满】、930461548【满】、611974621。
https://github.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient
MIT License
1.51k stars 290 forks source link

[BUG] 智能对话接口过时 #69

Closed dydhyhwu closed 1 year ago

dydhyhwu commented 1 year ago

智能对话文档(签名、智能对话)

关于智能对话的接口,仓库中的实现有如下几个问题:

  1. SignRequestAIBotRequest根据目前的文档,不需要加密。目前代码里实现了WechatOpenAIPlatformRequest.Serialization.IEncryptedXmlable接口,导致这两个接口进行了加密,从而请求失败。
  2. AIBotResponse结构已更新,无需data包裹。

与问题相关的源代码

public class TestCase_AIBotTests
{
    [Fact(DisplayName = "测试用例:智能对话")]
    public async void TestSendMessage()
    {
        var client = new TestClients();

        var signRequest = new SignRequest()
        {
            UserId = "test"
        };
        var signResponse = await TestClients.InstanceForPlatform.ExecuteSignAsync(signRequest);

        var request = new AIBotRequest()
        {
            Signature = signResponse.Signature,
            QueryString = "你说啥",
            Timeout = 36000
        };

        var response = await TestClients.InstanceForPlatform.ExecuteAIBotAsync(request);
        var str = Encoding.UTF8.GetString(response.RawBytes);
        Console.WriteLine(response);
    }
}

异常堆栈或异常原因

System.InvalidOperationException: There was an error generating the XML document.

System.InvalidOperationException
There was an error generating the XML document.
   at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
   at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces)
   at SKIT.FlurlHttpClient.Wechat.OpenAI.Utilities.XmlUtility.Serialize(Type type, Object obj) in C:\Users\dell\RiderProjects\DotNetCore.SKIT.FlurlHttpClient.Wechat\src\SKIT.FlurlHttpClient.Wechat.OpenAI\Utilities\Internal\XmlUtility.cs:line 48
   at SKIT.FlurlHttpClient.Wechat.OpenAI.Utilities.XmlUtility.Serialize[T](T obj) in C:\Users\dell\RiderProjects\DotNetCore.SKIT.FlurlHttpClient.Wechat\src\SKIT.FlurlHttpClient.Wechat.OpenAI\Utilities\Internal\XmlUtility.cs:line 60
   at SKIT.FlurlHttpClient.Wechat.OpenAI.WechatOpenAIPlatformClient.SendRequestWithJsonAsync[T](IFlurlRequest flurlRequest, Object data, CancellationToken cancellationToken) in C:\Users\dell\RiderProjects\DotNetCore.SKIT.FlurlHttpClient.Wechat\src\SKIT.FlurlHttpClient.Wechat.OpenAI\WechatOpenAIPlatformClient.cs:line 105
   at SKIT.FlurlHttpClient.Wechat.OpenAI.WechatOpenAIPlatformClientExecuteQueryExtensions.ExecuteSignAsync(WechatOpenAIPlatformClient client, SignRequest request, CancellationToken cancellationToken) in C:\Users\dell\RiderProjects\DotNetCore.SKIT.FlurlHttpClient.Wechat\src\SKIT.FlurlHttpClient.Wechat.OpenAI\Extensions\Platform\WechatOpenAIPlatformClientExecuteQueryExtensions.cs:line 27
   at SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests.TestCase_AIBotTests.TestSendMessage() in C:\Users\dell\RiderProjects\DotNetCore.SKIT.FlurlHttpClient.Wechat\test\SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests\TestCase_AIBotTests.cs:line 20
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at Xunit.Sdk.AsyncTestSyncContext.<>c__DisplayClass7_0.<Post>b__0() in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\AsyncTestSyncContext.cs:line 58

System.InvalidOperationException
The type SKIT.FlurlHttpClient.Wechat.OpenAI.Models.Platform.SignRequest was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
   at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterObject.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterObject.Write2_xml(Object o)

发生问题的运行环境

请在此填写以下几项内容:

  1. 操作系统:Windows 11
  2. .NET 版本:.NET 6
  3. 使用的模块及版本:SKIT.FlurlHttpClient.Wechat.OpenAI 2.0.0-rc7

补充说明

fudiwei commented 1 year ago

@WhileKing 我手头没有可供测试的账号,能否帮我确认一下下面这个接口的返回值具体是什么结构的?文档上并没有给出示例。

https://developers.weixin.qq.com/doc/aispeech/confapi/mp/getbindlist.html

dydhyhwu commented 1 year ago

@WhileKing 我手头没有可供测试的账号,能否帮我确认一下下面这个接口的返回值具体是什么结构的?文档上并没有给出示例。

https://developers.weixin.qq.com/doc/aispeech/confapi/mp/getbindlist.html

{
    "bindlist": [
        {
            "info": {
                "authorizer_info": {
                    "nick_name": "公众号名称",
                    "head_img": "公众号头像",
                    "service_type_info": {
                        "id": 1
                    },
                    "verify_type_info": {
                        "id": -1
                    },
                    "user_name": "未知, gh_xxxxxxx",
                    "alias": "公众号基础信息-微信号"
                    "qrcode_url": "公众号二维码URL",
                    "business_info": {
                        "open_pay": 0,
                        "open_shake": 0,
                        "open_scan": 0,
                        "open_card": 0,
                        "open_store": 0
                    },
                    "idc": 1,
                    "principal_name": "公众号基础信息-账号主体,如:个人",
                    "signature": "公众号简介",
                    "account_status": 1
                },
                "authorization_info": null,
                "binded": true,
                "authorizer_appid": "授权方的appid"
            }
        }
    ]
}
dydhyhwu commented 1 year ago

我只绑定了公众号,测试环境的。所以只返回了一个对象,仅供参考。有几个信息找不到对应的地方(像user_name, idc)

fudiwei commented 1 year ago

Release v2.0.0.