博客 (20)

Tea.TeaException:“code: 400, Specified parameter Version is not valid. request id: ”

可能是 AlibabaCloud.OpenApiClient.Models.Config 的 Endpoint 配置错误。


Tea.TeaException:“code: 400, The parameter IpProtocol must be specified with case insensitive TCP, UDP, ICMP, GRE or All. request id: ”

必须指定 Permissions 参数。参考文档


Tea.TeaException:“code: 403, User not authorized to operate on the specified resource, or this API doesn't support RAM. request id: ”

前往 RAM 访问控制配置用户的权限。


Tea.TeaException:“code: 401, The specified security group is not authorized to operate. request id: ”

没有权限操作当前安全组。或者检查安全组的实例 ID 是否正确。


本文不定期更新。

xoyozo 2 个月前
499

截止 2024 年 9 月,CZDB 数据已支持 JAVA、PHP、C、Node.js、Python 语言解析,但官方迟迟未推出 C# / ASP.NET 的版本,于是我参照前面几种语言版本写了 C# 版,支持 IPv4 与 IPv6,实测查询速度,CZDB 版的 MEMORY 模式比原来的 DAT 版数据库快数百倍(具体要看磁盘和内存的读写速度)。能够有效降低 CPU 的使用率,特别是在需要频繁查询 IP 属地的应用场景(譬如每个 HTTP 请求都要判断 IP 属地来决定是否允许访问)。

我要试试→

源代码已提交给纯真官方,相信很快就会有官方版本的 SDK。

xoyozo 9 个月前
1,657

实例化方法一:DbSearcher(String dbFile, QueryType queryType, String key)

实例化方法二:DbSearcher(InputStream is, QueryType queryType, String key)


  • 方法一通过传入文件路径来实例化,方法二通过传入文件流来实例化;

  • 当 queryType 为 MEMORY 时,方法一和方法二只有在实例化时有性能差别,差别在于将指定路径的文件读到内存中保存;在执行 Search 方法时无性能差别,因为都是在内存中执行查找;

  • queryType 为 MEMORYBTREE 的差别在于前者是在内存中查找,速度快但占内存,后者是在文件中查找,速度慢但省内存


错误:Padding is invalid and cannot be removed.

原因:可能是数据库文件与密钥不一致。

xoyozo 9 个月前
1,373

微信网页开发 JS-SDK 官方文档介绍的获取地理位置接口示例是这样的:

wx.getLocation({
  type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
  success: function (res) {
    var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
    var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
    var speed = res.speed; // 速度,以米/每秒计
    var accuracy = res.accuracy; // 位置精度
  }});

实际上是这样的:

wx.getLocation({
  type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
  success: function (res) {
    // 网页位置信息授权点击“确定”按钮,以及允许后继续获取定位信息
  },
  fail: function (err) {
    // 获取定位信息失败(譬如:网页位置信息已授权,但操作系统定位已关闭)
  },
  cancel: function (err) {
    // 网页位置信息授权点击“拒绝”按钮
  }
});

顺便提一下如何关闭网页授权:

进入网页使用 JS-SDK 的公众号(可以在授权弹框中看到服务号名称),点击右上角人形图标,继续点击右上角三个点图标,选择设置,关闭“位置信息”。

授权框.png公众号设置.png

xoyozo 10 个月前
944

.NET SDK 的版本 8.0.303 至少需要 MSBuild 的 17.8.3 版本。当前可用的 MSBuild 版本为 16.11.2.50704。请将在 global.json 中指定的 .NET SDK 更改为需要当前可用的 MSBuild 版本的旧版本。

解决方法:

运行 Visual Studio Installer,

选择相应 VS 版本进行修改,

切到“单个组件”,

勾选“.NET SDK (out of support)”,

点击修改并继续。

xoyozo 11 个月前
1,706

有一个项目,在 VS2022 中正常打开,在 VS2019 中无法加载项目,项目目标框架是 .NET Standard 2.0。报错内容:

error: 无法打开项目文件。 .NET SDK 的版本 7.0.306 至少需要 MSBuild 的 17.4.0 版本。当前可用的 MSBuild 版本为 16.11.2.50704。请将在 global.json 中指定的 .NET SDK 更改为需要当前可用的 MSBuild 版本的旧版本。

解决方法:

运行 Visual Studio Installer,选择 Visual Studio 2019 进行修改,切换到“单个组件”,勾选“.NET SDK (out of support)”,会联动勾选“.NET 5.0 Runtime (Out of support)”与“.NET Core 3.1 Runtime (Out of support)”。

