Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

网站同时使用了公众号和小程序jsapi支付,签名却固定用配置文件TenPayV3_AppId用于appId,导致只能支持一种支付 #2809

Closed
4 of 31 tasks
f0508crm opened this issue Apr 6, 2023 · 8 comments

Comments

@f0508crm
Copy link

f0508crm commented Apr 6, 2023

此版块专为反馈 bug 及提交需求服务,不负责解答开发问题,请勿发表开发问题,
如果您需要这方面的帮助,请移步问答社区https://weixin.senparc.com/QA

问题描述

网站同时使用了公众号和小程序jsapi支付,签名却固定用配置文件TenPayV3_AppId用于appId,导致只能支持一种支付

重现问题步骤(如果可以)

var jsApiUiPackage = TenPaySignHelper.GetJsApiUiPackage(appId, result.prepay_id);

    public static JsApiUiPackage GetJsApiUiPackage(string appId, string prepayId)
    {
        string timestamp = TenPayV3Util.GetTimestamp();
        string noncestr = TenPayV3Util.GetNoncestr();
        string text = (prepayId.Contains("prepay_id=") ? prepayId : $"prepay_id={prepayId}");
        string signature = CreatePaySign(timestamp, noncestr, text);
        return new JsApiUiPackage(appId, timestamp, noncestr, text, signature);
    }

    public static string CreatePaySign(string timeStamp, string nonceStr, string package, ISenparcWeixinSettingForTenpayV3 senparcWeixinSettingForTenpayV3 = null)
    {
        if (senparcWeixinSettingForTenpayV3 == null)
        {
            senparcWeixinSettingForTenpayV3 = Config.SenparcWeixinSetting.TenpayV3Setting;
        }

        string tenPayV3_AppId = senparcWeixinSettingForTenpayV3.TenPayV3_AppId;
        string tenPayV3_PrivateKey = senparcWeixinSettingForTenpayV3.TenPayV3_PrivateKey;
        return CreatePaySign(timeStamp, nonceStr, package, tenPayV3_AppId, tenPayV3_PrivateKey);
    }
微信官方文档 URL
微信官方文档快照(直接复制关键内容到下方)
发现问题的模块
  • Senparc.Weixin 版本:
  • Senparc.Weixin.MP 版本:
  • Senparc.Weixin.MP.MVC 版本:
  • Senparc.Weixin.Open 版本:
    - [ ] Senparc.Weixin.QY 版本:
  • Senparc.Weixin.Work 版本:
  • Senparc.Weixin.WxOpen 版本:
  • Senparc.Weixin.Cache.Redis 版本:
  • Senparc.Weixin.Cache.Memcached 版本:
  • Senparc.Weixin.Tenpay 版本:
  • Senparc.WebSocket 版本:
  • 其他模块:
模块对应的 .net 版本
  • .net 3.5
  • .net 4.0
  • .net 4.5+
  • .net standard 2.0 / 2.1
  • .net core 1.x
  • .net core 2.x
  • .net core 3.x
  • .net 5.x / 6.x
开发环境
  • Visual Studio 2019
  • Visual Studio 2022
  • Visual Studio Code
  • 其他:
缓存环境
  • 服务器内存缓存(默认)
  • Redis 版本:
  • Memcached 版本:
  • 其他:
系统环境
  • Windows,版本:
  • Linux,版本:
  • Mac,版本:
  • 其他:
联系方式

Email:

(也可将问题地址及联系方式发送到 www.jeffrey.su@gmail.com)

发布问题后,请保持对 issue 的关注,有时会有需要进一步沟通的信息,很长时间内没有得到答复的 issue 将被关闭。

@JaneConan
Copy link
Contributor

@f0508crm @SenparcHai @JaneConan 正在处理

@JaneConan
Copy link
Contributor

PR已提交 #2810 请苏老师指导审核 @JeffreySu

JeffreySu added a commit that referenced this issue Apr 7, 2023
…ySign_InputParam

Feature/#2809 change create pay sign input param
@JeffreySu
Copy link
Owner

@JaneConan 已经回复了,为了避免程序里面硬编码appId,我们已经提供了支持多账套的方案,你可以参考一下。

@f0508crm
Copy link
Author

f0508crm commented Apr 7, 2023

首先先确认一个情况,微信支付是否存在创建订单的appId跟签名时appId不一致还可以成功支付的情况,如果不存在这种情况,那既然传了参数appId,签名就直接使用appId,而不要使用TenPayV3_AppId,否则就是多此一举,给用户增加使用难度和排查bug难度

@JeffreySu
Copy link
Owner

1、appId 和你后续支付的令牌、OpenId等肯定是有关联的,所以不能混用。
2、所有的 appId 都建议从配置中读取,所以你需要在 appsettings.json 里面配置之后读入,当然极端情况你可能会在程序里面 hard code,这种少数情况你可以直接构造一个类,传入appId即可,但是如果只提供appId,对于正常实用配置的程序来说,又会额外增加负担,并且参数的一致性、可靠性是降低的。

@f0508crm
Copy link
Author

f0508crm commented Apr 7, 2023

appId也是从配置文件里面读取的,那为什么还要用到TenPayV3_AppId,而且他们的值本身就必须一致。还有我并没有混用。

@f0508crm
Copy link
Author

f0508crm commented Apr 7, 2023

支付签名里面用的appId就是微信公众号和小程序的appId,而不是微信支付本身的appId,微信支付自己是没有appId的。

@f0508crm
Copy link
Author

f0508crm commented Apr 7, 2023

配置文件TenPayV3_AppId在公众号和小程序的jsapi支付上,根本是可以不要用的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants