Skip to content

Commit

Permalink
调整获取调起支付所需的签名CreatePaySign接口,移除从Config中获取appId,增加自定义入参appId
Browse files Browse the repository at this point in the history
  • Loading branch information
JaneConan committed Apr 6, 2023
1 parent 8b9c4a4 commit 3416346
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,31 @@ public static string CreateSign(string message, string privateKey = null)
/// <summary>
/// 获取调起支付所需的签名
/// </summary>
/// <param name="appId">传入的appId</param>
/// <param name="timeStamp">时间戳</param>
/// <param name="nonceStr">随机串</param>
/// <param name="package">格式:prepay_id={0}</param>
/// <param name="senparcWeixinSettingForTenpayV3">可为空 为空将从Senparc.Weixin.Config获取</param>
/// <returns></returns>
public static string CreatePaySign(string timeStamp, string nonceStr, string package, ISenparcWeixinSettingForTenpayV3 senparcWeixinSettingForTenpayV3 = null)
public static string CreatePaySign(string appId, string timeStamp, string nonceStr, string package, ISenparcWeixinSettingForTenpayV3 senparcWeixinSettingForTenpayV3 = null)
{
senparcWeixinSettingForTenpayV3 ??= Senparc.Weixin.Config.SenparcWeixinSetting.TenpayV3Setting;

var appId = senparcWeixinSettingForTenpayV3.TenPayV3_AppId;
var privateKey = senparcWeixinSettingForTenpayV3.TenPayV3_PrivateKey;

return CreatePaySign(timeStamp, nonceStr, package, appId, privateKey);
return CreatePaySign(appId, timeStamp, nonceStr, package, privateKey);
}

/// <summary>
/// 获取调起支付所需的签名
/// </summary>
/// <param name="appId">传入的appId</param>
/// <param name="timeStamp">时间戳</param>
/// <param name="nonceStr">随机串</param>
/// <param name="package">格式:prepay_id={0}</param>
/// <param name="privateKey">商户证书私钥</param>
/// <returns></returns>
public static string CreatePaySign(string timeStamp, string nonceStr, string package, string appId, string privateKey)
public static string CreatePaySign(string appId, string timeStamp, string nonceStr, string package, string privateKey)
{
string contentForSign = $"{appId}\n{timeStamp}\n{nonceStr}\n{package}\n";
return CreateSign(contentForSign, privateKey);
Expand Down Expand Up @@ -184,7 +185,7 @@ public static JsApiUiPackage GetJsApiUiPackage(string appId, string prepayId)
var timeStamp = TenPayV3Util.GetTimestamp();
var nonceStr = TenPayV3Util.GetNoncestr();
var prepayIdPackage = prepayId.Contains("prepay_id=") ? prepayId : string.Format("prepay_id={0}", prepayId);
var sign = TenPaySignHelper.CreatePaySign(timeStamp, nonceStr, prepayIdPackage);
var sign = TenPaySignHelper.CreatePaySign(appId, timeStamp, nonceStr, prepayIdPackage);

JsApiUiPackage jsApiUiPackage = new(appId, timeStamp, nonceStr, prepayIdPackage, sign);
return jsApiUiPackage;
Expand Down

0 comments on commit 3416346

Please sign in to comment.