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.5k stars 289 forks source link

企微发红包返回 “签名错误” #117

Closed goodsxx closed 10 months ago

goodsxx commented 10 months ago

⚠⚠ 请注意:不符合格式要求的 Issue 可能会被直接关闭。


关于问题的简单描述

调用ExecuteSendPayMarketingTransfersWeWorkRedPackAsync接口时,提示签名错误,我一一核对了参数,确认没有问题,我查看了源码,发现SendPayMarketingTransfersWeWorkRedPackRequest貌似没有定义 sign(微信支付签名) 这个字段,只有 workwx_sign(企微签名这个字段),并且在ExecuteSendPayMarketingTransfersWeWorkRedPackAsync的源码中我只看到了对workwx_sign签名生成的逻辑,没有看到sign(微信支付签名)生成,不知道是否是这个原因?

image image

文档地址: https://developer.work.weixin.qq.com/document/path/90275 https://developer.work.weixin.qq.com/document/path/90281#11652

与问题相关的源代码 下面ExecuteSendPayMarketingTransfersWeWorkRedPackAsync方法的源码,只有workwx_sign的签名部分

/// <summary>
/// <para>异步调用 [POST] /mmpaymkttransfers/sendworkwxredpack 接口。</para>
/// <para>REF: https://developer.work.weixin.qq.com/document/path/96697 </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.SendPayMarketingTransfersWeWorkRedPackResponse> ExecuteSendPayMarketingTransfersWeWorkRedPackAsync(this WechatTenpayClient client, Models.SendPayMarketingTransfersWeWorkRedPackRequest request, CancellationToken cancellationToken = default)
{
    if (client is null) throw new ArgumentNullException(nameof(client));
    if (request is null) throw new ArgumentNullException(nameof(request));

    if (request.WeWorkSign == null)
    {
        if (request.MerchantId == null)
        {
            request.MerchantId = client.Credentials.MerchantId;
        }

        if (request.AppId == null)
        {
            request.AppId = client.Credentials.AppId;
        }

        if (request.NonceString == null)
        {
            request.NonceString = Guid.NewGuid().ToString("N");
        }

        request.WeWorkSign = Utilities.RequestSigner.Sign(
            paramsMap: new Dictionary<string, string?>()
            {
                { "act_name", request.ActivityName },
                { "mch_billno", request.MerchantBillNumber },
                { "mch_id", request.MerchantId },
                { "nonce_str", request.NonceString },
                { "re_openid", request.OpenId },
                { "total_amount", request.TotalAmount.ToString() },
                { "wxappid", request.AppId }
            },
            secretKey: "secret",
            secretValue: client.Credentials.WeWorkPaymentSecret!,
            signType: Constants.SignTypes.MD5
        );
    }

    IFlurlRequest flurlReq = client
        .CreateRequest(request, HttpMethod.Post, "mmpaymkttransfers", "sendworkwxredpack");

    return await client.SendRequestWithXmlAsync<Models.SendPayMarketingTransfersWeWorkRedPackResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}

异常堆栈或异常原因

请在此填写你遇到的问题抛出错误时的异常消息和堆栈跟踪(如果有的话)。


发生问题的运行环境

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

  1. 操作系统:请填写发生问题的操作系统环境信息(如:Windows Server 2012 R2)
  2. .NET 版本:请填写发生问题的 .NET 环境信息(如:.NET Framework 4.7.2 / .NET 5.0)
  3. 使用的模块及版本:请填写发生问题的模块信息(如:SKIT.FlurlHttpClient.Wechat.Api 1.0.0)
  4. 其他环境信息。

补充说明

请在此填写任何其他可以定位问题的信息。

goodsxx commented 10 months ago

image 啊,不是这个问题,我找到了这部分代码!