QQ截图20230728135007.png

xoyozo 2 年前
8,289

新版本 SDK 已解决这个问题


image.png

升级到 .NET 7 后,Senparc.Weixin 6.15.7 正常,6.15.8.1-6.15.8.3 无法正常启动,行

builder.Services.AddSenparcWeixinServices(builder.Configuration);

报错:

System.NullReferenceException:“Object reference not set to an instance of an object.”

临时解决方法,改为:

builder.Services.AddSenparcWeixinServices(builder.Configuration, delegate { });



a
转自 adaxiong 2 年前
1,979

本文使用 ASP.NET 6 版本 Senparc.Weixin.Sample.MP 示例项目改造。


第一步 注册多公众号

方法一:打开 appsettings.json 文件,在 SenparcWeixinSetting 节点内添加数组节点 Items,该对象类型同 SenparcWeixinSetting。

//Senparc.Weixin SDK 设置
"SenparcWeixinSetting": {
  "IsDebug": true,
  "Token": "",
  "EncodingAESKey": "",
  "WeixinAppId": "",
  "WeixinAppSecret": "",
  "Items": [
    {
      "IsDebug": true,
      "Token": "a",
      "EncodingAESKey": "a",
      "WeixinAppId": "a",
      "WeixinAppSecret": "a"
    },
    {
      "IsDebug": true,
      "Token": "b",
      "EncodingAESKey": "b",
      "WeixinAppId": "b",
      "WeixinAppSecret": "b"
    }
  ]
}

方法二:修改 Program.cs 文件,在 UseSenparcWeixin 方法中注册多个公众号信息。

var registerService = app.UseSenparcWeixin(app.Environment,
    null /* 不为 null 则覆盖 appsettings  中的 SenparcSetting 配置*/,
    null /* 不为 null 则覆盖 appsettings  中的 SenparcWeixinSetting 配置*/,
    register => { /* CO2NET 全局配置 */ },
    (register, weixinSetting) =>
    {
        //注册公众号信息(可以执行多次,注册多个公众号)
        //register.RegisterMpAccount(weixinSetting, "【盛派网络小助手】公众号");
        foreach (var mp in 从数据库或配置文件中获取的公众号列表)
        {
            register.RegisterMpAccount(new SenparcWeixinSetting
            {
                //IsDebug = true,
                WeixinAppId = mp.AppId,
                WeixinAppSecret = mp.AppSecret,
                Token = mp.Token,
                EncodingAESKey = mp.EncodingAeskey,
            }, mp.Name);
        }
    });

完成后,我们可以从 Config.SenparcWeixinSetting.Items 获取这些信息。


第二步 接入验证与消息处理

打开 WeixinController 控制器,将构造函数改写为:

public WeixinController(IHttpContextAccessor httpContextAccessor)
{
    AppId = httpContextAccessor.HttpContext!.Request.Query["appId"];
    var MpSetting = Services.MPService.MpSettingByAppId(AppId);
    Token = MpSetting.Token;
    EncodingAESKey = MpSetting.EncodingAESKey;
}

示例中 Services.MPService.MpSettingByAppId() 方法实现从 Config.SenparcWeixinSetting.Items 返回指定 appId 的公众号信息。

为使 IHttpContextAccessor 注入生效,打开 Program.cs,在行

builder.Services.AddControllersWithViews();

下方插入

builder.Services.AddHttpContextAccessor();

这样,我们就可以在构造函数中直接获取地址栏中的 appId 参数,找到对应的公众号进行消息处理。


第三步 消息自动回复中的 AppId

打开 CustomMessageHandler.cs,将 

private string appId = Config.SenparcWeixinSetting.MpSetting.WeixinAppId;
private string appSecret = Config.SenparcWeixinSetting.MpSetting.WeixinAppSecret;

替换为:

private string appId = null!;
private string appSecret = null!;

并在构造函数中插入

appId = postModel.AppId;
appSecret = Services.MPService.MpSettingByAppId(postModel.AppId).WeixinAppSecret;

这样,本页中使用的 appId / appSecret 会从 postModel 中获取,而非默认公众号。postModel 已在 WeixinController 中赋值当前的 appId。

改造后,我们可以在 OnTextRequestAsync() 等处理消息的方法中可以判断 appId 来处理不同的消息。


第四步 其它功能和接口

其它功能和接口均可用指定的 AppId 和对应的 AppSecret 进行调用。

xoyozo 3 年前
4,791